@@ -5,11 +5,6 @@ import {
55 normalizeOptionalString ,
66} from "@openclaw/normalization-core/string-coerce" ;
77import { normalizeStringEntries } from "@openclaw/normalization-core/string-normalization" ;
8- import {
9- expandToolGroups ,
10- normalizeToolPolicyName ,
11- resolveToolProfilePolicy ,
12- } from "../../../../src/agents/tool-policy-shared.js" ;
138import type {
149 AgentIdentityResult ,
1510 AgentsFilesListResult ,
@@ -201,11 +196,6 @@ export function resolveToolProfileOptions(
201196 } ) ) ;
202197}
203198
204- type ToolPolicy = {
205- allow ?: string [ ] ;
206- deny ?: string [ ] ;
207- } ;
208-
209199type GitHubIdentityConfigValue = {
210200 profileId ?: string ;
211201 gitAuthor ?: { name ?: string ; email ?: string } ;
@@ -592,90 +582,3 @@ export function buildModelOptions(
592582
593583 return options ;
594584}
595-
596- type CompiledPattern =
597- | { kind : "all" }
598- | { kind : "exact" ; value : string }
599- | { kind : "regex" ; value : RegExp } ;
600-
601- function compilePattern ( pattern : string ) : CompiledPattern {
602- const normalized = normalizeToolPolicyName ( pattern ) ;
603- if ( ! normalized ) {
604- return { kind : "exact" , value : "" } ;
605- }
606- if ( normalized === "*" ) {
607- return { kind : "all" } ;
608- }
609- if ( ! normalized . includes ( "*" ) ) {
610- return { kind : "exact" , value : normalized } ;
611- }
612- const escaped = normalized . replace ( / [ . * + ? ^ $ { } ( ) | [ \\ ] \\ ] / g, "\\$&" ) ;
613- return { kind : "regex" , value : new RegExp ( `^${ escaped . replaceAll ( "\\*" , ".*" ) } $` ) } ;
614- }
615-
616- function compilePatterns ( patterns ?: string [ ] ) : CompiledPattern [ ] {
617- if ( ! Array . isArray ( patterns ) ) {
618- return [ ] ;
619- }
620- return expandToolGroups ( patterns )
621- . map ( compilePattern )
622- . filter ( ( pattern ) => {
623- return pattern . kind !== "exact" || pattern . value . length > 0 ;
624- } ) ;
625- }
626-
627- function matchesAny ( name : string , patterns : CompiledPattern [ ] ) {
628- for ( const pattern of patterns ) {
629- if ( pattern . kind === "all" ) {
630- return true ;
631- }
632- if ( pattern . kind === "exact" && name === pattern . value ) {
633- return true ;
634- }
635- if ( pattern . kind === "regex" && pattern . value . test ( name ) ) {
636- return true ;
637- }
638- }
639- return false ;
640- }
641-
642- export function isAllowedByPolicy ( name : string , policy ?: ToolPolicy ) {
643- if ( ! policy ) {
644- return true ;
645- }
646- const normalized = normalizeToolPolicyName ( name ) ;
647- const deny = compilePatterns ( policy . deny ) ;
648- if ( matchesAny ( normalized , deny ) ) {
649- return false ;
650- }
651- const allow = compilePatterns ( policy . allow ) ;
652- if ( allow . length === 0 ) {
653- return true ;
654- }
655- if ( matchesAny ( normalized , allow ) ) {
656- return true ;
657- }
658- if ( normalized === "apply_patch" && matchesAny ( "exec" , allow ) ) {
659- return true ;
660- }
661- return false ;
662- }
663-
664- export function matchesList ( name : string , list ?: string [ ] ) {
665- if ( ! Array . isArray ( list ) || list . length === 0 ) {
666- return false ;
667- }
668- const normalized = normalizeToolPolicyName ( name ) ;
669- const patterns = compilePatterns ( list ) ;
670- if ( matchesAny ( normalized , patterns ) ) {
671- return true ;
672- }
673- if ( normalized === "apply_patch" && matchesAny ( "exec" , patterns ) ) {
674- return true ;
675- }
676- return false ;
677- }
678-
679- export function resolveToolProfile ( profile : string ) {
680- return resolveToolProfilePolicy ( profile ) ?? undefined ;
681- }
0 commit comments