@@ -48,7 +48,7 @@ function extractLineRange(input: string) {
4848export type AutocompleteRef = {
4949 onInput : ( value : string ) => void
5050 onKeyDown : ( e : KeyEvent ) => void
51- visible : false | "@" | "/"
51+ visible : false | "@" | "/" | "$"
5252}
5353
5454export type AutocompleteOption = {
@@ -72,6 +72,7 @@ export function Autocomplete(props: {
7272 ref : ( ref : AutocompleteRef ) => void
7373 fileStyleId : number
7474 agentStyleId : number
75+ skillStyleId : number
7576 promptPartTypeId : ( ) => number
7677} ) {
7778 const sdk = useSDK ( )
@@ -143,7 +144,8 @@ export function Autocomplete(props: {
143144
144145 const charAfterCursor = props . value . at ( currentCursorOffset )
145146 const needsSpace = charAfterCursor !== " "
146- const append = "@" + text + ( needsSpace ? " " : "" )
147+ const prefix = part . type === "skill" ? "$" : "@"
148+ const append = prefix + text + ( needsSpace ? " " : "" )
147149
148150 input . cursorOffset = store . index
149151 const startCursor = input . logicalCursor
@@ -153,11 +155,18 @@ export function Autocomplete(props: {
153155 input . deleteRange ( startCursor . row , startCursor . col , endCursor . row , endCursor . col )
154156 input . insertText ( append )
155157
156- const virtualText = "@" + text
158+ const virtualText = prefix + text
157159 const extmarkStart = store . index
158160 const extmarkEnd = extmarkStart + Bun . stringWidth ( virtualText )
159161
160- const styleId = part . type === "file" ? props . fileStyleId : part . type === "agent" ? props . agentStyleId : undefined
162+ const styleId =
163+ part . type === "file"
164+ ? props . fileStyleId
165+ : part . type === "agent"
166+ ? props . agentStyleId
167+ : part . type === "skill"
168+ ? props . skillStyleId
169+ : undefined
161170
162171 const extmarkId = input . extmarks . create ( {
163172 start : extmarkStart ,
@@ -196,6 +205,10 @@ export function Autocomplete(props: {
196205 part . source . start = extmarkStart
197206 part . source . end = extmarkEnd
198207 part . source . value = virtualText
208+ } else if ( part . type === "skill" && part . source ) {
209+ part . source . start = extmarkStart
210+ part . source . end = extmarkEnd
211+ part . source . value = virtualText
199212 }
200213 const partIndex = draft . parts . length
201214 draft . parts . push ( part )
@@ -341,6 +354,36 @@ export function Autocomplete(props: {
341354 )
342355 } )
343356
357+ const skills = createMemo ( ( ) : AutocompleteOption [ ] => {
358+ const results = sync . data . skill . map (
359+ ( skill ) : AutocompleteOption => ( {
360+ display : skill . name ,
361+ description : skill . description ,
362+ onSelect : ( ) => {
363+ insertPart ( skill . name , {
364+ type : "skill" ,
365+ name : skill . name ,
366+ source : {
367+ start : 0 ,
368+ end : 0 ,
369+ value : "$" + skill . name ,
370+ } ,
371+ } )
372+ } ,
373+ } ) ,
374+ )
375+
376+ results . sort ( ( a , b ) => a . display . localeCompare ( b . display ) )
377+
378+ const max = firstBy ( results , [ ( x ) => x . display . length , "desc" ] ) ?. display . length
379+ if ( ! max ) return results
380+ const maxDisplay = Math . min ( max ! , 20 )
381+ return results . map ( ( item ) => ( {
382+ ...item ,
383+ display : item . display . length > 20 ? item . display . slice ( 0 , 17 ) + "... " : item . display . padEnd ( maxDisplay + 1 ) ,
384+ } ) )
385+ } )
386+
344387 const commands = createMemo ( ( ) : AutocompleteOption [ ] => {
345388 const results : AutocompleteOption [ ] = [ ...command . slashes ( ) ]
346389
@@ -372,9 +415,14 @@ export function Autocomplete(props: {
372415 const filesValue = files ( )
373416 const agentsValue = agents ( )
374417 const commandsValue = commands ( )
418+ const skillsValue = skills ( )
375419
376420 const mixed : AutocompleteOption [ ] =
377- store . visible === "@" ? [ ...agentsValue , ...( filesValue || [ ] ) , ...mcpResources ( ) ] : [ ...commandsValue ]
421+ store . visible === "@"
422+ ? [ ...agentsValue , ...( filesValue || [ ] ) , ...mcpResources ( ) ]
423+ : store . visible === "$"
424+ ? [ ...skillsValue ]
425+ : [ ...commandsValue ]
378426
379427 const currentFilter = filter ( )
380428
@@ -461,7 +509,7 @@ export function Autocomplete(props: {
461509 setStore ( "selected" , 0 )
462510 }
463511
464- function show ( mode : "@" | "/" ) {
512+ function show ( mode : "@" | "/" | "$" ) {
465513 command . keybinds ( false )
466514 setStore ( {
467515 visible : mode ,
@@ -517,13 +565,25 @@ export function Autocomplete(props: {
517565 // Check for "@" trigger - find the nearest "@" before cursor with no whitespace between
518566 const text = value . slice ( 0 , offset )
519567 const idx = text . lastIndexOf ( "@" )
520- if ( idx === - 1 ) return
568+ if ( idx !== - 1 ) {
569+ const between = text . slice ( idx )
570+ const before = idx === 0 ? undefined : value [ idx - 1 ]
571+ if ( ( before === undefined || / \s / . test ( before ) ) && ! between . match ( / \s / ) ) {
572+ show ( "@" )
573+ setStore ( "index" , idx )
574+ return
575+ }
576+ }
521577
522- const between = text . slice ( idx )
523- const before = idx === 0 ? undefined : value [ idx - 1 ]
524- if ( ( before === undefined || / \s / . test ( before ) ) && ! between . match ( / \s / ) ) {
525- show ( "@" )
526- setStore ( "index" , idx )
578+ // Check for "$" trigger - find the nearest "$" before cursor with no whitespace between
579+ const dollarIdx = text . lastIndexOf ( "$" )
580+ if ( dollarIdx !== - 1 ) {
581+ const between = text . slice ( dollarIdx )
582+ const before = dollarIdx === 0 ? undefined : value [ dollarIdx - 1 ]
583+ if ( ( before === undefined || / \s / . test ( before ) ) && ! between . match ( / \s / ) ) {
584+ show ( "$" )
585+ setStore ( "index" , dollarIdx )
586+ }
527587 }
528588 } ,
529589 onKeyDown ( e : KeyEvent ) {
@@ -578,6 +638,14 @@ export function Autocomplete(props: {
578638 if ( e . name === "/" ) {
579639 if ( props . input ( ) . cursorOffset === 0 ) show ( "/" )
580640 }
641+
642+ if ( e . name === "$" ) {
643+ const cursorOffset = props . input ( ) . cursorOffset
644+ const charBeforeCursor =
645+ cursorOffset === 0 ? undefined : props . input ( ) . getTextRange ( cursorOffset - 1 , cursorOffset )
646+ const canTrigger = charBeforeCursor === undefined || charBeforeCursor === "" || / \s / . test ( charBeforeCursor )
647+ if ( canTrigger ) show ( "$" )
648+ }
581649 }
582650 } ,
583651 } )
0 commit comments