Files
openclaw-zero-token/config/normalize-paths.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

70 lines
1.8 KiB
TypeScript

import { isPlainObject, resolveUserPath } from "../utils.js";
import type { OpenClawConfig } from "./types.js";
const PATH_VALUE_RE = /^~(?=$|[\\/])/;
const PATH_KEY_RE = /(dir|path|paths|file|root|workspace)$/i;
const PATH_LIST_KEYS = new Set(["paths", "pathPrepend"]);
function normalizeStringValue(key: string | undefined, value: string): string {
if (!PATH_VALUE_RE.test(value.trim())) {
return value;
}
if (!key) {
return value;
}
if (PATH_KEY_RE.test(key) || PATH_LIST_KEYS.has(key)) {
return resolveUserPath(value);
}
return value;
}
function normalizeAny(key: string | undefined, value: unknown): unknown {
if (typeof value === "string") {
return normalizeStringValue(key, value);
}
if (Array.isArray(value)) {
const normalizeChildren = Boolean(key && PATH_LIST_KEYS.has(key));
return value.map((entry) => {
if (typeof entry === "string") {
return normalizeChildren ? normalizeStringValue(key, entry) : entry;
}
if (Array.isArray(entry)) {
return normalizeAny(undefined, entry);
}
if (isPlainObject(entry)) {
return normalizeAny(undefined, entry);
}
return entry;
});
}
if (!isPlainObject(value)) {
return value;
}
for (const [childKey, childValue] of Object.entries(value)) {
const next = normalizeAny(childKey, childValue);
if (next !== childValue) {
value[childKey] = next;
}
}
return value;
}
/**
* Normalize "~" paths in path-ish config fields.
*
* Goal: accept `~/...` consistently across config file + env overrides, while
* keeping the surface area small and predictable.
*/
export function normalizeConfigPaths(cfg: OpenClawConfig): OpenClawConfig {
if (!cfg || typeof cfg !== "object") {
return cfg;
}
normalizeAny(undefined, cfg);
return cfg;
}