fix(update): harden root selection

This commit is contained in:
Peter Steinberger
2026-01-10 20:32:15 +01:00
parent 777fb6b7bb
commit 4c4c167416
7 changed files with 209 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
import type { Command } from "commander";
import { resolveClawdbotPackageRoot } from "../infra/clawdbot-root.js";
import {
runGatewayUpdate,
type UpdateRunResult,
@@ -103,8 +104,15 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
defaultRuntime.log("");
}
const root =
(await resolveClawdbotPackageRoot({
moduleUrl: import.meta.url,
argv1: process.argv[1],
cwd: process.cwd(),
})) ?? process.cwd();
const result = await runGatewayUpdate({
cwd: process.cwd(),
cwd: root,
argv1: process.argv[1],
timeoutMs,
});
@@ -124,6 +132,18 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
),
);
}
if (result.reason === "not-git-install") {
defaultRuntime.log(
theme.warn(
"Skipped: this Clawdbot install isn't a git checkout. Update via your package manager, then run `clawdbot doctor` and `clawdbot daemon restart`.",
),
);
defaultRuntime.log(
theme.muted(
"Examples: `npm i -g clawdbot@latest` or `pnpm add -g clawdbot@latest`",
),
);
}
defaultRuntime.exit(0);
return;
}
@@ -141,9 +161,7 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
}
} catch (err) {
if (!opts.json) {
defaultRuntime.log(
theme.warn(`Daemon restart failed: ${String(err)}`),
);
defaultRuntime.log(theme.warn(`Daemon restart failed: ${String(err)}`));
defaultRuntime.log(
theme.muted(
"You may need to restart the daemon manually: clawdbot daemon restart",
@@ -179,14 +197,14 @@ export function registerUpdateCli(program: Command) {
"after",
`
Examples:
clawdbot update # Update from git or package manager
clawdbot update # Update a source checkout (git)
clawdbot update --restart # Update and restart the daemon
clawdbot update --json # Output result as JSON
clawdbot --update # Shorthand for clawdbot update
Notes:
- For git installs: fetches, rebases, installs deps, builds, and runs doctor
- For npm installs: runs package manager update command
- For npm installs: use npm/pnpm to reinstall (see docs/install/updating.md)
- Skips update if the working directory has uncommitted changes
`,
)