@@ -142,6 +142,19 @@ function profileCorpus(fileNames) {
142142 . join ( '\n' )
143143}
144144
145+ function profileCorpusEntries ( fileNames ) {
146+ return fileNames . map ( fileName => {
147+ const info = profileFileInfo ( fileName )
148+ const text = info . source === 'missing' ? '' : fs . readFileSync ( info . path , 'utf8' )
149+ return { fileName, info, text }
150+ } )
151+ }
152+
153+ function extractExplicitProfileTiers ( text ) {
154+ return [ ...String ( text || '' ) . matchAll ( / P r o f i l e \s * 档 位 [ : : ] \s * ` ? ( p r o f i l e - (?: l i t e | s t a n d a r d | c l o s e d - l o o p ) ) ` ? / gi) ]
155+ . map ( match => match [ 1 ] )
156+ }
157+
145158function hasCurrentAgentsDistribution ( text ) {
146159 return / d e v c o d e x \/ a g e n t s \/ \s * → \s * \. g i t h u b \/ a g e n t s \/ / . test ( text ) &&
147160 / ( C o p i l o t [ ^ \n 。 ] * 默 认 分 发 | 默 认 分 发 [ ^ \n 。 ] * C o p i l o t ) / . test ( text ) &&
@@ -594,7 +607,7 @@ const PROFILE_TIER_GATES = [
594607]
595608
596609function detectProfileTier ( ) {
597- const combined = profileCorpus ( [
610+ const tierFiles = [
598611 'README.md' ,
599612 '01-项目信息.md' ,
600613 '02-架构约束.md' ,
@@ -604,11 +617,34 @@ function detectProfileTier() {
604617 '05-发布规范.md' ,
605618 '06-功能清单.md' ,
606619 '07-用户文档与契约规范.md'
607- ] )
608- const explicitTier = combined . match ( / P r o f i l e \s * 档 位 [ : : ] \s * ` ? ( p r o f i l e - (?: l i t e | s t a n d a r d | c l o s e d - l o o p ) ) ` ? / i)
609- if ( explicitTier ) {
610- return { tier : explicitTier [ 1 ] , combined }
620+ ]
621+ const entries = profileCorpusEntries ( tierFiles )
622+ const combined = entries
623+ . map ( entry => `\n--- ${ entry . fileName } (${ entry . info . source } ) ---\n${ entry . text } ` )
624+ . join ( '\n' )
625+
626+ const projectTiers = entries
627+ . filter ( entry => entry . info . source === 'project' )
628+ . flatMap ( entry => extractExplicitProfileTiers ( entry . text ) )
629+ const uniqueProjectTiers = [ ...new Set ( projectTiers ) ]
630+ if ( uniqueProjectTiers . length > 1 ) {
631+ warn ( `[profile] multiple project-local profile tiers declared: ${ uniqueProjectTiers . join ( ', ' ) } ` )
632+ }
633+ if ( uniqueProjectTiers . length >= 1 ) {
634+ return { tier : uniqueProjectTiers [ 0 ] , combined }
635+ }
636+
637+ const fallbackTiers = entries
638+ . filter ( entry => entry . info . source !== 'missing' )
639+ . flatMap ( entry => extractExplicitProfileTiers ( entry . text ) )
640+ const uniqueFallbackTiers = [ ...new Set ( fallbackTiers ) ]
641+ if ( uniqueFallbackTiers . length > 1 ) {
642+ warn ( `[profile] multiple fallback profile tiers declared: ${ uniqueFallbackTiers . join ( ', ' ) } ` )
643+ }
644+ if ( uniqueFallbackTiers . length >= 1 ) {
645+ return { tier : uniqueFallbackTiers [ 0 ] , combined }
611646 }
647+
612648 const matches = [ ...combined . matchAll ( / \b p r o f i l e - (?: l i t e | s t a n d a r d | c l o s e d - l o o p ) \b / g) ] . map ( match => match [ 0 ] )
613649 const unique = [ ...new Set ( matches ) ]
614650 if ( unique . length > 1 ) {
0 commit comments