oclaw/openclaw/scripts/lib/extension-source-classifier.mjs
oliver dbbe3add6a 重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
2026-04-26 08:34:33 +08:00

44 lines
2 KiB
JavaScript

const CODE_FILE_RE = /\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const DECLARATION_FILE_RE = /\.d\.ts$/u;
const RUNTIME_API_BARREL_RE = /(^|\/)runtime-api\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const PUBLIC_API_BARREL_RE = /(^|\/)api\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_LIKE_SEGMENT_RE =
/(^|\/)(?:__tests__|fixtures|test|tests|test-fixtures|test-support|test-utils)(?:\/|$)/u;
const TEST_LIKE_FILENAME_RE =
/(^|\/)[^/]*test-(?:support|helpers|fixtures|harness)\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_SHARED_FILENAME_RE = /(^|\/)[^/]*\.test-[^/]*\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_CANARY_FILENAME_RE = /(^|\/)__rootdir_boundary_canary__\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const SNAPSHOT_FILE_RE = /\.snap$/u;
const SUFFIX_SKIP_RE = /\.(?:test|spec|fixture)\./u;
const INFRA_DIR_RE = /(^|\/)(?:coverage|dist|node_modules)(?:\/|$)/u;
const INFRA_NAME_RE = /(test-harness|test-support|test-helpers|test-fixtures)/u;
export function normalizeExtensionSourcePath(filePath) {
return filePath.replaceAll("\\", "/");
}
export function classifyBundledExtensionSourcePath(filePath) {
const normalizedPath = normalizeExtensionSourcePath(filePath);
const isCodeFile = CODE_FILE_RE.test(normalizedPath) && !DECLARATION_FILE_RE.test(normalizedPath);
const isRuntimeApiBarrel = RUNTIME_API_BARREL_RE.test(normalizedPath);
const isPublicApiBarrel = PUBLIC_API_BARREL_RE.test(normalizedPath);
const isTestLike =
TEST_LIKE_SEGMENT_RE.test(normalizedPath) ||
TEST_LIKE_FILENAME_RE.test(normalizedPath) ||
TEST_SHARED_FILENAME_RE.test(normalizedPath) ||
TEST_CANARY_FILENAME_RE.test(normalizedPath) ||
SUFFIX_SKIP_RE.test(normalizedPath) ||
SNAPSHOT_FILE_RE.test(normalizedPath) ||
INFRA_NAME_RE.test(normalizedPath);
const isInfraArtifact = INFRA_DIR_RE.test(normalizedPath);
return {
normalizedPath,
isCodeFile,
isRuntimeApiBarrel,
isPublicApiBarrel,
isTestLike,
isInfraArtifact,
isProductionSource: isCodeFile && !isRuntimeApiBarrel && !isTestLike && !isInfraArtifact,
};
}