Skip to content

Commit 17c68d1

Browse files
authored
Merge pull request #1 from naaa760/fix/diff-rule-whitelist
fix: allow diff-aware rules on landing UI
2 parents f47dfd1 + 07e8ae9 commit 17c68d1

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

script.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff 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(/^```yaml\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 ? /file_patterns|require_patterns|forbidden_patterns/.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

0 commit comments

Comments
 (0)