fix(workspace): align clawd + bootstrap
This commit is contained in:
@@ -268,9 +268,9 @@ describe("doctor", () => {
|
||||
parsed: {
|
||||
gateway: { mode: "local", bind: "loopback" },
|
||||
agent: {
|
||||
workspace: "/Users/steipete/clawdbot",
|
||||
workspace: "/Users/steipete/clawd",
|
||||
sandbox: {
|
||||
workspaceRoot: "/Users/steipete/clawdbot/sandboxes",
|
||||
workspaceRoot: "/Users/steipete/clawd/sandboxes",
|
||||
docker: {
|
||||
image: "clawdbot-sandbox",
|
||||
containerPrefix: "clawdbot-sbx",
|
||||
@@ -282,9 +282,9 @@ describe("doctor", () => {
|
||||
config: {
|
||||
gateway: { mode: "local", bind: "loopback" },
|
||||
agent: {
|
||||
workspace: "/Users/steipete/clawdbot",
|
||||
workspace: "/Users/steipete/clawd",
|
||||
sandbox: {
|
||||
workspaceRoot: "/Users/steipete/clawdbot/sandboxes",
|
||||
workspaceRoot: "/Users/steipete/clawd/sandboxes",
|
||||
docker: {
|
||||
image: "clawdbot-sandbox",
|
||||
containerPrefix: "clawdbot-sbx",
|
||||
@@ -365,8 +365,8 @@ describe("doctor", () => {
|
||||
const sandbox = agent.sandbox as Record<string, unknown>;
|
||||
const docker = sandbox.docker as Record<string, unknown>;
|
||||
|
||||
expect(agent.workspace).toBe("/Users/steipete/clawdbot");
|
||||
expect(sandbox.workspaceRoot).toBe("/Users/steipete/clawdbot/sandboxes");
|
||||
expect(agent.workspace).toBe("/Users/steipete/clawd");
|
||||
expect(sandbox.workspaceRoot).toBe("/Users/steipete/clawd/sandboxes");
|
||||
expect(docker.image).toBe("clawdbot-sandbox");
|
||||
expect(docker.containerPrefix).toBe("clawdbot-sbx");
|
||||
});
|
||||
|
||||
@@ -247,15 +247,28 @@ async function noteSecurityWarnings(cfg: ClawdbotConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
function replacePathSegment(
|
||||
function normalizeDefaultWorkspacePath(
|
||||
value: string | undefined,
|
||||
from: string,
|
||||
to: string,
|
||||
): string | undefined {
|
||||
if (!value) return value;
|
||||
const pattern = new RegExp(`(^|[\\/])${from}([\\/]|$)`, "g");
|
||||
if (!pattern.test(value)) return value;
|
||||
return value.replace(pattern, `$1${to}$2`);
|
||||
|
||||
const resolved = resolveUserPath(value);
|
||||
const home = os.homedir();
|
||||
|
||||
const next = [
|
||||
["clawdis", "clawd"],
|
||||
["clawdbot", "clawd"],
|
||||
].reduce((acc, [from, to]) => {
|
||||
const fromPrefix = path.join(home, from);
|
||||
if (acc === fromPrefix) return path.join(home, to);
|
||||
const withSep = `${fromPrefix}${path.sep}`;
|
||||
if (acc.startsWith(withSep)) {
|
||||
return path.join(home, to).concat(acc.slice(fromPrefix.length));
|
||||
}
|
||||
return acc;
|
||||
}, resolved);
|
||||
|
||||
return next === resolved ? value : next;
|
||||
}
|
||||
|
||||
function replaceLegacyName(value: string | undefined): string | undefined {
|
||||
@@ -556,11 +569,7 @@ function normalizeLegacyConfigValues(cfg: ClawdbotConfig): {
|
||||
let next: ClawdbotConfig = cfg;
|
||||
|
||||
const workspace = cfg.agent?.workspace;
|
||||
const updatedWorkspace = replacePathSegment(
|
||||
replacePathSegment(workspace, "clawdis", "clawdbot"),
|
||||
"clawd",
|
||||
"clawdbot",
|
||||
);
|
||||
const updatedWorkspace = normalizeDefaultWorkspacePath(workspace);
|
||||
if (updatedWorkspace && updatedWorkspace !== workspace) {
|
||||
next = {
|
||||
...next,
|
||||
@@ -573,11 +582,7 @@ function normalizeLegacyConfigValues(cfg: ClawdbotConfig): {
|
||||
}
|
||||
|
||||
const workspaceRoot = cfg.agent?.sandbox?.workspaceRoot;
|
||||
const updatedWorkspaceRoot = replacePathSegment(
|
||||
replacePathSegment(workspaceRoot, "clawdis", "clawdbot"),
|
||||
"clawd",
|
||||
"clawdbot",
|
||||
);
|
||||
const updatedWorkspaceRoot = normalizeDefaultWorkspacePath(workspaceRoot);
|
||||
if (updatedWorkspaceRoot && updatedWorkspaceRoot !== workspaceRoot) {
|
||||
next = {
|
||||
...next,
|
||||
|
||||
@@ -223,10 +223,11 @@ export async function openUrl(url: string): Promise<boolean> {
|
||||
export async function ensureWorkspaceAndSessions(
|
||||
workspaceDir: string,
|
||||
runtime: RuntimeEnv,
|
||||
options?: { skipBootstrap?: boolean },
|
||||
) {
|
||||
const ws = await ensureAgentWorkspace({
|
||||
dir: workspaceDir,
|
||||
ensureBootstrapFiles: true,
|
||||
ensureBootstrapFiles: !options?.skipBootstrap,
|
||||
});
|
||||
runtime.log(`Workspace OK: ${ws.dir}`);
|
||||
const sessionsDir = resolveSessionTranscriptsDir();
|
||||
|
||||
@@ -219,7 +219,9 @@ export async function runNonInteractiveOnboarding(
|
||||
nextConfig = applyWizardMetadata(nextConfig, { command: "onboard", mode });
|
||||
await writeConfigFile(nextConfig);
|
||||
runtime.log(`Updated ${CONFIG_PATH_CLAWDBOT}`);
|
||||
await ensureWorkspaceAndSessions(workspaceDir, runtime);
|
||||
await ensureWorkspaceAndSessions(workspaceDir, runtime, {
|
||||
skipBootstrap: Boolean(nextConfig.agent?.skipBootstrap),
|
||||
});
|
||||
|
||||
if (opts.installDaemon) {
|
||||
const service = resolveGatewayService();
|
||||
|
||||
@@ -74,7 +74,7 @@ export async function setupCommand(
|
||||
|
||||
const ws = await ensureAgentWorkspace({
|
||||
dir: workspace,
|
||||
ensureBootstrapFiles: true,
|
||||
ensureBootstrapFiles: !next.agent?.skipBootstrap,
|
||||
});
|
||||
runtime.log(`Workspace OK: ${ws.dir}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user