2026-03-31 18:47:00 +03:00
|
|
|
export const createOpenCodeResolutionRuntime = (dependencies) => {
|
|
|
|
|
const {
|
|
|
|
|
path,
|
|
|
|
|
resolveOpencodeCliPath,
|
|
|
|
|
applyOpencodeBinaryFromSettings,
|
|
|
|
|
ensureOpencodeCliEnv,
|
2026-04-12 07:29:09 +12:00
|
|
|
resolveManagedOpenCodeLaunchSpec,
|
2026-03-31 18:47:00 +03:00
|
|
|
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;
|
2026-04-12 07:29:09 +12:00
|
|
|
const launchSpec = resolved && !useWslForOpencode
|
|
|
|
|
? resolveManagedOpenCodeLaunchSpec(resolved)
|
|
|
|
|
: null;
|
2026-03-31 18:47:00 +03:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
configured,
|
|
|
|
|
resolved,
|
|
|
|
|
resolvedDir: resolved ? path.dirname(resolved) : null,
|
|
|
|
|
source,
|
|
|
|
|
detectedNow,
|
|
|
|
|
detectedSourceNow,
|
2026-04-12 07:29:09 +12:00
|
|
|
launchBinary: launchSpec?.binary || null,
|
|
|
|
|
launchArgs: launchSpec?.args || [],
|
|
|
|
|
launchWrapperType: launchSpec?.wrapperType || null,
|
2026-03-31 18:47:00 +03:00
|
|
|
viaWsl: useWslForOpencode,
|
|
|
|
|
wslBinary: resolvedWslBinary || null,
|
|
|
|
|
wslPath: resolvedWslOpencodePath || null,
|
|
|
|
|
wslDistro: resolvedWslDistro || null,
|
|
|
|
|
node: resolvedNodeBinary || null,
|
|
|
|
|
bun: resolvedBunBinary || null,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
getOpenCodeResolutionSnapshot,
|
|
|
|
|
};
|
|
|
|
|
};
|