Files
openchamber/packages/web/server/lib/opencode/opencode-resolution-runtime.js
T
Dr. ZedandBohdan Triapitsyn 636dcd5314 fix: improve Windows managed OpenCode shutdown and launch behavior (#844)
* fix: windows shutdown and restart orphaned cleanup

* fix: launch managed OpenCode directly on Windows
Unwrap OpenCode wrappers to launch directly on Windows, improving shutdown reliability and avoid orphans.

* fix: restore desktopNotifyEnabled in health snapshot

---------

Signed-off-by: Dr. Zed <142888684+DocterZed@users.noreply.github.com>
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-04-11 22:29:09 +03:00

72 lines
2.1 KiB
JavaScript

export const createOpenCodeResolutionRuntime = (dependencies) => {
const {
path,
resolveOpencodeCliPath,
applyOpencodeBinaryFromSettings,
ensureOpencodeCliEnv,
resolveManagedOpenCodeLaunchSpec,
getResolvedState,
setResolvedOpencodeBinarySource,
} = dependencies;
const getOpenCodeResolutionSnapshot = async (settings) => {
const configured = typeof settings?.opencodeBinary === 'string' ? settings.opencodeBinary : null;
const { resolvedOpencodeBinarySource: previousSource } = getResolvedState();
const detectedNow = resolveOpencodeCliPath();
const { resolvedOpencodeBinarySource: rawDetectedSourceNow } = getResolvedState();
setResolvedOpencodeBinarySource(previousSource);
await applyOpencodeBinaryFromSettings();
ensureOpencodeCliEnv();
const {
resolvedOpencodeBinary,
resolvedOpencodeBinarySource,
useWslForOpencode,
resolvedWslBinary,
resolvedWslOpencodePath,
resolvedWslDistro,
resolvedNodeBinary,
resolvedBunBinary,
} = getResolvedState();
const resolved = resolvedOpencodeBinary || null;
const source = resolvedOpencodeBinarySource || null;
const detectedSourceNow =
detectedNow &&
resolved &&
detectedNow === resolved &&
rawDetectedSourceNow === 'env' &&
source &&
source !== 'env'
? source
: rawDetectedSourceNow;
const launchSpec = resolved && !useWslForOpencode
? resolveManagedOpenCodeLaunchSpec(resolved)
: null;
return {
configured,
resolved,
resolvedDir: resolved ? path.dirname(resolved) : null,
source,
detectedNow,
detectedSourceNow,
launchBinary: launchSpec?.binary || null,
launchArgs: launchSpec?.args || [],
launchWrapperType: launchSpec?.wrapperType || null,
viaWsl: useWslForOpencode,
wslBinary: resolvedWslBinary || null,
wslPath: resolvedWslOpencodePath || null,
wslDistro: resolvedWslDistro || null,
node: resolvedNodeBinary || null,
bun: resolvedBunBinary || null,
};
};
return {
getOpenCodeResolutionSnapshot,
};
};