diff --git a/src/infra/openclaw-root.ts b/src/infra/openclaw-root.ts index 2beb3e8f0c4..257b547f1ff 100644 --- a/src/infra/openclaw-root.ts +++ b/src/infra/openclaw-root.ts @@ -87,19 +87,7 @@ export async function resolveOpenClawPackageRoot(opts: { argv1?: string; moduleUrl?: string; }): Promise { - const candidates: string[] = []; - - if (opts.moduleUrl) { - candidates.push(path.dirname(fileURLToPath(opts.moduleUrl))); - } - if (opts.argv1) { - candidates.push(...candidateDirsFromArgv1(opts.argv1)); - } - if (opts.cwd) { - candidates.push(opts.cwd); - } - - for (const candidate of candidates) { + for (const candidate of buildCandidates(opts)) { const found = await findPackageRoot(candidate); if (found) { return found; @@ -114,6 +102,17 @@ export function resolveOpenClawPackageRootSync(opts: { argv1?: string; moduleUrl?: string; }): string | null { + for (const candidate of buildCandidates(opts)) { + const found = findPackageRootSync(candidate); + if (found) { + return found; + } + } + + return null; +} + +function buildCandidates(opts: { cwd?: string; argv1?: string; moduleUrl?: string }): string[] { const candidates: string[] = []; if (opts.moduleUrl) { @@ -126,12 +125,5 @@ export function resolveOpenClawPackageRootSync(opts: { candidates.push(opts.cwd); } - for (const candidate of candidates) { - const found = findPackageRootSync(candidate); - if (found) { - return found; - } - } - - return null; + return candidates; }