mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 17:10:20 +00:00
refactor: reuse runtime requires evaluation
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import type { OpenClawConfig, HookConfig } from "../config/config.js";
|
||||
import type { HookEligibilityContext, HookEntry } from "./types.js";
|
||||
import {
|
||||
evaluateRuntimeRequires,
|
||||
hasBinary,
|
||||
isConfigPathTruthyWithDefaults,
|
||||
resolveConfigPath,
|
||||
resolveRuntimePlatform,
|
||||
} from "../shared/config-eval.js";
|
||||
import { resolveHookKey } from "./frontmatter.js";
|
||||
import type { HookEligibilityContext, HookEntry } from "./types.js";
|
||||
|
||||
const DEFAULT_CONFIG_VALUES: Record<string, boolean> = {
|
||||
"browser.enabled": true,
|
||||
@@ -66,54 +67,12 @@ export function shouldIncludeHook(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check required binaries (all must be present)
|
||||
const requiredBins = entry.metadata?.requires?.bins ?? [];
|
||||
if (requiredBins.length > 0) {
|
||||
for (const bin of requiredBins) {
|
||||
if (hasBinary(bin)) {
|
||||
continue;
|
||||
}
|
||||
if (eligibility?.remote?.hasBin?.(bin)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check anyBins (at least one must be present)
|
||||
const requiredAnyBins = entry.metadata?.requires?.anyBins ?? [];
|
||||
if (requiredAnyBins.length > 0) {
|
||||
const anyFound =
|
||||
requiredAnyBins.some((bin) => hasBinary(bin)) ||
|
||||
eligibility?.remote?.hasAnyBin?.(requiredAnyBins);
|
||||
if (!anyFound) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check required environment variables
|
||||
const requiredEnv = entry.metadata?.requires?.env ?? [];
|
||||
if (requiredEnv.length > 0) {
|
||||
for (const envName of requiredEnv) {
|
||||
if (process.env[envName]) {
|
||||
continue;
|
||||
}
|
||||
if (hookConfig?.env?.[envName]) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check required config paths
|
||||
const requiredConfig = entry.metadata?.requires?.config ?? [];
|
||||
if (requiredConfig.length > 0) {
|
||||
for (const configPath of requiredConfig) {
|
||||
if (!isConfigPathTruthy(config, configPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return evaluateRuntimeRequires({
|
||||
requires: entry.metadata?.requires,
|
||||
hasBin: hasBinary,
|
||||
hasRemoteBin: eligibility?.remote?.hasBin,
|
||||
hasAnyRemoteBin: eligibility?.remote?.hasAnyBin,
|
||||
hasEnv: (envName) => Boolean(process.env[envName] || hookConfig?.env?.[envName]),
|
||||
isConfigPathTruthy: (configPath) => isConfigPathTruthy(config, configPath),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user