@@ -16,7 +16,7 @@ function stripFrontmatter(content: string): string {
1616
1717export async function readSkill (
1818 nameOrPath : string ,
19- options : { reference ?: string ; listRefs ?: boolean } ,
19+ options : { reference ?: string ; listRefs ?: boolean ; listExamples ?: boolean ; examplesForRef ?: string } ,
2020) : Promise < void > {
2121 // Support colon syntax: "skillName:path/to/file.ext"
2222 let skillName = nameOrPath ;
@@ -61,6 +61,68 @@ export async function readSkill(
6161 return ;
6262 }
6363
64+ // Mode 1b: List examples
65+ const refFilter = options . examplesForRef ?. trim ( ) ;
66+ if ( options . listExamples || options . examplesForRef !== undefined ) {
67+ if ( options . examplesForRef !== undefined && ! refFilter ) {
68+ console . error ( c ( 'red' , 'Reference name for --examples cannot be empty.' ) ) ;
69+ process . exit ( 1 ) ;
70+ }
71+ const refs = entry . references ?? [ ] ;
72+
73+ // Collect all examples, optionally filtered by reference
74+ const allExamples : Array < { ref : string ; name : string ; level : string ; description : string } > = [ ] ;
75+ for ( const ref of refs ) {
76+ if ( refFilter && ref . name !== refFilter ) continue ;
77+ if ( ! ref . examples || ref . examples . length === 0 ) continue ;
78+ for ( const ex of ref . examples ) {
79+ allExamples . push ( { ref : ref . name , name : ex . name , level : ex . level , description : ex . description } ) ;
80+ }
81+ }
82+
83+ if ( refFilter && ! refs . some ( ( r ) => r . name === refFilter ) ) {
84+ console . error ( c ( 'red' , `Reference "${ refFilter } " not found in skill "${ skillName } ".` ) ) ;
85+ console . log ( c ( 'gray' , `Use 'frontmcp skills read ${ skillName } --refs' to list available references.` ) ) ;
86+ process . exit ( 1 ) ;
87+ }
88+
89+ if ( allExamples . length === 0 ) {
90+ const scope = refFilter ? `reference "${ refFilter } "` : `skill "${ skillName } "` ;
91+ console . log ( c ( 'yellow' , `No examples found for ${ scope } .` ) ) ;
92+ return ;
93+ }
94+
95+ const title = refFilter ? `Examples for ${ skillName } > ${ refFilter } ` : `Examples for ${ skillName } ` ;
96+ console . log ( c ( 'bold' , `\n ${ title } :\n` ) ) ;
97+
98+ let currentRef = '' ;
99+ for ( const ex of allExamples ) {
100+ if ( ex . ref !== currentRef ) {
101+ currentRef = ex . ref ;
102+ console . log ( ` ${ c ( 'cyan' , currentRef ) } ` ) ;
103+ }
104+ const levelTag =
105+ ex . level === 'advanced'
106+ ? c ( 'red' , ex . level )
107+ : ex . level === 'intermediate'
108+ ? c ( 'yellow' , ex . level )
109+ : c ( 'green' , ex . level ) ;
110+ console . log ( ` ${ c ( 'green' , ex . name ) } ${ c ( 'gray' , `[${ levelTag } ]` ) } ` ) ;
111+ if ( ex . description ) {
112+ console . log ( ` ${ c ( 'gray' , ex . description ) } ` ) ;
113+ }
114+ }
115+ console . log ( '' ) ;
116+ console . log (
117+ c (
118+ 'gray' ,
119+ ` ${ allExamples . length } example(s). Read with: frontmcp skills read ${ skillName } :examples/<reference>/<example>.md` ,
120+ ) ,
121+ ) ;
122+ console . log ( '' ) ;
123+ return ;
124+ }
125+
64126 // Mode 2: Read a specific file (reference or any file in skill dir)
65127 if ( filePath ) {
66128 // Try exact path first, then references/<name>.md fallback
@@ -122,6 +184,10 @@ export async function readSkill(
122184 console . log ( c ( 'gray' , ` Has resources: ${ entry . hasResources } ` ) ) ;
123185 if ( entry . references && entry . references . length > 0 ) {
124186 console . log ( c ( 'gray' , ` References: ${ entry . references . length } (use --refs to list)` ) ) ;
187+ const exampleCount = entry . references . reduce ( ( sum , r ) => sum + ( r . examples ?. length ?? 0 ) , 0 ) ;
188+ if ( exampleCount > 0 ) {
189+ console . log ( c ( 'gray' , ` Examples: ${ exampleCount } (use --examples to list)` ) ) ;
190+ }
125191 }
126192 console . log ( '' ) ;
127193 console . log ( c ( 'gray' , ' ─────────────────────────────────────' ) ) ;
@@ -134,5 +200,9 @@ export async function readSkill(
134200 console . log ( c ( 'gray' , ` Install: frontmcp skills install ${ skillName } --provider claude` ) ) ;
135201 if ( entry . references && entry . references . length > 0 ) {
136202 console . log ( c ( 'gray' , ` References: frontmcp skills read ${ skillName } --refs` ) ) ;
203+ const footerExampleCount = entry . references . reduce ( ( sum , r ) => sum + ( r . examples ?. length ?? 0 ) , 0 ) ;
204+ if ( footerExampleCount > 0 ) {
205+ console . log ( c ( 'gray' , ` Examples: frontmcp skills read ${ skillName } --examples` ) ) ;
206+ }
137207 }
138208}
0 commit comments