fix(config): reject shared agentDir

This commit is contained in:
Peter Steinberger
2026-01-08 11:53:01 +01:00
parent aa34d7d5f2
commit f24a4626e3
4 changed files with 193 additions and 0 deletions

View File

@@ -8,6 +8,10 @@ import {
resolveShellEnvFallbackTimeoutMs,
shouldEnableShellEnvFallback,
} from "../infra/shell-env.js";
import {
DuplicateAgentDirError,
findDuplicateAgentDirs,
} from "./agent-dirs.js";
import {
applyIdentityDefaults,
applyLoggingDefaults,
@@ -140,6 +144,14 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
),
);
const duplicates = findDuplicateAgentDirs(cfg, {
env: deps.env,
homedir: deps.homedir,
});
if (duplicates.length > 0) {
throw new DuplicateAgentDirError(duplicates);
}
const enabled =
shouldEnableShellEnvFallback(deps.env) ||
cfg.env?.shellEnv?.enabled === true;
@@ -157,6 +169,10 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
return cfg;
} catch (err) {
if (err instanceof DuplicateAgentDirError) {
deps.logger.error(err.message);
throw err;
}
deps.logger.error(`Failed to read config at ${configPath}`, err);
return {};
}