File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,23 +115,28 @@ async function generateRule(description) {
115115 if ( ! data ) {
116116 throw new Error ( 'Empty response from API' ) ;
117117 }
118-
119- // Check if the rule is supported
120- if ( ! data . supported ) {
121- const reason = data . feedback || 'This type of rule is not supported by Watchflow' ;
122- throw new Error ( reason ) ;
123- }
124-
125- // Extract the YAML snippet from the response
118+
119+ // Extract the YAML snippet from the response first so we can whitelist diff rules
120+ let yaml = null ;
126121 if ( data . snippet ) {
127- // Remove the markdown code block wrapper if present
128- let yaml = data . snippet ;
122+ yaml = data . snippet ;
129123 if ( yaml . startsWith ( '```yaml\n' ) ) {
130124 yaml = yaml . replace ( / ^ ` ` ` y a m l \n / , '' ) . replace ( / \n ` ` ` $ / , '' ) ;
131125 }
126+ }
127+
128+ // Allow diff-aware rules (file_patterns/require_patterns/forbidden_patterns) even if the API flags them unsupported
129+ const isDiffRule = yaml ? / f i l e _ p a t t e r n s | r e q u i r e _ p a t t e r n s | f o r b i d d e n _ p a t t e r n s / . test ( yaml ) : false ;
130+
131+ if ( ! data . supported && ! isDiffRule ) {
132+ const reason = data . feedback || 'This type of rule is not supported by Watchflow' ;
133+ throw new Error ( reason ) ;
134+ }
135+
136+ if ( yaml ) {
132137 return yaml ;
133138 }
134-
139+
135140 throw new Error ( 'No rule snippet found in API response' ) ;
136141}
137142
You can’t perform that action at this time.
0 commit comments