@@ -893,6 +893,88 @@ test("createSession appends default system prompts in prefix-cache-friendly orde
893893 assert . equal ( systemContents [ 3 ] , "root project instructions" ) ;
894894} ) ;
895895
896+ test ( "createSession includes agent instructions in the skill matching system prompt" , async ( ) => {
897+ const workspace = createTempDir ( "deepcode-skill-match-create-workspace-" ) ;
898+ const home = createTempDir ( "deepcode-skill-match-create-home-" ) ;
899+ setHomeDir ( home ) ;
900+ globalThis . fetch = ( async ( ) => ( { ok : true , text : async ( ) => "" } ) as Response ) as typeof fetch ;
901+
902+ fs . mkdirSync ( path . join ( workspace , ".deepcode" ) , { recursive : true } ) ;
903+ fs . writeFileSync ( path . join ( workspace , ".deepcode" , "AGENTS.md" ) , "prefer project-specific skill matching" , "utf8" ) ;
904+ const skillDir = path . join ( workspace , ".deepcode" , "skills" , "project-aware" ) ;
905+ fs . mkdirSync ( skillDir , { recursive : true } ) ;
906+ fs . writeFileSync (
907+ path . join ( skillDir , "SKILL.md" ) ,
908+ "---\nname: project-aware\ndescription: Match project-specific instructions\n---\n# Project Aware\n" ,
909+ "utf8"
910+ ) ;
911+
912+ const requests : any [ ] = [ ] ;
913+ const client = {
914+ chat : {
915+ completions : {
916+ create : async ( request : any ) => {
917+ requests . push ( request ) ;
918+ return { choices : [ { message : { content : '{"skillNames":[]}' } } ] } ;
919+ } ,
920+ } ,
921+ } ,
922+ } ;
923+ const manager = createMockedClientSessionManagerWithClient ( workspace , client ) ;
924+ ( manager as any ) . activateSession = async ( ) => { } ;
925+
926+ await manager . createSession ( { text : "pick the right workflow" } ) ;
927+
928+ const messages = ( requests [ 0 ] ?. messages ?? [ ] ) as Array < { role ?: string ; content ?: string } > ;
929+ assert . equal ( messages [ 0 ] ?. role , "system" ) ;
930+ assert . match ( messages [ 0 ] ?. content ?? "" , / < a g e n t - i n s t r u c t i o n s > / ) ;
931+ assert . match ( messages [ 0 ] ?. content ?? "" , / p r e f e r p r o j e c t - s p e c i f i c s k i l l m a t c h i n g / ) ;
932+ assert . match ( messages [ 0 ] ?. content ?? "" , / < \/ a g e n t - i n s t r u c t i o n s > / ) ;
933+ assert . match ( messages [ 0 ] ?. content ?? "" , / T h e c a n d i d a t e s k i l l s a r e a s f o l l o w s / ) ;
934+ assert . equal ( messages [ 1 ] ?. role , "user" ) ;
935+ } ) ;
936+
937+ test ( "replySession includes current agent instructions in the skill matching system prompt" , async ( ) => {
938+ const workspace = createTempDir ( "deepcode-skill-match-reply-workspace-" ) ;
939+ const home = createTempDir ( "deepcode-skill-match-reply-home-" ) ;
940+ setHomeDir ( home ) ;
941+ globalThis . fetch = ( async ( ) => ( { ok : true , text : async ( ) => "" } ) as Response ) as typeof fetch ;
942+
943+ const requests : any [ ] = [ ] ;
944+ const client = {
945+ chat : {
946+ completions : {
947+ create : async ( request : any ) => {
948+ requests . push ( request ) ;
949+ return { choices : [ { message : { content : '{"skillNames":[]}' } } ] } ;
950+ } ,
951+ } ,
952+ } ,
953+ } ;
954+ const manager = createMockedClientSessionManagerWithClient ( workspace , client ) ;
955+ ( manager as any ) . activateSession = async ( ) => { } ;
956+
957+ const sessionId = await manager . createSession ( { text : "" } ) ;
958+ fs . writeFileSync ( path . join ( workspace , "AGENTS.md" ) , "use reply-time agent instructions" , "utf8" ) ;
959+ const skillDir = path . join ( workspace , ".agents" , "skills" , "reply-aware" ) ;
960+ fs . mkdirSync ( skillDir , { recursive : true } ) ;
961+ fs . writeFileSync (
962+ path . join ( skillDir , "SKILL.md" ) ,
963+ "---\nname: reply-aware\ndescription: Match reply-time instructions\n---\n# Reply Aware\n" ,
964+ "utf8"
965+ ) ;
966+
967+ await manager . replySession ( sessionId , { text : "pick the reply workflow" } ) ;
968+
969+ const messages = ( requests [ 0 ] ?. messages ?? [ ] ) as Array < { role ?: string ; content ?: string } > ;
970+ assert . equal ( messages [ 0 ] ?. role , "system" ) ;
971+ assert . match ( messages [ 0 ] ?. content ?? "" , / < a g e n t - i n s t r u c t i o n s > / ) ;
972+ assert . match ( messages [ 0 ] ?. content ?? "" , / u s e r e p l y - t i m e a g e n t i n s t r u c t i o n s / ) ;
973+ assert . match ( messages [ 0 ] ?. content ?? "" , / < \/ a g e n t - i n s t r u c t i o n s > / ) ;
974+ assert . match ( messages [ 0 ] ?. content ?? "" , / T h e c a n d i d a t e s k i l l s a r e a s f o l l o w s / ) ;
975+ assert . equal ( messages [ 1 ] ?. role , "user" ) ;
976+ } ) ;
977+
896978test ( "replySession stores /init and sends the active root project AGENTS path to the LLM" , async ( ) => {
897979 const workspace = createTempDir ( "deepcode-init-root-workspace-" ) ;
898980 const home = createTempDir ( "deepcode-init-root-home-" ) ;
0 commit comments