refactor(agents): dedupe config and truncation guards

This commit is contained in:
Peter Steinberger
2026-02-22 17:54:42 +00:00
parent 409a02691f
commit 3286791316
12 changed files with 325 additions and 318 deletions

View File

@@ -48,14 +48,16 @@ export type RuntimeRequires = {
config?: string[];
};
export function evaluateRuntimeRequires(params: {
type RuntimeRequirementEvalParams = {
requires?: RuntimeRequires;
hasBin: (bin: string) => boolean;
hasAnyRemoteBin?: (bins: string[]) => boolean;
hasRemoteBin?: (bin: string) => boolean;
hasEnv: (envName: string) => boolean;
isConfigPathTruthy: (pathStr: string) => boolean;
}): boolean {
};
export function evaluateRuntimeRequires(params: RuntimeRequirementEvalParams): boolean {
const requires = params.requires;
if (!requires) {
return true;
@@ -103,6 +105,35 @@ export function evaluateRuntimeRequires(params: {
return true;
}
export function evaluateRuntimeEligibility(
params: {
os?: string[];
remotePlatforms?: string[];
always?: boolean;
} & RuntimeRequirementEvalParams,
): boolean {
const osList = params.os ?? [];
const remotePlatforms = params.remotePlatforms ?? [];
if (
osList.length > 0 &&
!osList.includes(resolveRuntimePlatform()) &&
!remotePlatforms.some((platform) => osList.includes(platform))
) {
return false;
}
if (params.always === true) {
return true;
}
return evaluateRuntimeRequires({
requires: params.requires,
hasBin: params.hasBin,
hasRemoteBin: params.hasRemoteBin,
hasAnyRemoteBin: params.hasAnyRemoteBin,
hasEnv: params.hasEnv,
isConfigPathTruthy: params.isConfigPathTruthy,
});
}
export function resolveRuntimePlatform(): string {
return process.platform;
}