@@ -387,18 +387,39 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
387387 }
388388}
389389
390- function insertRuleInContext ( ruleName ) {
391- // For rules, we just insert the text directly into the editor
392- // This matches the workspace sidebar behavior for rules
393- setTimeout ( ( ) => {
394- if ( window . insertTextAtCursor ) {
395- window . insertTextAtCursor ( ruleName ) ;
396- } else if ( window . workspaceMonacoEditor ) {
397- // Fallback: set editor value directly
398- window . workspaceMonacoEditor . setValue ( ruleName ) ;
399- window . workspaceMonacoEditor . focus ( ) ;
390+ async function insertRuleInContext ( ruleName ) {
391+ try {
392+ const response = await fetch ( `/api/actions/rule-content/${ encodeURIComponent ( ruleName ) } ` ) ;
393+
394+ if ( response . ok ) {
395+ const result = await response . json ( ) ;
396+
397+ // Get current CLAUDE.md content from workspace
398+ let currentContent = '' ;
399+ if ( window . workspaceManager && window . workspaceManager . getState ( ) ) {
400+ const claudeFile = window . workspaceManager . getState ( ) . files [ 'CLAUDE.md' ] ;
401+ if ( claudeFile ) {
402+ currentContent = claudeFile ;
403+ }
404+ }
405+
406+ // Add rule content to CLAUDE.md (no toggle behavior for quick start)
407+ const ruleContent = result . content . trim ( ) ;
408+ const newContent = currentContent + ( currentContent ? '\n' : '' ) + ruleContent ;
409+
410+ // Add to virtual workspace
411+ if ( window . workspaceManager && window . workspaceManager . currentState ) {
412+ window . workspaceManager . currentState . addFile ( 'CLAUDE.md' , newContent ) ;
413+ window . workspaceManager . saveState ( window . workspaceManager . currentContextId ) ;
414+ window . workspaceManager . render ( ) ;
415+ }
416+ } else {
417+ const error = await response . json ( ) ;
418+ console . error ( `Error: ${ error . detail } ` ) ;
400419 }
401- } , 100 ) ;
420+ } catch ( error ) {
421+ console . error ( `Error installing rule: ${ error . message } ` ) ;
422+ }
402423}
403424
404425// Show workspace with fade transition
0 commit comments