fix: preserve user PATH for managed opencode

This commit is contained in:
Bohdan Triapitsyn
2026-04-25 20:44:07 +03:00
parent d40041fccd
commit 836d1b1b3b
7 changed files with 318 additions and 49 deletions
+17 -18
View File
@@ -162,24 +162,19 @@ export const createOpenCodeEnvRuntime = (deps) => {
return null;
};
const mergePathValues = (preferred, fallback) => {
const merged = new Set();
const pathLooksUserConfigured = (value) => {
if (typeof value !== 'string' || !value) {
return false;
}
const addSegments = (value) => {
if (typeof value !== 'string' || !value) {
return;
}
for (const segment of value.split(path.delimiter)) {
if (segment) {
merged.add(segment);
}
}
};
addSegments(preferred);
addSegments(fallback);
return Array.from(merged).join(path.delimiter);
const home = os.homedir();
return value.split(path.delimiter).some((segment) => (
segment.startsWith(home + path.sep)
|| segment === home
|| segment.startsWith('/opt/homebrew/')
|| segment.startsWith('/opt/pkg/')
|| segment.startsWith('/opt/pmk/')
));
};
const applyLoginShellEnvSnapshot = () => {
@@ -200,7 +195,11 @@ export const createOpenCodeEnvRuntime = (deps) => {
process.env[key] = value;
}
process.env.PATH = mergePathValues(snapshot.PATH || '', process.env.PATH || '');
const currentPath = process.env.PATH || '';
const shellPath = snapshot.PATH || '';
if (!pathLooksUserConfigured(currentPath) && shellPath) {
process.env.PATH = shellPath;
}
};
const isWslExecutableValue = (value) => {