






















@@ -1,3 +1,9 @@
1+/**
2+ * Minimal setup command.
3+ *
4+ * Ensures config, default workspace, and session directories exist without
5+ * running the full onboarding wizard.
6+ */
17import fs from "node:fs/promises";
28import JSON5 from "json5";
39import { z } from "zod";
@@ -53,6 +59,8 @@ const configLoggingModuleLoader = createLazyImportLoader<ConfigLoggingModule>(
5359() => import("../config/logging.js"),
5460);
556162+// Keep setup's cold path small; config/workspace modules are loaded only when
63+// their default dependency is actually needed.
5664function loadAgentWorkspaceModule(): Promise<AgentWorkspaceModule> {
5765return agentWorkspaceModuleLoader.load();
5866}
@@ -124,10 +132,13 @@ async function readConfigFileRaw(configPath: string): Promise<{
124132const parsed = safeParseWithSchema(JsonRecordSchema, JSON5.parse(raw));
125133return { exists: true, parsed: (parsed ?? {}) as OpenClawConfig };
126134} catch {
135+// Missing or malformed config should not block setup; setup writes only the
136+// minimal defaults it owns and leaves deeper repair to doctor/onboard.
127137return { exists: false, parsed: {} };
128138}
129139}
130140141+/** Prepares config, workspace, and session directories for a usable installation. */
131142export async function setupCommand(
132143opts?: { workspace?: string },
133144runtime: RuntimeEnv = defaultRuntime,
@@ -167,6 +178,8 @@ export async function setupCommand(
167178defaults.workspace !== workspace ||
168179cfg.gateway?.mode !== next.gateway?.mode
169180) {
181+// Preserve all existing config fields and touch only workspace/gateway mode
182+// defaults that this command owns.
170183const replaceConfig =
171184deps.replaceConfigFile ?? ((params) => writeDefaultConfigFile(params.nextConfig));
172185await replaceConfig({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。