@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
|
@@ -5,7 +5,7 @@ import { normalizeSessionEventType } from '../session-metadata/session-projectio
|
|
|
5
5
|
const RETENTION = 30 * 24 * 60 * 60 * 1000;
|
|
6
6
|
const nextCursor = (page) => typeof page?.cursor?.next === 'string' ? page.cursor.next : null;
|
|
7
7
|
|
|
8
|
-
export function createContentSearchRuntime({ service, getRuntimeKey, listSessions, listMessages, now = Date.now }) {
|
|
8
|
+
export function createContentSearchRuntime({ service, getRuntimeKey, getEventRuntimeKey = getRuntimeKey, listSessions, getSession, listMessages, now = Date.now }) {
|
|
9
9
|
let stopped = false;
|
|
10
10
|
let flight;
|
|
11
11
|
let timer;
|
|
@@ -16,11 +16,12 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
16
16
|
const deleted = new Set();
|
|
17
17
|
const status = () => {
|
|
18
18
|
const runtime = getRuntimeKey();
|
|
19
|
+
if (!stopped && state.runtime !== runtime) schedule(0);
|
|
19
20
|
const coverage = service.coverage(runtime);
|
|
20
21
|
return { ...(state.runtime === runtime ? state : { runtime, phase: 'pending', since: now() - RETENTION, total: 0, completed: 0, failed: 0, updatedAt: null }),
|
|
21
22
|
...coverage, initializationRequired: coverage.indexCompletedAt === null, ...service.stats(runtime) };
|
|
22
23
|
};
|
|
23
|
-
const sync = () => {
|
|
24
|
+
const sync = ({ incremental = false } = {}) => {
|
|
24
25
|
if (stopped) return Promise.resolve();
|
|
25
26
|
if (flight) return flight;
|
|
26
27
|
const runtime = getRuntimeKey();
|
|
@@ -32,13 +33,37 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
32
33
|
state = { runtime, phase: previous ? 'ready' : 'indexing', since: now() - RETENTION, total: state.total, completed: 0, failed: 0, updatedAt: previous };
|
|
33
34
|
flight = (async () => {
|
|
34
35
|
if (service.coverage(runtime).indexCompletedAt === null) service.beginInitialization(runtime, now());
|
|
36
|
+
const revisions = new Map(service.pending(runtime).map(({ id, revision }) => [id, revision]));
|
|
37
|
+
for (const id of revisions.keys()) dirty.add(id);
|
|
35
38
|
const pendingDirty = new Set(dirty);
|
|
39
|
+
const initialized = service.coverage(runtime).indexCompletedAt !== null;
|
|
40
|
+
const scanCatalog = !incremental || !initialized || service.needsEventIdentityRepair(runtime);
|
|
36
41
|
const sessions = [];
|
|
37
42
|
const ids = new Set();
|
|
38
43
|
let cursor;
|
|
44
|
+
let completeCatalog = scanCatalog;
|
|
39
45
|
const cursors = new Set();
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
if (!scanCatalog) {
|
|
47
|
+
for (const sessionID of pendingDirty) {
|
|
48
|
+
try {
|
|
49
|
+
const session = await getSession({ sessionID, signal });
|
|
50
|
+
if (!current()) return;
|
|
51
|
+
if (!session?.id || !Number.isFinite(session.time?.updated)) throw new Error('Invalid dirty session');
|
|
52
|
+
if (!session.parentID && session.time.updated >= state.since && !deleted.has(sessionID)) sessions.push(session);
|
|
53
|
+
else {
|
|
54
|
+
service.removeSession(runtime, sessionID);
|
|
55
|
+
dirty.delete(sessionID);
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (!current()) return;
|
|
59
|
+
if ((error?.status ?? error?.response?.status) === 404) {
|
|
60
|
+
service.removeSession(runtime, sessionID);
|
|
61
|
+
dirty.delete(sessionID);
|
|
62
|
+
} else state.failed++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else do {
|
|
66
|
+
const page = await listSessions({ limit: 100, ...(cursor ? { cursor } : { order: 'desc' }), signal });
|
|
42
67
|
if (!current()) return;
|
|
43
68
|
if (!Array.isArray(page?.data)) throw new Error('Invalid global session page');
|
|
44
69
|
for (const session of page.data) {
|
|
@@ -51,11 +76,42 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
51
76
|
cursor = nextCursor(page);
|
|
52
77
|
if (cursor && cursors.has(cursor)) throw new Error('Repeated session cursor');
|
|
53
78
|
if (cursor) cursors.add(cursor);
|
|
79
|
+
if (page.data.some((session) => session.time.updated < state.since)) {
|
|
80
|
+
completeCatalog = !cursor;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
54
83
|
} while (cursor && current());
|
|
55
84
|
state.total = sessions.length;
|
|
56
85
|
state.completed = 0;
|
|
57
86
|
const recentIDs = new Set(sessions.map((session) => session.id));
|
|
58
|
-
|
|
87
|
+
// A time-bounded catalog cannot classify pending IDs outside its pages.
|
|
88
|
+
// Resolve those IDs directly so excluded children/expired roots cannot
|
|
89
|
+
// keep initialization dirty forever. Failed reads remain pending.
|
|
90
|
+
if (scanCatalog && !completeCatalog) for (const sessionID of pendingDirty) if (!recentIDs.has(sessionID)) {
|
|
91
|
+
try {
|
|
92
|
+
const session = await getSession({ sessionID, signal });
|
|
93
|
+
if (!current()) return;
|
|
94
|
+
if (!session?.id || !Number.isFinite(session.time?.updated)) throw new Error('Invalid dirty session');
|
|
95
|
+
if (!session.parentID && session.time.updated >= state.since && !deleted.has(sessionID)) {
|
|
96
|
+
sessions.push(session);
|
|
97
|
+
recentIDs.add(sessionID);
|
|
98
|
+
} else {
|
|
99
|
+
service.removeSession(runtime, sessionID);
|
|
100
|
+
dirty.delete(sessionID);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (!current()) return;
|
|
104
|
+
if ((error?.status ?? error?.response?.status) === 404) {
|
|
105
|
+
service.removeSession(runtime, sessionID);
|
|
106
|
+
dirty.delete(sessionID);
|
|
107
|
+
} else state.failed++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
state.total = sessions.length;
|
|
111
|
+
if (scanCatalog && completeCatalog) for (const id of pendingDirty) if (!recentIDs.has(id)) {
|
|
112
|
+
dirty.delete(id);
|
|
113
|
+
service.acknowledge(runtime, id, revisions.get(id));
|
|
114
|
+
}
|
|
59
115
|
if (service.coverage(runtime).indexCompletedAt === null) state.phase = 'indexing';
|
|
60
116
|
let index = 0;
|
|
61
117
|
const worker = async () => {
|
|
@@ -85,7 +141,10 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
85
141
|
// Native pages are newest-first, including control records.
|
|
86
142
|
if (page.data.length && page.data.every((record) => Number(record.time?.created) < state.since)) break;
|
|
87
143
|
} while (before && current());
|
|
88
|
-
if (current() && !deleted.has(session.id))
|
|
144
|
+
if (current() && !deleted.has(session.id)) {
|
|
145
|
+
service.replaceSession(runtime, session, [...records.values()], state.since, now());
|
|
146
|
+
if (revisions.has(session.id)) service.acknowledge(runtime, session.id, revisions.get(session.id));
|
|
147
|
+
}
|
|
89
148
|
state.completed++;
|
|
90
149
|
} catch {
|
|
91
150
|
if (!current()) return;
|
|
@@ -96,7 +155,7 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
96
155
|
};
|
|
97
156
|
await Promise.all([worker(), worker()]);
|
|
98
157
|
if (current()) {
|
|
99
|
-
service.prune(runtime, state.since, ids);
|
|
158
|
+
service.prune(runtime, state.since, completeCatalog ? ids : undefined);
|
|
100
159
|
state.phase = state.failed ? 'partial' : 'ready';
|
|
101
160
|
state.updatedAt = now();
|
|
102
161
|
if (!state.failed && !dirty.size) service.completeInitialization(runtime, state.since, state.updatedAt);
|
|
@@ -110,14 +169,19 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
110
169
|
if (stopped || (timer && due <= Date.now() + delay)) return;
|
|
111
170
|
if (timer) clearTimeout(timer);
|
|
112
171
|
due = Date.now() + delay;
|
|
113
|
-
timer = setTimeout(async () => {
|
|
172
|
+
timer = setTimeout(async () => {
|
|
173
|
+
timer = undefined;
|
|
174
|
+
await sync({ incremental: true });
|
|
175
|
+
if (service.coverage(getRuntimeKey()).indexCompletedAt === null || service.needsEventIdentityRepair(getRuntimeKey()) || service.pending(getRuntimeKey()).length) schedule(30_000);
|
|
176
|
+
}, delay);
|
|
114
177
|
timer.unref?.();
|
|
115
178
|
};
|
|
116
179
|
return {
|
|
117
180
|
sync, status,
|
|
118
181
|
start() { schedule(0); },
|
|
119
182
|
observe(event) {
|
|
120
|
-
if (event.runtimeIdentity?.runtimeKey && event.runtimeIdentity.runtimeKey !==
|
|
183
|
+
if (event.runtimeIdentity?.runtimeKey && event.runtimeIdentity.runtimeKey !== getEventRuntimeKey()) return;
|
|
184
|
+
if (state.runtime !== getRuntimeKey()) schedule(0);
|
|
121
185
|
const payload = event.payload?.payload ?? event.payload;
|
|
122
186
|
const type = normalizeSessionEventType(payload?.type ?? '');
|
|
123
187
|
if (!(type.startsWith('message.') || type.startsWith('session.'))) return;
|
|
@@ -125,7 +189,8 @@ export function createContentSearchRuntime({ service, getRuntimeKey, listSession
|
|
|
125
189
|
const data = payload.properties ?? payload.data ?? {};
|
|
126
190
|
const id = data.sessionID ?? data.info?.sessionID ?? data.session?.id ?? (type.startsWith('session.') ? data.id ?? data.info?.id : undefined);
|
|
127
191
|
if (id && type === 'session.deleted') { dirty.delete(id); deleted.add(id); service.removeSession(getRuntimeKey(), id); }
|
|
128
|
-
else if (id) dirty.add(id);
|
|
192
|
+
else if (id) { dirty.add(id); service.markDirty(getRuntimeKey(), id); }
|
|
193
|
+
if (!id) return;
|
|
129
194
|
// Coalesce bursts; ongoing scans retain dirty IDs for the next pass.
|
|
130
195
|
schedule(1000);
|
|
131
196
|
},
|
|
@@ -1,7 +1,97 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
1
|
+
import { expect, test, vi } from 'vitest';
|
|
2
2
|
import { createContentSearchService } from './service.js';
|
|
3
3
|
import { createContentSearchRuntime } from './runtime.js';
|
|
4
4
|
|
|
5
|
+
test('bounded backfill drains excluded dirty children without repeating the catalog scan', async () => {
|
|
6
|
+
const service = createContentSearchService({ dbPath: ':memory:' });
|
|
7
|
+
const day = 86400000;
|
|
8
|
+
const now = 40 * day;
|
|
9
|
+
service.markDirty('host', 'child');
|
|
10
|
+
const listSessions = vi.fn(async () => ({ data: [{ id: 'old', time: { updated: 1 } }], cursor: { next: 'older' } }));
|
|
11
|
+
const runtime = createContentSearchRuntime({ service, getRuntimeKey: () => 'host', now: () => now,
|
|
12
|
+
listSessions, getSession: async () => ({ id: 'child', parentID: 'parent', time: { updated: now } }),
|
|
13
|
+
listMessages: vi.fn(),
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
await runtime.sync({ incremental: true });
|
|
17
|
+
expect(service.pending('host')).toEqual([]);
|
|
18
|
+
expect(runtime.status().initializationRequired).toBe(false);
|
|
19
|
+
await runtime.sync({ incremental: true });
|
|
20
|
+
expect(listSessions).toHaveBeenCalledTimes(1);
|
|
21
|
+
} finally { await runtime.stop(); service.close(); }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('warm startup and idle time do not scan history; durable dirty events refresh only their session', async () => {
|
|
25
|
+
vi.useFakeTimers();
|
|
26
|
+
const service = createContentSearchService({ dbPath: ':memory:' });
|
|
27
|
+
service.beginInitialization('host', 1);
|
|
28
|
+
service.completeInitialization('host', 0, 2);
|
|
29
|
+
const listSessions = vi.fn(async () => ({ data: [], cursor: {} }));
|
|
30
|
+
const getSession = vi.fn(async ({ sessionID }) => ({ id: sessionID, time: { updated: Date.now() } }));
|
|
31
|
+
const listMessages = vi.fn(async () => ({ data: [], cursor: {} }));
|
|
32
|
+
let runtime = createContentSearchRuntime({ service, getRuntimeKey: () => 'host', listSessions, getSession, listMessages });
|
|
33
|
+
try {
|
|
34
|
+
runtime.start();
|
|
35
|
+
await vi.advanceTimersByTimeAsync(120_000);
|
|
36
|
+
expect(listSessions).not.toHaveBeenCalled();
|
|
37
|
+
expect(listMessages).not.toHaveBeenCalled();
|
|
38
|
+
runtime.observe({ payload: { type: 'message.updated', data: { sessionID: 'one' } } });
|
|
39
|
+
await runtime.stop();
|
|
40
|
+
runtime = createContentSearchRuntime({ service, getRuntimeKey: () => 'host', listSessions, getSession, listMessages });
|
|
41
|
+
runtime.start();
|
|
42
|
+
await vi.advanceTimersByTimeAsync(120_000);
|
|
43
|
+
expect(listSessions).not.toHaveBeenCalled();
|
|
44
|
+
expect(getSession).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(getSession.mock.calls[0][0].sessionID).toBe('one');
|
|
46
|
+
expect(listMessages).toHaveBeenCalledTimes(1);
|
|
47
|
+
} finally { await runtime.stop(); service.close(); vi.useRealTimers(); }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('initial history stops at thirty days without pruning unseen sessions as deleted', async () => {
|
|
51
|
+
const service = createContentSearchService({ dbPath: ':memory:' });
|
|
52
|
+
const day = 86400000;
|
|
53
|
+
const now = 40 * day;
|
|
54
|
+
service.replaceSession('host', { id: 'unseen', time: { updated: now } }, [], 0);
|
|
55
|
+
const listSessions = vi.fn(async () => ({ data: [
|
|
56
|
+
{ id: 'recent', time: { updated: now } },
|
|
57
|
+
{ id: 'old', time: { updated: now - 31 * day } },
|
|
58
|
+
], cursor: { next: 'older-history' } }));
|
|
59
|
+
const listMessages = vi.fn(async () => ({ data: [], cursor: {} }));
|
|
60
|
+
const runtime = createContentSearchRuntime({ service, getRuntimeKey: () => 'host', now: () => now, listSessions, listMessages });
|
|
61
|
+
try {
|
|
62
|
+
await runtime.sync();
|
|
63
|
+
expect(listSessions).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(listMessages).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(listMessages.mock.calls[0][0].sessionID).toBe('recent');
|
|
66
|
+
expect(service.updated('host', 'unseen')).toBe(now);
|
|
67
|
+
expect(runtime.status().initializationRequired).toBe(false);
|
|
68
|
+
} finally { await runtime.stop(); service.close(); }
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('an event received while indexing survives acknowledgement and retries only that session', async () => {
|
|
72
|
+
const service = createContentSearchService({ dbPath: ':memory:' });
|
|
73
|
+
service.beginInitialization('host', 1);
|
|
74
|
+
service.completeInitialization('host', 0, 2);
|
|
75
|
+
const listSessions = vi.fn();
|
|
76
|
+
let reads = 0;
|
|
77
|
+
const runtime = createContentSearchRuntime({ service, getRuntimeKey: () => 'host', now: () => 100,
|
|
78
|
+
listSessions, getSession: async ({ sessionID }) => ({ id: sessionID, time: { updated: 10 } }),
|
|
79
|
+
listMessages: async () => {
|
|
80
|
+
if (++reads === 1) runtime.observe({ payload: { type: 'message.updated', data: { sessionID: 's' } } });
|
|
81
|
+
return { data: [], cursor: {} };
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
runtime.observe({ payload: { type: 'message.updated', data: { sessionID: 's' } } });
|
|
86
|
+
await runtime.sync({ incremental: true });
|
|
87
|
+
expect(service.pending('host')).toHaveLength(1);
|
|
88
|
+
await runtime.sync({ incremental: true });
|
|
89
|
+
expect(reads).toBe(2);
|
|
90
|
+
expect(service.pending('host')).toEqual([]);
|
|
91
|
+
expect(listSessions).not.toHaveBeenCalled();
|
|
92
|
+
} finally { await runtime.stop(); service.close(); }
|
|
93
|
+
});
|
|
94
|
+
|
|
5
95
|
test('indexes only roots and prunes legacy subagents after a complete catalog, including dirty children', async () => {
|
|
6
96
|
const service = createContentSearchService({ dbPath: ':memory:' });
|
|
7
97
|
const root = { id: 'root', time: { updated: 10 } };
|
|
@@ -22,6 +22,7 @@ export function createContentSearchService({ dbPath }) {
|
|
|
22
22
|
CREATE TABLE IF NOT EXISTS search_message(id INTEGER PRIMARY KEY, runtime TEXT, session TEXT, message TEXT, role TEXT, created REAL, body TEXT, UNIQUE(runtime,session,message));
|
|
23
23
|
CREATE INDEX IF NOT EXISTS search_message_scope ON search_message(runtime,session);
|
|
24
24
|
CREATE TABLE IF NOT EXISTS search_coverage(runtime TEXT PRIMARY KEY, started_at REAL NOT NULL, completed_at REAL, since REAL, verified_at REAL);
|
|
25
|
+
CREATE TABLE IF NOT EXISTS search_dirty(runtime TEXT, id TEXT, revision INTEGER NOT NULL, PRIMARY KEY(runtime,id));
|
|
25
26
|
CREATE VIRTUAL TABLE IF NOT EXISTS search_fts USING fts5(body, content='search_message', content_rowid='id', tokenize='trigram');
|
|
26
27
|
CREATE TRIGGER IF NOT EXISTS search_insert AFTER INSERT ON search_message BEGIN
|
|
27
28
|
INSERT INTO search_fts(rowid,body) VALUES(new.id,new.body); END;
|
|
@@ -35,23 +36,39 @@ export function createContentSearchService({ dbPath }) {
|
|
|
35
36
|
if (!sessionColumns.some((column) => column.name === 'indexed_at')) {
|
|
36
37
|
db.exec('ALTER TABLE search_session ADD COLUMN indexed_at REAL');
|
|
37
38
|
}
|
|
39
|
+
if (!db.prepare('PRAGMA table_info(search_coverage)').all().some((column) => column.name === 'event_identity_repaired')) {
|
|
40
|
+
db.exec('ALTER TABLE search_coverage ADD COLUMN event_identity_repaired INTEGER NOT NULL DEFAULT 0');
|
|
41
|
+
}
|
|
38
42
|
const remove = db.prepare('DELETE FROM search_message WHERE runtime=? AND session=?');
|
|
39
43
|
const write = db.prepare('INSERT INTO search_message(runtime,session,message,role,created,body) VALUES(?,?,?,?,?,?)');
|
|
40
44
|
const removeSession = db.transaction((runtime, id) => {
|
|
41
45
|
remove.run(runtime, id);
|
|
42
46
|
db.prepare('DELETE FROM search_session WHERE runtime=? AND id=?').run(runtime, id);
|
|
47
|
+
db.prepare('DELETE FROM search_dirty WHERE runtime=? AND id=?').run(runtime, id);
|
|
43
48
|
});
|
|
44
49
|
return {
|
|
50
|
+
markDirty(runtime, id) {
|
|
51
|
+
db.prepare('INSERT INTO search_dirty(runtime,id,revision) VALUES(?,?,1) ON CONFLICT(runtime,id) DO UPDATE SET revision=revision+1').run(runtime, id);
|
|
52
|
+
},
|
|
53
|
+
pending(runtime) {
|
|
54
|
+
return db.prepare('SELECT id,revision FROM search_dirty WHERE runtime=?').all(runtime);
|
|
55
|
+
},
|
|
56
|
+
acknowledge(runtime, id, revision) {
|
|
57
|
+
return db.prepare('DELETE FROM search_dirty WHERE runtime=? AND id=? AND revision=?').run(runtime, id, revision).changes > 0;
|
|
58
|
+
},
|
|
45
59
|
coverage(runtime) {
|
|
46
60
|
return db.prepare('SELECT started_at AS indexStartedAt, completed_at AS indexCompletedAt, since AS coveredSince, verified_at AS verifiedAt FROM search_coverage WHERE runtime=?').get(runtime)
|
|
47
61
|
?? { indexStartedAt: null, indexCompletedAt: null, coveredSince: null, verifiedAt: null };
|
|
48
62
|
},
|
|
63
|
+
needsEventIdentityRepair(runtime) {
|
|
64
|
+
return db.prepare('SELECT event_identity_repaired FROM search_coverage WHERE runtime=?').get(runtime)?.event_identity_repaired !== 1;
|
|
65
|
+
},
|
|
49
66
|
beginInitialization(runtime, timestamp) {
|
|
50
67
|
db.prepare(`INSERT INTO search_coverage(runtime,started_at) VALUES(?,?)
|
|
51
68
|
ON CONFLICT(runtime) DO NOTHING`).run(runtime, timestamp);
|
|
52
69
|
},
|
|
53
70
|
completeInitialization(runtime, since, timestamp) {
|
|
54
|
-
db.prepare(`UPDATE search_coverage SET completed_at=COALESCE(completed_at,?), since=?, verified_at
|
|
71
|
+
db.prepare(`UPDATE search_coverage SET completed_at=COALESCE(completed_at,?), since=?, verified_at=?, event_identity_repaired=1 WHERE runtime=?`)
|
|
55
72
|
.run(timestamp, since, timestamp, runtime);
|
|
56
73
|
},
|
|
57
74
|
replaceSession: db.transaction((runtime, session, records, since = null, indexedAt = Date.now()) => {
|
|
@@ -73,7 +90,7 @@ export function createContentSearchService({ dbPath }) {
|
|
|
73
90
|
prune: db.transaction((runtime, since, ids) => {
|
|
74
91
|
db.prepare('DELETE FROM search_message WHERE runtime=? AND created<?').run(runtime, since);
|
|
75
92
|
db.prepare('UPDATE search_session SET since=MAX(since,?) WHERE runtime=? AND since IS NOT NULL').run(since, runtime);
|
|
76
|
-
for (const row of db.prepare('SELECT id FROM search_session WHERE runtime=?').all(runtime)) {
|
|
93
|
+
if (ids) for (const row of db.prepare('SELECT id FROM search_session WHERE runtime=?').all(runtime)) {
|
|
77
94
|
if (!ids.has(row.id)) removeSession(runtime, row.id);
|
|
78
95
|
}
|
|
79
96
|
}),
|
|
@@ -6,6 +6,7 @@ Own filesystem API behavior for the web server runtime, including file operation
|
|
|
6
6
|
## Entrypoints and structure
|
|
7
7
|
- `packages/web/server/lib/fs/routes.js`: route registration and runtime-owned state for `/api/fs/*` endpoints.
|
|
8
8
|
- `packages/web/server/lib/fs/search.js`: fuzzy filesystem search runtime used by non-FS routes (for example project icon discovery).
|
|
9
|
+
- `packages/web/server/lib/fs/binary-file.js`: shared 8 KiB binary sniff for Web stat, Electron binary-path IPC, and both VS Code stat adapters. Strict UTF-8 decoding permits an incomplete trailing code point only when the opened file's size confirms more bytes remain; NUL, malformed sequences, and incomplete UTF-8 at EOF remain binary. File handles close on every outcome, and filesystem errors propagate.
|
|
9
10
|
|
|
10
11
|
## Public exports
|
|
11
12
|
- `registerFsRoutes(app, dependencies)` from `routes.js`
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const BINARY_SAMPLE_BYTES = 8192;
|
|
2
|
+
|
|
3
|
+
export const isBinaryFile = async (filePath, fsPromises) => {
|
|
4
|
+
const file = await fsPromises.open(filePath, 'r');
|
|
5
|
+
try {
|
|
6
|
+
const sample = Buffer.alloc(BINARY_SAMPLE_BYTES);
|
|
7
|
+
const { bytesRead } = await file.read(sample, 0, sample.length, 0);
|
|
8
|
+
const bytes = sample.subarray(0, bytesRead);
|
|
9
|
+
if (bytes.includes(0)) return true;
|
|
10
|
+
const { size } = await file.stat();
|
|
11
|
+
try {
|
|
12
|
+
// Only a non-EOF sample may end partway through a UTF-8 code point.
|
|
13
|
+
new TextDecoder('utf-8', { fatal: true }).decode(bytes, { stream: bytesRead < size });
|
|
14
|
+
return false;
|
|
15
|
+
} catch {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
} finally {
|
|
19
|
+
await file.close();
|
|
20
|
+
}
|
|
21
|
+
};
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { createImageFingerprintReader } from './image-fingerprint.js';
|
|
3
|
+
import { isBinaryFile } from './binary-file.js';
|
|
3
4
|
import { createRealpathCache } from '../path-realpath-cache.js';
|
|
4
5
|
import nodeFsPromises from 'node:fs/promises';
|
|
5
6
|
import nodePath from 'node:path';
|
|
@@ -127,27 +128,6 @@ const FILE_MIME_MAP = Object.freeze({
|
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
const MAX_SERVE_BYTES = 100 * 1024 * 1024;
|
|
130
|
-
const BINARY_SAMPLE_BYTES = 8192;
|
|
131
|
-
|
|
132
|
-
const isBinaryFile = async (filePath, fsPromises) => {
|
|
133
|
-
const file = await fsPromises.open(filePath, 'r');
|
|
134
|
-
try {
|
|
135
|
-
const sample = Buffer.alloc(BINARY_SAMPLE_BYTES);
|
|
136
|
-
const { bytesRead } = await file.read(sample, 0, sample.length, 0);
|
|
137
|
-
const bytes = sample.subarray(0, bytesRead);
|
|
138
|
-
if (bytes.includes(0)) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
143
|
-
return false;
|
|
144
|
-
} catch {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
} finally {
|
|
148
|
-
await file.close();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
131
|
|
|
152
132
|
// Only deterministic, side-effect-free git plumbing path queries are cacheable.
|
|
153
133
|
// Anything outside this allowlist (including any non-git command) runs normally
|
|
@@ -285,6 +285,48 @@ const callMkdir = async (handler, body) => {
|
|
|
285
285
|
};
|
|
286
286
|
|
|
287
287
|
describe('fs stat', () => {
|
|
288
|
+
it.each([
|
|
289
|
+
['two-byte code point split after byte 1', Buffer.from('a'.repeat(8191) + 'é'), false],
|
|
290
|
+
['Chinese split after byte 2', Buffer.from('a'.repeat(8190) + '好'), false],
|
|
291
|
+
['emoji split after byte 1', Buffer.from('a'.repeat(8191) + '😀'), false],
|
|
292
|
+
['emoji split after byte 2', Buffer.from('a'.repeat(8190) + '😀'), false],
|
|
293
|
+
['emoji split after byte 3', Buffer.from('a'.repeat(8189) + '😀'), false],
|
|
294
|
+
['complete Chinese at exact sample EOF', Buffer.from('a'.repeat(8189) + '好'), false],
|
|
295
|
+
['empty file', Buffer.alloc(0), false],
|
|
296
|
+
['incomplete UTF-8 at short EOF', Buffer.from([0xe5, 0xa5]), true],
|
|
297
|
+
['incomplete UTF-8 at exact sample EOF', Buffer.concat([Buffer.alloc(8191, 0x61), Buffer.from([0xe5])]), true],
|
|
298
|
+
['invalid leading byte before non-EOF boundary', Buffer.concat([Buffer.from([0xff]), Buffer.alloc(8192, 0x61)]), true],
|
|
299
|
+
['NUL before non-EOF boundary', Buffer.concat([Buffer.from([0]), Buffer.alloc(8192, 0x61)]), true],
|
|
300
|
+
['invalid continuation at non-EOF boundary', Buffer.concat([Buffer.alloc(8190, 0x61), Buffer.from([0xe5, 0x61, 0x61])]), true],
|
|
301
|
+
['overlong sequence at non-EOF boundary', Buffer.concat([Buffer.alloc(8190, 0x61), Buffer.from([0xe0, 0x80, 0x80])]), true],
|
|
302
|
+
['surrogate at non-EOF boundary', Buffer.concat([Buffer.alloc(8190, 0x61), Buffer.from([0xed, 0xa0, 0x80])]), true],
|
|
303
|
+
['out-of-range code point at non-EOF boundary', Buffer.concat([Buffer.alloc(8190, 0x61), Buffer.from([0xf4, 0x90, 0x80, 0x80])]), true],
|
|
304
|
+
])('classifies %s', async (_name, bytes, expected) => {
|
|
305
|
+
const directory = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'yuri-binary-sample-'));
|
|
306
|
+
const filePath = path.join(directory, 'report.eficy');
|
|
307
|
+
try {
|
|
308
|
+
await fs.promises.writeFile(filePath, bytes);
|
|
309
|
+
const res = await callStat(registerStat(fs.promises), { path: filePath });
|
|
310
|
+
expect(res.statusCode).toBe(200);
|
|
311
|
+
expect(res.body).toMatchObject({ isBinary: expected });
|
|
312
|
+
} finally {
|
|
313
|
+
await fs.promises.rm(directory, { recursive: true, force: true });
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('keeps Chinese UTF-8 crossing the 8192-byte sample boundary previewable', async () => {
|
|
318
|
+
const directory = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'yuri-binary-sample-'));
|
|
319
|
+
const filePath = path.join(directory, 'report.shadcn.eficy');
|
|
320
|
+
try {
|
|
321
|
+
await fs.promises.writeFile(filePath, 'a'.repeat(8191) + '好' + 'b'.repeat(28573));
|
|
322
|
+
const res = await callStat(registerStat(fs.promises), { path: filePath });
|
|
323
|
+
expect(res.statusCode).toBe(200);
|
|
324
|
+
expect(res.body).toMatchObject({ size: 36767, isBinary: false });
|
|
325
|
+
} finally {
|
|
326
|
+
await fs.promises.rm(directory, { recursive: true, force: true });
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
288
330
|
it('reports binary content from a bounded byte sample', async () => {
|
|
289
331
|
const file = {
|
|
290
332
|
read: vi.fn(async (buffer) => {
|
|
@@ -307,6 +349,7 @@ describe('fs stat', () => {
|
|
|
307
349
|
|
|
308
350
|
it('keeps UTF-8 text previewable', async () => {
|
|
309
351
|
const file = {
|
|
352
|
+
stat: vi.fn(async () => ({ size: 23 })),
|
|
310
353
|
read: vi.fn(async (buffer) => {
|
|
311
354
|
buffer.set(Buffer.from('export const value = 1;'));
|
|
312
355
|
return { bytesRead: 23 };
|
|
@@ -20,10 +20,11 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
20
20
|
connection shortcuts to exclude themselves without changing management lists.
|
|
21
21
|
- `plugins.js`: config entries and plugin-directory files are inventory, not compatibility checks. They do not synthesize `compatibility` or `compatible` fields; Settings uses the OpenCode runtime inventory for actual load status and errors.
|
|
22
22
|
- Reads native V2 `plugins` (strings or `{ package, options }`) with legacy `plugin`/tuple fallback. A native array, including an empty one, wins within each document. Entry mutations write only `plugins`, convert retained legacy tuples, and remove the shadowed legacy key in the touched source file. Options, ordering, unrelated configuration and JSONC comments are preserved through the shared atomic config writer; malformed entries or write failures do not replace the original file. Web, Electron and mobile use this host implementation; VS Code mirrors the same persistence contract.
|
|
23
|
-
- `session-directory-runtime.js`: Host-side physical directory identity for session index/list/detail/live projection. Uses a runtime-scoped, bounded 256-entry cache (60s success / 5s failed resolution), cleared when the upstream URL changes. Local directory lists use
|
|
23
|
+
- `session-directory-runtime.js`: Host-side physical directory identity for session index/list/detail/live projection. Uses a runtime-scoped, bounded 256-entry cache (60s success / 5s failed resolution), cleared when the upstream URL changes. Local directory lists use session pages and physical-directory filtering to include legacy symlink sessions without mixing worktrees; they never request `/location` to discover project identity. Startup backfill reads one global session stream rather than one stream per project. One request reads one page and preserves opaque cursors; consumers must follow continuations even after filtered-empty pages. Non-loopback upstreams keep their own path namespace.
|
|
24
24
|
- `packages/web/server/lib/opencode/index.js`: public entrypoint (currently baseline placeholder).
|
|
25
25
|
- `packages/web/server/lib/opencode/auth.js`: host-only authoritative provider credential API reads and deletion.
|
|
26
26
|
- `packages/web/server/lib/opencode/auth-state-runtime.js`: managed OpenCode server auth password/header runtime.
|
|
27
|
+
- `gui-plugin-source.js`: process-local native GUI client admission. Requires ready managed-child/shared-service ownership plus loopback endpoint; external servers/SSH forwards cannot supply native code. The returned server controller's `getGuiPluginClient()` calls this gate, and throws stable `GUI_PLUGIN_UNTRUSTED_SOURCE` / `GUI_PLUGIN_UNAVAILABLE` codes. It is never an HTTP route or renderer-provided endpoint.
|
|
27
28
|
- `packages/web/server/lib/opencode/cli-options.js`: CLI/environment option parsing for server startup arguments.
|
|
28
29
|
- `packages/web/server/lib/opencode/cli-entry-runtime.js`: CLI entrypoint runtime that detects direct execution, forces `YURI_RUNTIME=web` unless already `ssh-remote` (so `dev:server` cannot inherit a leftover desktop env and host a relay, while SSH-managed remotes may), parses CLI options, and starts server bootstrap.
|
|
29
30
|
- `packages/web/server/lib/opencode/routes.js`: OpenCode/provider settings and auth-related route registration.
|
|
@@ -32,8 +33,8 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
32
33
|
- `packages/web/server/lib/opencode/v1-migration-gate.js`: pure V1→v2 migration admission gate (`GET /api/experimental/migration/v1` → whether transcript may be fetched).
|
|
33
34
|
- `packages/web/server/lib/opencode/managed-capabilities-runtime.js`: managed-child scheduled-task resources, config injection, rotating bridge identity, and bridge authorization.
|
|
34
35
|
- `packages/web/server/lib/opencode/env-runtime.js`: OpenCode CLI/binary resolution and shell environment runtime.
|
|
35
|
-
- `packages/web/server/lib/opencode/ensure-cli.js`: detect local `opencode` version and install the latest stable official V2 into the Yuri data dir when no usable CLI exists
|
|
36
|
-
- `packages/web/server/lib/opencode/upgrade-screen.js`: startup gate for the running OpenCode below `2.0.20`. Client/schema dependencies
|
|
36
|
+
- `packages/web/server/lib/opencode/ensure-cli.js`: detect local `opencode` version and install the latest stable official V2 into the Yuri data dir when no usable CLI exists. Registry lookup failures remain errors; verified cached installations can be reused offline. Never uses a packaged/bundled binary.
|
|
37
|
+
- `packages/web/server/lib/opencode/upgrade-screen.js`: startup gate for the running OpenCode below `2.0.20`. Client/schema dependencies accept compatible 2.x updates; fresh installations and required upgrades resolve latest stable 2.x at installation time. The compatible execution floor is independently `2.0.20` (credential API). An unreadable running version is unavailable even when the local CLI is compatible. `POST /api/opencode/install-required` upgrades the selected shared global CLI in place; other supported local installations use the owned-cache installer. Global upgrades do not persist a binary override, so subsequent launches still follow shell discovery. Success requires the running service to meet both the floor and selected target. External services are not replaced; compatible newer shared services are not automatically downgraded. Failure restores binary selection and reports `upgraded: false`, without claiming process or package-manager rollback.
|
|
37
38
|
- `packages/web/server/lib/opencode/env-config.js`: OpenCode-related environment variable parsing and validation (host/port/hostname).
|
|
38
39
|
- `packages/web/server/lib/opencode/hmr-state-runtime.js`: HMR-persistent runtime state initialization, auth-state bootstrap, and HMR sync helpers.
|
|
39
40
|
- `packages/web/server/lib/opencode/bootstrap-runtime.js`: base app bootstrap runtime for status/auth/tts/notification/Yuri route wiring.
|
|
@@ -68,6 +69,10 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
68
69
|
- `packages/web/server/lib/opencode/settings-normalization-runtime.js`: path/settings normalization and sanitization helpers runtime used by settings/routes/config wiring.
|
|
69
70
|
- `packages/web/server/lib/opencode/theme-runtime.js`: custom theme JSON validation and theme directory loading runtime for settings utility routes.
|
|
70
71
|
- `packages/web/server/lib/opencode/proxy.js`: OpenCode API/SSE forwarding and readiness-gate route registration.
|
|
72
|
+
- `plugin-gui-response.js`: shared Web/Electron/VS Code code-only revision response owner for exact `GET /api/plugin/gui?id=…` (one nonempty id). The installed GUI client alias is official `@opencode/client@2.2.0`: HTTP returns `{ location, data: { code, revision, options } }`. Every call still reads the complete current upstream response through the existing auth/readiness/abort boundary; there is no Host bundle cache.
|
|
73
|
+
- Request `X-Yuri-Gui-Revision: <lowercase SHA-256 hex of UTF-8 revision>` opts into code reuse. This header and HTTP condition/range headers are stripped before upstream so Yuri always requests a complete representation. Other query and request headers retain proxy semantics.
|
|
74
|
+
- A valid upstream 200 JSON bundle (`code` string, nonempty `revision` string, `options` object) receives `X-Yuri-Gui-Revision` and `Cache-Control: private, no-store`. Matching tokens additionally receive `X-Yuri-Gui-Code: cached` and only `data.code` becomes `''`; current `options`, `revision`, location and other fields remain. Unmatched/ordinary calls preserve original body bytes. No 304 or Yuri ETag is generated. Upstream failure statuses/bodies remain failures; malformed successful bodies remain unchanged without a revision receipt.
|
|
75
|
+
- Clients restore code before SDK decoding and may persist code/revision only, never options. Browser caches must not store these option-bearing responses. Stale validators and decoded compression/length headers are removed at the response boundary. Packaged/mobile cross-origin clients receive the two response headers through CORS; Relay forwards them transparently on the same `/api/plugin/gui` path.
|
|
71
76
|
- `packages/web/server/lib/opencode/instance-recovery-runtime.js`: directory-instance health recovery before turn admission (`prompt_async` / `command` / `shell`). When OpenCode's per-directory instance is poisoned (MCP probe returns 503 empty while HTTP still accepts prompts that immediately abort as `MessageAbortedError`), dispose the instance so the next admission recreates a healthy one.
|
|
72
77
|
- `packages/web/server/lib/opencode/session-runtime.js`: session status/attention/activity runtime for OpenCode SSE events.
|
|
73
78
|
- `packages/web/server/lib/opencode/watcher.js`: global SSE watcher runtime for push/session event fanout.
|
|
@@ -111,8 +116,8 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
111
116
|
- `POST /api/opencode/upgrade` (ticket 12): upgrades the remote latest or explicitly targeted version. Shared services using a global CLI invoke that selected installation's `upgrade <version>` and verify its disk version; owned-cache installations download into `~/.config/yuri/opencode-cli/<version>/`. Shared services restart through the selected CLI entry path and adopt its registration again. Success requires fresh CLI/service version probes and runtime contract verification. Global upgrades never switch to an owned cache on failure. Arbitrary external servers, private processes using global CLI, and private bundled binaries return HTTP 409. Concurrent upgrades are single-flight (`operation` state). Active sessions do not block an explicitly requested upgrade or require additional confirmation. Failure restores binary selection and reports the failed phase; it cannot undo package-manager changes and does not claim process restoration.
|
|
112
117
|
- `GET /api/opencode/upgrade-status`: returns `currentVersion`/`serveVersion`/`cliVersion`, `targetVersion`/`latestVersion` (official npm `@opencode/cli` latest stable 2.x release), `supplySource`, `ownership`, `canManage`, `management`, `guidance`, `contract`, and `operation`. Official shared services report `ownership: 'shared-service'`, `processOwnership: 'shared'`, and `canManage: true`. `available` is true only when `canManage` and target > current; unmanaged global/external runtimes report `available: null` plus manual guidance. `update-discovery.js` shares one in-flight registry request per host, caches successful checks for five minutes and failed checks for thirty seconds, with a five-second request deadline. Failed registry checks return HTTP 500 with `available: null`, never a false up-to-date result. An upgrade without an explicit target resolves this same remote release. Shared Web/Electron/hosted-mobile/Capacitor clients check after startup, every five minutes while visible, on focus/reconnect, and on runtime changes; query results and dismissed notifications are scoped to the host. Successful upgrade already includes process restart and live version verification, so no second reload is needed.
|
|
113
118
|
- `GET /api/opencode/compatibility`: startup upgrade-screen status. `compatible` requires the running OpenCode 2.x at `2.0.20` or newer; older/invalid versions are `incompatible`; unreadable running versions are `unavailable`. External serves are not replaced.
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
- `POST /api/opencode/install-required`: resolves the latest stable 2.x release (never below the `2.0.20` floor), upgrades the selected shared global CLI or owned cache, and restarts through the existing lifecycle. Discovery failure does not install a historical fallback. `upgraded: true` requires live version verification. Concurrent installs are single-flight; failures remain errors. Compatibility status reports the minimum before installation resolves its actual target.
|
|
120
|
+
- `GET /api/opencode/contract`: runtime contract admission for the **running serve**. Reachability, auth, execution, migration, and CLI↔serve mismatch are separate. The `2.0.20` floor is independent of installation targets; compatible newer 2.x services remain admitted. The legacy `pinnedVersion` response field is null.
|
|
116
121
|
- `GET /api/opencode/health`: probes managed OpenCode `GET /api/info` (Basic auth, 4s timeout). `healthy` is reachability/version shape via `evaluateOpenCodeHealthBody` (admits official 2.x `ServerInfo` and classic `{ healthy: true, version }`; rejects 1.x / missing / `healthy: false`). Response also includes `executionAllowed`, `protocolCompatible`, and `contract` so clients do not treat health success as full execution semantics. Upstream non-OK responses pass through status with `{ healthy: false, error, contract }`; transport failures return HTTP 503.
|
|
117
122
|
- `GET /api/opencode/version`: serve + CLI versions, mismatch flag, and contract snapshot
|
|
118
123
|
- `POST /api/opencode/directory`
|
|
@@ -145,12 +150,12 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
145
150
|
- Native `session.execution.started/succeeded/failed/interrupted` and `session.retry.scheduled` feed the same status/activity/attention transitions. Shutdown interruption retains busy ownership; other terminal events settle idle. `extractSessionStatusUpdate` is shared by Host forwarding, index ingestion and Goal timer handling so retry metadata and shutdown semantics stay aligned.
|
|
146
151
|
|
|
147
152
|
## Public exports (opencode2-pin.js)
|
|
148
|
-
- `
|
|
153
|
+
- `MINIMUM_OPENCODE2_VERSION`: compatibility floor, not an installation pin.
|
|
149
154
|
- `OPENCODE2_NPM_PACKAGE`: `@opencode/cli` (global install that ships the official `opencode` v2 binary; not 1.x `opencode-ai`).
|
|
150
155
|
- `parseOpenCode2VersionOutput(stdout)` / `compareOpenCode2Versions(left, right)` / `isOpenCode2VersionAtLeast(version, minimum)`: CLI `--version` parse and pin comparison.
|
|
151
156
|
- `openCode2BinaryName(platform)` / `npmPackageForOpenCode2(platform, arch)`: staged binary name `opencode` (`opencode.exe` on Windows) and official platform package `@opencode/cli-<os>-<arch>[-baseline]`.
|
|
152
157
|
- `isOpenCode1xVersion(value)` / `isAcceptableOpenCode2HealthVersion(value)` / `evaluateOpenCodeHealthBody(body)`: health admission accepts only 2.x. 1.x, `0.x` pre-2 binaries, and missing/unknown versions are rejected even when `healthy: true`.
|
|
153
|
-
- `resolveOpenCode2UpgradeTarget(target)` / `rejectOpenCode1xUpgradeTarget(target)`:
|
|
158
|
+
- `resolveOpenCode2UpgradeTarget(target)` / `rejectOpenCode1xUpgradeTarget(target)`: require a resolved upgrade target and refuse 1.x; no historical default.
|
|
154
159
|
|
|
155
160
|
## Public exports (runtime-contract.js)
|
|
156
161
|
- Pure admission matrix. `RUNTIME_CONTRACT_MIN_VERIFIED` (`2.0.20`) is the documented 2.x floor, shared with the startup gate through `MINIMUM_OPENCODE2_VERSION`; the VS Code sidecar mirrors this floor. Capabilities include `core.protocol`, `session.prompt`, `session.queuedInput`, `session.background`, `session.generationFallback`, `migration.v1Read`.
|
|
@@ -167,8 +172,8 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
167
172
|
- `buildUpgradeStatusSnapshot` / `evaluateOwnedUpgradeResult` / `createUpgradeOperationState` / `resolveOwnedCacheBinaryPath`.
|
|
168
173
|
|
|
169
174
|
## Public exports (ensure-cli.js)
|
|
170
|
-
- `ensurePinnedOpenCode2Cli({ discoveredPath, pin, autoInstall, install, readVersion })`: reuse any discovered acceptable 2.x CLI (official name `opencode`), then the newest verified owned cache. Only a fresh installation queries the stable 2.x release via `update-discovery.js`;
|
|
171
|
-
- `installPinnedOpenCode2Cli(options)`: download `@opencode/cli-<os>-<arch
|
|
175
|
+
- `ensurePinnedOpenCode2Cli({ discoveredPath, pin, autoInstall, install, readVersion })`: reuse any discovered acceptable 2.x CLI (official name `opencode`), then the newest verified owned cache. Only a fresh installation queries the stable 2.x release via `update-discovery.js`; the optional explicit `pin` remains an override, not a product default. Registry errors propagate without a historical fallback. Downloads stay under `~/.config/yuri/opencode-cli/<version>/opencode`. `YURI_OPENCODE2_AUTO_INSTALL=0` disables download (`OPENCODE_CLI_MISSING`).
|
|
176
|
+
- `installPinnedOpenCode2Cli(options)`: resolve latest stable 2.x unless a concrete version was supplied, download its `@opencode/cli-<os>-<arch>` package, extract, copy as `opencode`, chmod, verify `--version` against the resolved version.
|
|
172
177
|
- `installedOpenCode2BinaryPath(version)` / `installedOpenCode2BinaryCandidates(options)` / `readOpenCode2BinaryVersion(path)` / `isOpenCode2AutoInstallEnabled()`. Cache candidates are stable 2.x directories ordered by numeric version, so an offline restart discovers a newer installation rather than reverting to the packaged pin.
|
|
173
178
|
- `terminal-path.js` exposes owned-cache CLIs to new terminals on installation/reuse. It writes an idempotent source line to zsh `.zprofile`/`.zshrc` (including `ZDOTDIR`), bash `.bashrc` and the active login profile, POSIX `.profile`, or fish `config.fish`. The sourced file in the Yuri data directory selects the verified executable directory. Windows updates only user PATH, retaining unrelated entries, broadcasts the environment change, and records `opencode-path.windows` in the data directory. Subsequent owned-cache upgrades refresh an existing terminal integration after binary verification. Existing global installations do not trigger shell edits. PATH-setup failure warns and keeps the working Yuri runtime; a later startup retries. Existing terminal processes need a new shell, and shell-file changes already completed before a failure are retained.
|
|
174
179
|
- `upgradeSelectedOpenCodeCli({ binaryPath, version, launchSpec, env })`: runs the selected CLI's official `upgrade <version>` without a shell, with a five-minute deadline and bounded captured output. Returns the original CLI entry path, preserving Homebrew symlinks. Windows launch specs unwrap native/runtime shims; unresolved batch wrappers require terminal upgrade instead of spawning console grandchildren. Child output is not returned or logged. Package-manager failures never fall back to another installation; callers verify the original entry's version before restarting. Package-manager file changes cannot be rolled back by restoring Yuri's binary selection.
|
|
@@ -5,7 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import { createOpenCodeUpdateDiscovery } from './update-discovery.js';
|
|
6
6
|
import { configureOpenCodeTerminalPath } from './terminal-path.js';
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
MINIMUM_OPENCODE2_VERSION,
|
|
9
9
|
compareOpenCode2Versions,
|
|
10
10
|
isAcceptableOpenCode2HealthVersion,
|
|
11
11
|
isOpenCode2VersionAtLeast,
|
|
@@ -54,7 +54,7 @@ export function resolveYuriDataDir(env = process.env, homedir = os.homedir) {
|
|
|
54
54
|
return path.join(home, '.config', 'yuri');
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function installedOpenCode2BinaryPath(version =
|
|
57
|
+
export function installedOpenCode2BinaryPath(version = MINIMUM_OPENCODE2_VERSION, options = {}) {
|
|
58
58
|
const dataDir = options.dataDir || resolveYuriDataDir(options.env, options.homedir);
|
|
59
59
|
return path.join(dataDir, 'opencode-cli', version, openCodeBinaryName(options.platform));
|
|
60
60
|
}
|
|
@@ -160,7 +160,10 @@ const findBinary = (root, binaryName) => {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
export async function installPinnedOpenCode2Cli(options = {}) {
|
|
163
|
-
const version = options.version ||
|
|
163
|
+
const version = options.version || await discoverLatestVersion();
|
|
164
|
+
if (!/^2\.\d+\.\d+$/.test(version) || (!options.version && !isOpenCode2VersionAtLeast(version))) {
|
|
165
|
+
throw new Error(`Invalid stable OpenCode installation target: ${version}`);
|
|
166
|
+
}
|
|
164
167
|
const platform = options.platform || process.platform;
|
|
165
168
|
const arch = options.arch || process.arch;
|
|
166
169
|
const dataDir = options.dataDir || resolveYuriDataDir(options.env, options.homedir);
|
|
@@ -239,10 +242,10 @@ export async function installPinnedOpenCode2Cli(options = {}) {
|
|
|
239
242
|
|
|
240
243
|
/**
|
|
241
244
|
* Reuse any discovered acceptable 2.x CLI. Fresh installs resolve stable 2.x;
|
|
242
|
-
*
|
|
245
|
+
* registry failures remain errors when no usable local installation exists.
|
|
243
246
|
*/
|
|
244
247
|
export async function ensurePinnedOpenCode2Cli(input = {}) {
|
|
245
|
-
const pin = input.pin ||
|
|
248
|
+
const pin = input.pin || MINIMUM_OPENCODE2_VERSION;
|
|
246
249
|
const discoveredPath = typeof input.discoveredPath === 'string' ? input.discoveredPath.trim() : '';
|
|
247
250
|
const autoInstall = input.autoInstall ?? isOpenCode2AutoInstallEnabled(input.env);
|
|
248
251
|
const readVersion = typeof input.readVersion === 'function'
|
|
@@ -276,20 +279,15 @@ export async function ensurePinnedOpenCode2Cli(input = {}) {
|
|
|
276
279
|
|
|
277
280
|
if (!autoInstall) {
|
|
278
281
|
const error = new Error(
|
|
279
|
-
|
|
282
|
+
'Unable to locate OpenCode 2. Set OPENCODE_BINARY or install @opencode/cli@2.',
|
|
280
283
|
);
|
|
281
284
|
error.code = 'OPENCODE_CLI_MISSING';
|
|
282
285
|
throw error;
|
|
283
286
|
}
|
|
284
287
|
|
|
285
|
-
|
|
286
|
-
if (!
|
|
287
|
-
|
|
288
|
-
const latest = await (input.resolveLatestVersion || discoverLatestVersion)();
|
|
289
|
-
if (/^2\.\d+\.\d+$/.test(latest) && isOpenCode2VersionAtLeast(latest, pin)) target = latest;
|
|
290
|
-
} catch {
|
|
291
|
-
console.warn('[OpenCode] Latest version lookup failed; using the tested fallback version.');
|
|
292
|
-
}
|
|
288
|
+
const target = input.pin || await (input.resolveLatestVersion || discoverLatestVersion)();
|
|
289
|
+
if (!/^2\.\d+\.\d+$/.test(target) || !isOpenCode2VersionAtLeast(target)) {
|
|
290
|
+
throw new Error(`Invalid stable OpenCode installation target: ${target}`);
|
|
293
291
|
}
|
|
294
292
|
const installedPath = await install({ ...input, version: target });
|
|
295
293
|
const version = readVersion(installedPath);
|