daemon: prefer symlinked paths over realpath for stable service configs (#1505)
When installing the LaunchAgent/systemd service, the CLI was using fs.realpath() to resolve the entry.js path, which converted stable symlinked paths (e.g. node_modules/clawdbot) into version-specific paths (e.g. .pnpm/clawdbot@X.Y.Z/...). This caused the service to break after pnpm updates because the old versioned path no longer exists, even though the symlink still works. Now we prefer the original (symlinked) path when it's valid, keeping service configs stable across package version updates.
This commit is contained in:
@@ -27,6 +27,20 @@ async function resolveCliEntrypointPathForService(): Promise<string> {
|
||||
const looksLikeDist = /[/\\]dist[/\\].+\.(cjs|js|mjs)$/.test(resolvedPath);
|
||||
if (looksLikeDist) {
|
||||
await fs.access(resolvedPath);
|
||||
// Prefer the original (possibly symlinked) path over the resolved realpath.
|
||||
// This keeps LaunchAgent/systemd paths stable across package version updates,
|
||||
// since symlinks like node_modules/clawdbot -> .pnpm/clawdbot@X.Y.Z/...
|
||||
// are automatically updated by pnpm, while the resolved path contains
|
||||
// version-specific directories that break after updates.
|
||||
const normalizedLooksLikeDist = /[/\\]dist[/\\].+\.(cjs|js|mjs)$/.test(normalized);
|
||||
if (normalizedLooksLikeDist && normalized !== resolvedPath) {
|
||||
try {
|
||||
await fs.access(normalized);
|
||||
return normalized;
|
||||
} catch {
|
||||
// Fall through to return resolvedPath
|
||||
}
|
||||
}
|
||||
return resolvedPath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user