UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

34 lines • 1.68 kB
import { fromConfig } from "./config.js"; import { Wildcard } from "./wildcard.js"; /** Last matching deny in global, project, CLI order, as used by the tool refusal. */ export function findDenyProvenance(settingsManager, cliRuleset, permission, patterns, matchesIdentity) { const matches = (rules) => rules.filter((rule) => rule.action === "deny" && Wildcard.match(permission, rule.permission) && (patterns.some((value) => Wildcard.match(value, rule.pattern) || (rule.pattern.endsWith(" *") && Wildcard.match(value, rule.pattern.slice(0, -2)))) || (matchesIdentity?.(rule.pattern) ?? false))); const globalPermission = settingsManager.getGlobalSettings().permission; const globalMatches = matches(globalPermission ? fromConfig(globalPermission) : []); const projectPermission = settingsManager.getProjectSettings().permission; const projectMatches = matches(projectPermission ? fromConfig(projectPermission) : []); const cliMatches = matches(cliRuleset); if (cliMatches.length > 0) { return { layer: "cli", ...cliMatches[cliMatches.length - 1], otherLayerDenies: projectMatches.length > 0 || globalMatches.length > 0, }; } if (projectMatches.length > 0) { return { layer: "project", ...projectMatches[projectMatches.length - 1], otherLayerDenies: globalMatches.length > 0, }; } if (globalMatches.length > 0) { return { layer: "global", ...globalMatches[globalMatches.length - 1], otherLayerDenies: false }; } return undefined; } //# sourceMappingURL=deny-provenance.js.map