@@ -11,6 +11,12 @@ export interface AvailableTool {
1111 category : "lsp" | "ast" | "search" | "session" | "command" | "other"
1212}
1313
14+ export interface AvailableSkill {
15+ name : string
16+ description : string
17+ location : "user" | "project" | "plugin"
18+ }
19+
1420export function categorizeTools ( toolNames : string [ ] ) : AvailableTool [ ] {
1521 return toolNames . map ( ( name ) => {
1622 let category : AvailableTool [ "category" ] = "other"
@@ -51,27 +57,73 @@ function formatToolsForPrompt(tools: AvailableTool[]): string {
5157 return parts . join ( ", " )
5258}
5359
54- export function buildKeyTriggersSection ( agents : AvailableAgent [ ] ) : string {
60+ export function buildKeyTriggersSection ( agents : AvailableAgent [ ] , skills : AvailableSkill [ ] = [ ] ) : string {
5561 const keyTriggers = agents
5662 . filter ( ( a ) => a . metadata . keyTrigger )
5763 . map ( ( a ) => `- ${ a . metadata . keyTrigger } ` )
5864
59- if ( keyTriggers . length === 0 ) return ""
65+ const skillTriggers = skills
66+ . filter ( ( s ) => s . description )
67+ . map ( ( s ) => `- **Skill \`${ s . name } \`**: ${ extractTriggerFromDescription ( s . description ) } ` )
68+
69+ const allTriggers = [ ...keyTriggers , ...skillTriggers ]
70+
71+ if ( allTriggers . length === 0 ) return ""
6072
6173 return `### Key Triggers (check BEFORE classification):
62- ${ keyTriggers . join ( "\n" ) }
74+
75+ **BLOCKING: Check skills FIRST before any action.**
76+ If a skill matches, invoke it IMMEDIATELY via \`skill\` tool.
77+
78+ ${ allTriggers . join ( "\n" ) }
6379- **GitHub mention (@mention in issue/PR)** → This is a WORK REQUEST. Plan full cycle: investigate → implement → create PR
6480- **"Look into" + "create PR"** → Not just research. Full implementation cycle expected.`
6581}
6682
67- export function buildToolSelectionTable ( agents : AvailableAgent [ ] , tools : AvailableTool [ ] = [ ] ) : string {
83+ function extractTriggerFromDescription ( description : string ) : string {
84+ const triggerMatch = description . match ( / T r i g g e r [ s ] ? [: \s] + ( [ ^ . ] + ) / i)
85+ if ( triggerMatch ) return triggerMatch [ 1 ] . trim ( )
86+
87+ const activateMatch = description . match ( / A c t i v a t e w h e n [: \s] + ( [ ^ . ] + ) / i)
88+ if ( activateMatch ) return activateMatch [ 1 ] . trim ( )
89+
90+ const useWhenMatch = description . match ( / U s e (?: t h i s ) ? w h e n [: \s] + ( [ ^ . ] + ) / i)
91+ if ( useWhenMatch ) return useWhenMatch [ 1 ] . trim ( )
92+
93+ return description . split ( "." ) [ 0 ] || description
94+ }
95+
96+ export function buildToolSelectionTable (
97+ agents : AvailableAgent [ ] ,
98+ tools : AvailableTool [ ] = [ ] ,
99+ skills : AvailableSkill [ ] = [ ]
100+ ) : string {
68101 const rows : string [ ] = [
69- "### Tool Selection:" ,
102+ "### Tool & Skill Selection:" ,
103+ "" ,
104+ "**Priority Order**: Skills → Direct Tools → Agents" ,
70105 "" ,
71- "| Tool | Cost | When to Use |" ,
72- "|------|------|-------------|" ,
73106 ]
74107
108+ // Skills section (highest priority)
109+ if ( skills . length > 0 ) {
110+ rows . push ( "#### Skills (INVOKE FIRST if matching)" )
111+ rows . push ( "" )
112+ rows . push ( "| Skill | When to Use |" )
113+ rows . push ( "|-------|-------------|" )
114+ for ( const skill of skills ) {
115+ const shortDesc = extractTriggerFromDescription ( skill . description )
116+ rows . push ( `| \`${ skill . name } \` | ${ shortDesc } |` )
117+ }
118+ rows . push ( "" )
119+ }
120+
121+ // Tools and Agents table
122+ rows . push ( "#### Tools & Agents" )
123+ rows . push ( "" )
124+ rows . push ( "| Resource | Cost | When to Use |" )
125+ rows . push ( "|----------|------|-------------|" )
126+
75127 if ( tools . length > 0 ) {
76128 const toolsDisplay = formatToolsForPrompt ( tools )
77129 rows . push ( `| ${ toolsDisplay } | FREE | Not Complex, Scope Clear, No Implicit Assumptions |` )
@@ -88,7 +140,7 @@ export function buildToolSelectionTable(agents: AvailableAgent[], tools: Availab
88140 }
89141
90142 rows . push ( "" )
91- rows . push ( "**Default flow**: explore/librarian (background) + tools → oracle (if required)" )
143+ rows . push ( "**Default flow**: skill (if match) → explore/librarian (background) + tools → oracle (if required)" )
92144
93145 return rows . join ( "\n" )
94146}
0 commit comments