mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 20:00:21 +00:00
refactor: dedupe string list helpers
This commit is contained in:
@@ -3,29 +3,23 @@ import {
|
||||
loadExtraBootstrapFilesWithDiagnostics,
|
||||
} from "../../../agents/workspace.js";
|
||||
import { createSubsystemLogger } from "../../../logging/subsystem.js";
|
||||
import { normalizeTrimmedStringList } from "../../../shared/string-normalization.js";
|
||||
import { resolveHookConfig } from "../../config.js";
|
||||
import { isAgentBootstrapEvent, type HookHandler } from "../../hooks.js";
|
||||
|
||||
const HOOK_KEY = "bootstrap-extra-files";
|
||||
const log = createSubsystemLogger("bootstrap-extra-files");
|
||||
|
||||
function normalizeStringArray(value: unknown): string[] {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
return value.map((v) => (typeof v === "string" ? v.trim() : "")).filter(Boolean);
|
||||
}
|
||||
|
||||
function resolveExtraBootstrapPatterns(hookConfig: Record<string, unknown>): string[] {
|
||||
const fromPaths = normalizeStringArray(hookConfig.paths);
|
||||
const fromPaths = normalizeTrimmedStringList(hookConfig.paths);
|
||||
if (fromPaths.length > 0) {
|
||||
return fromPaths;
|
||||
}
|
||||
const fromPatterns = normalizeStringArray(hookConfig.patterns);
|
||||
const fromPatterns = normalizeTrimmedStringList(hookConfig.patterns);
|
||||
if (fromPatterns.length > 0) {
|
||||
return fromPatterns;
|
||||
}
|
||||
return normalizeStringArray(hookConfig.files);
|
||||
return normalizeTrimmedStringList(hookConfig.files);
|
||||
}
|
||||
|
||||
const bootstrapExtraFilesHook: HookHandler = async (event) => {
|
||||
|
||||
Reference in New Issue
Block a user