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:
George Zhang
2026-01-23 19:52:26 +08:00
committed by GitHub
parent 2c85b1b409
commit bfbeea0f20
2 changed files with 34 additions and 0 deletions

View File

@@ -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;
}