44 BookmarkIcon as BookmarkOutline ,
55 EyeIcon ,
66 PencilIcon ,
7- PlusIcon ,
87} from "@heroicons/react/24/outline" ;
98import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid" ;
109import {
@@ -19,11 +18,12 @@ import {
1918 DEFAULT_PLAN_SYSTEM_MESSAGE ,
2019 DEFAULT_SYSTEM_MESSAGES_URL ,
2120} from "core/llm/defaultSystemMessages" ;
22- import { useContext , useMemo } from "react" ;
21+ import { useContext , useMemo , useState } from "react" ;
22+ import { DropdownButton } from "../../../components/DropdownButton" ;
2323import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip" ;
2424import Switch from "../../../components/gui/Switch" ;
2525import { useMainEditor } from "../../../components/mainInput/TipTapEditor" ;
26- import { Button , Card , EmptyState , useFontSize } from "../../../components/ui" ;
26+ import { Card , EmptyState } from "../../../components/ui" ;
2727import { useAuth } from "../../../context/Auth" ;
2828import { IdeMessengerContext } from "../../../context/IdeMessenger" ;
2929import { useBookmarkedSlashCommands } from "../../../hooks/useBookmarkedSlashCommands" ;
@@ -202,8 +202,8 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
202202 ) ;
203203 }
204204
205- const smallFont = useFontSize ( - 2 ) ;
206- const tinyFont = useFontSize ( - 3 ) ;
205+ const smallFont = fontSize ( - 2 ) ;
206+ const tinyFont = fontSize ( - 3 ) ;
207207 return (
208208 < div
209209 className = { `border-border flex flex-col rounded-sm px-2 py-1.5 transition-colors ${ isDisabled ? "opacity-50" : "" } ` }
@@ -427,18 +427,30 @@ function addDefaultSystemMessage(
427427 }
428428}
429429
430+ // Define dropdown options for global rules
431+ const globalRulesOptions = [
432+ { value : "workspace" , label : "Current workspace" } ,
433+ { value : "global" , label : "Global" } ,
434+ ] ;
435+
430436function RulesSubSection ( ) {
431437 const { selectedProfile } = useAuth ( ) ;
432438 const config = useAppSelector ( ( store ) => store . config . config ) ;
433439 const mode = useAppSelector ( ( store ) => store . session . mode ) ;
434440 const ideMessenger = useContext ( IdeMessengerContext ) ;
435441 const isLocal = selectedProfile ?. profileType === "local" ;
442+ const [ globalRulesMode , setGlobalRulesMode ] = useState < string > ( "workspace" ) ;
436443
437- const handleAddRule = ( ) => {
444+ const handleAddRule = ( mode ?: string ) => {
445+ const currentMode = mode || globalRulesMode ;
438446 if ( isLocal ) {
439- void ideMessenger . request ( "config/addLocalWorkspaceBlock" , {
440- blockType : "rules" ,
441- } ) ;
447+ if ( currentMode === "global" ) {
448+ void ideMessenger . request ( "config/addGlobalRule" , undefined ) ;
449+ } else {
450+ void ideMessenger . request ( "config/addLocalWorkspaceBlock" , {
451+ blockType : "rules" ,
452+ } ) ;
453+ }
442454 } else {
443455 void ideMessenger . request ( "controlPlane/openUrl" , {
444456 path : "?type=rules" ,
@@ -447,6 +459,11 @@ function RulesSubSection() {
447459 }
448460 } ;
449461
462+ const handleOptionClick = ( value : string ) => {
463+ setGlobalRulesMode ( value ) ;
464+ handleAddRule ( value ) ;
465+ } ;
466+
450467 const sortedRules : RuleWithSource [ ] = useMemo ( ( ) => {
451468 const rules = [ ...config . rules . map ( ( rule ) => ( { ...rule } ) ) ] ;
452469
@@ -489,12 +506,22 @@ function RulesSubSection() {
489506
490507 return (
491508 < div >
492- < ConfigHeader
493- title = "Rules"
494- variant = "sm"
495- onAddClick = { handleAddRule }
496- addButtonTooltip = "Add rule"
497- />
509+ { isLocal ? (
510+ < DropdownButton
511+ title = "Rules"
512+ variant = "sm"
513+ options = { globalRulesOptions }
514+ onOptionClick = { handleOptionClick }
515+ addButtonTooltip = "Add rules"
516+ />
517+ ) : (
518+ < ConfigHeader
519+ title = "Rules"
520+ variant = "sm"
521+ onAddClick = { ( ) => handleAddRule ( ) }
522+ addButtonTooltip = "Add rules"
523+ />
524+ ) }
498525
499526 < Card >
500527 { sortedRules . length > 0 ? (
0 commit comments