@@ -1413,6 +1413,45 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
14131413 ) ;
14141414 }
14151415
1416+ async function readSourceConfigBestEffort ( ) : Promise < OpenClawConfig > {
1417+ maybeLoadDotEnvForConfig ( deps . env ) ;
1418+ const exists = deps . fs . existsSync ( configPath ) ;
1419+ if ( ! exists ) {
1420+ return { } ;
1421+ }
1422+
1423+ try {
1424+ const raw = deps . fs . readFileSync ( configPath , "utf-8" ) ;
1425+ const parsedRes = parseConfigJson5 ( raw , deps . json5 ) ;
1426+ if ( ! parsedRes . ok ) {
1427+ return { } ;
1428+ }
1429+
1430+ const recovered = await maybeRecoverSuspiciousConfigRead ( {
1431+ deps,
1432+ configPath,
1433+ raw,
1434+ parsed : parsedRes . parsed ,
1435+ } ) ;
1436+
1437+ let resolved : unknown ;
1438+ try {
1439+ resolved = resolveConfigIncludesForRead ( recovered . parsed , configPath , deps ) ;
1440+ } catch {
1441+ return coerceConfig ( recovered . parsed ) ;
1442+ }
1443+
1444+ const readResolution = resolveConfigForRead ( resolved , deps . env ) ;
1445+ const legacyResolution = resolveLegacyConfigForRead (
1446+ readResolution . resolvedConfigRaw ,
1447+ recovered . parsed ,
1448+ ) ;
1449+ return coerceConfig ( legacyResolution . effectiveConfigRaw ) ;
1450+ } catch {
1451+ return { } ;
1452+ }
1453+ }
1454+
14161455 async function writeConfigFile (
14171456 cfg : OpenClawConfig ,
14181457 options : ConfigWriteOptions = { } ,
@@ -1674,6 +1713,7 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
16741713 configPath,
16751714 loadConfig,
16761715 readBestEffortConfig,
1716+ readSourceConfigBestEffort,
16771717 readConfigFileSnapshot,
16781718 readConfigFileSnapshotForWrite,
16791719 writeConfigFile,
@@ -1768,6 +1808,10 @@ export async function readBestEffortConfig(): Promise<OpenClawConfig> {
17681808 return await createConfigIO ( ) . readBestEffortConfig ( ) ;
17691809}
17701810
1811+ export async function readSourceConfigBestEffort ( ) : Promise < OpenClawConfig > {
1812+ return await createConfigIO ( ) . readSourceConfigBestEffort ( ) ;
1813+ }
1814+
17711815export async function readConfigFileSnapshot ( ) : Promise < ConfigFileSnapshot > {
17721816 return await createConfigIO ( ) . readConfigFileSnapshot ( ) ;
17731817}
0 commit comments