@@ -6,6 +6,7 @@ import { vscode } from "@/utils/vscode"
66import { cn } from "@/lib/utils"
77import { useExtensionState } from "@/context/ExtensionStateContext"
88import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue , StandardTooltip } from "@/components/ui"
9+ import { VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
910
1011import { SectionHeader } from "./SectionHeader"
1112import { Section } from "./Section"
@@ -29,10 +30,13 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
2930 type : "success" | "error" | null
3031 message : string
3132 } > ( { type : null , message : "" } )
32- const [ addToGitignore , setAddToGitignore ] = useState ( false )
33+ const [ addToGitignore , setAddToGitignore ] = useState ( true )
3334 const [ _existingFiles , setExistingFiles ] = useState < string [ ] > ( [ ] )
34- const [ alwaysAllowWriteProtected , setAlwaysAllowWriteProtected ] = useState ( false )
35+ const [ alwaysAllowWriteProtected , setAlwaysAllowWriteProtected ] = useState ( true )
3536 const [ selectedApiConfig , setSelectedApiConfig ] = useState < string > ( "" )
37+ const [ includeCustomRules , setIncludeCustomRules ] = useState ( false )
38+ const [ customRulesText , setCustomRulesText ] = useState ( "" )
39+ const [ sourceFileCount , setSourceFileCount ] = useState < number | null > ( null )
3640
3741 const { listApiConfigMeta, currentApiConfigName } = useExtensionState ( )
3842
@@ -118,6 +122,10 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
118122 exists : message . files ?. includes ( rule . id ) || false ,
119123 } ) ) ,
120124 )
125+ // Set source file count if provided
126+ if ( message . sourceFileCount !== undefined ) {
127+ setSourceFileCount ( message . sourceFileCount )
128+ }
121129 } else if ( message . type === "state" ) {
122130 // Update alwaysAllowWriteProtected from the extension state
123131 if ( message . state ?. alwaysAllowWriteProtected !== undefined ) {
@@ -150,6 +158,8 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
150158 addToGitignore,
151159 alwaysAllowWriteProtected,
152160 apiConfigName : selectedApiConfig ,
161+ includeCustomRules,
162+ customRulesText : includeCustomRules ? customRulesText : "" ,
153163 } )
154164 }
155165
@@ -221,6 +231,15 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
221231 </ div >
222232 </ div >
223233
234+ { /* Small repository warning */ }
235+ { sourceFileCount !== null && sourceFileCount > 0 && sourceFileCount < 20 && (
236+ < div className = "flex items-start gap-2 p-3 bg-vscode-inputValidation-warningBackground border border-vscode-inputValidation-warningBorder rounded-md" >
237+ < AlertTriangle className = "w-4 h-4 text-vscode-inputValidation-warningForeground mt-0.5 flex-shrink-0" />
238+ < div className = "text-sm text-vscode-inputValidation-warningForeground" >
239+ { t ( "settings:rules.smallRepoWarning" , { count : sourceFileCount } ) }
240+ </ div >
241+ </ div >
242+ ) }
224243 { hasExistingFiles && (
225244 < div className = "flex items-start gap-2 p-3 bg-vscode-inputValidation-warningBackground border border-vscode-inputValidation-warningBorder rounded-md" >
226245 < AlertTriangle className = "w-4 h-4 text-vscode-inputValidation-warningForeground mt-0.5 flex-shrink-0" />
@@ -235,7 +254,7 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
235254 </ div >
236255 ) }
237256
238- < div className = "border-t border-vscode-panel-border pt-4 " >
257+ < div className = "border-t border-vscode-panel-border pt-2 " >
239258 < label className = "flex items-center gap-2 cursor-pointer hover:opacity-80" >
240259 < input
241260 type = "checkbox"
@@ -251,7 +270,7 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
251270 </ label >
252271 </ div >
253272
254- < div className = "border-t border-vscode-panel-border pt-4 " >
273+ < div className = "border-t border-vscode-panel-border pt-2 " >
255274 < label className = "flex items-center gap-2 cursor-pointer hover:opacity-80" >
256275 < input
257276 type = "checkbox"
@@ -275,6 +294,45 @@ export const RulesSettings = ({ className, hasUnsavedChanges, ...props }: RulesS
275294 </ label >
276295 </ div >
277296
297+ < div className = "border-t border-vscode-panel-border pt-4" >
298+ < label className = "flex items-center gap-2 cursor-pointer hover:opacity-80" >
299+ < input
300+ type = "checkbox"
301+ checked = { includeCustomRules }
302+ onChange = { ( e ) => setIncludeCustomRules ( e . target . checked ) }
303+ />
304+ < div >
305+ < div className = "text-sm font-medium" >
306+ { t ( "settings:rules.includeCustomRules" ) }
307+ </ div >
308+ < div className = "text-xs text-vscode-descriptionForeground" >
309+ { t ( "settings:rules.includeCustomRulesDescription" ) }
310+ </ div >
311+ </ div >
312+ </ label >
313+
314+ { includeCustomRules && (
315+ < div className = "mt-3 pl-6" >
316+ < VSCodeTextArea
317+ resize = "vertical"
318+ value = { customRulesText }
319+ onChange = { ( e ) => {
320+ const value =
321+ ( e as unknown as CustomEvent ) ?. detail ?. target ?. value ||
322+ ( ( e as any ) . target as HTMLTextAreaElement ) . value
323+ setCustomRulesText ( value )
324+ } }
325+ placeholder = { t ( "settings:rules.customRulesPlaceholder" ) }
326+ rows = { 6 }
327+ className = "w-full"
328+ />
329+ < div className = "text-xs text-vscode-descriptionForeground mt-1" >
330+ { t ( "settings:rules.customRulesHint" ) }
331+ </ div >
332+ </ div >
333+ ) }
334+ </ div >
335+
278336 < div className = "flex flex-col gap-3" >
279337 < Select value = { selectedApiConfig } onValueChange = { setSelectedApiConfig } >
280338 < SelectTrigger className = "w-fit min-w-[5rem] max-w-[8rem]" >
0 commit comments