@@ -25,7 +25,7 @@ const { buildCompartmentAgentPrompt } = promptMod as {
2525 extractionFree ?: boolean ;
2626 } ) => string ;
2727} ;
28- const { buildReferenceBlocks, selectSeeds, renderSeedExamplesBlock } = referenceMod as {
28+ const { buildReferenceBlocks, selectSeeds, renderSeedExamplesBlock, selectSessionReferences , renderSessionReferencesBlock } = referenceMod as {
2929 buildReferenceBlocks : ( args : {
3030 sessionId : string ;
3131 chunkStart : number ;
@@ -37,6 +37,8 @@ const { buildReferenceBlocks, selectSeeds, renderSeedExamplesBlock } = reference
3737 count ?: number ,
3838 ) => Array < { importance : number ; block : string } > ;
3939 renderSeedExamplesBlock : ( seeds : Array < { importance : number ; block : string } > ) => string ;
40+ selectSessionReferences : ( compartments : TsReferenceCompartment [ ] , seeds : Array < { importance : number ; block : string } > , sessionId : string , chunkStart : number ) => TsReferenceCompartment [ ] ;
41+ renderSessionReferencesBlock : ( selected : TsReferenceCompartment [ ] , window ?: number ) => string ;
4042} ;
4143const { renderHistorianMemoryBlock } = injectMod as {
4244 renderHistorianMemoryBlock : ( memories : TsMemory [ ] ) => string | null ;
@@ -190,14 +192,14 @@ const matureCompartments: ReferenceCompartmentJson[] = [
190192 {
191193 start_message : 1 ,
192194 end_message : 5 ,
193- title : "old omitted one" ,
195+ title : "older low-mid one" ,
194196 content : "old content one" ,
195197 importance : 10 ,
196198 } ,
197199 {
198200 start_message : 6 ,
199201 end_message : 12 ,
200- title : "old omitted two" ,
202+ title : "older low-mid two" ,
201203 content : "old content two" ,
202204 importance : 20 ,
203205 } ,
@@ -334,9 +336,9 @@ const promptCaseSpecs: PromptCaseSpec[] = [
334336] ;
335337
336338const seedCaseSpecs : SeedCaseSpec [ ] = [
337- { label : "default rotation a" , session_id : "rot-a" , chunk_start : 0 , count : 4 } ,
338- { label : "default rotation b" , session_id : "rot-b" , chunk_start : 1 , count : 4 } ,
339- { label : "unicode utf16 rotation" , session_id : "emoji-🚀-session" , chunk_start : 7 , count : 4 } ,
339+ { label : "default rotation a" , session_id : "rot-a" , chunk_start : 0 , count : 3 } ,
340+ { label : "default rotation b" , session_id : "rot-b" , chunk_start : 1 , count : 3 } ,
341+ { label : "unicode utf16 rotation" , session_id : "emoji-🚀-session" , chunk_start : 7 , count : 3 } ,
340342 { label : "flat fallback count above band guard" , session_id : "fallback" , chunk_start : 12345 , count : 25 } ,
341343] ;
342344
@@ -367,7 +369,7 @@ const promptCases: PromptCase[] = promptCaseSpecs.map((spec) => {
367369 } ) ;
368370 return {
369371 ...spec ,
370- selected_seed_indices : selectedSeedIndices ( spec . session_id , spec . chunk_start , 4 ) ,
372+ selected_seed_indices : selectedSeedIndices ( spec . session_id , spec . chunk_start , 3 ) ,
371373 seed_examples : refs . seedExamples ,
372374 session_references : refs . sessionReferences ,
373375 project_memory : projectMemory ,
@@ -376,7 +378,7 @@ const promptCases: PromptCase[] = promptCaseSpecs.map((spec) => {
376378} ) ;
377379
378380const distinctDefaultSelections = new Set (
379- seedCases . filter ( ( c ) => c . count === 4 ) . map ( ( c ) => JSON . stringify ( c . selected_indices ) ) ,
381+ seedCases . filter ( ( c ) => c . count === 3 ) . map ( ( c ) => JSON . stringify ( c . selected_indices ) ) ,
380382) ;
381383if ( distinctDefaultSelections . size <= 1 ) {
382384 throw new Error ( "seed rotation cases are vacuous; distinct inputs produced the same selection" ) ;
@@ -394,7 +396,38 @@ if (!promptCases.some((c) => c.project_memory.length > 0)) {
394396 throw new Error ( "prompt cases never emitted project memory" ) ;
395397}
396398
397- const golden = { seed_cases : seedCases , prompt_cases : promptCases } ;
399+ // Boundary scores, clustered histories and Unicode ids pin band choice, tie
400+ // rotation, no-content exclusion and every fitting suffix in both languages.
401+ const referenceSpecs = [
402+ { label : "mixed recent bands" , scores : [ 1 , 9 , 10 , 29 , 30 , 59 , 60 , 84 , 85 , 100 , 70 , 90 , 70 , 90 ] } ,
403+ { label : "all bands covered" , scores : [ 5 , 20 , 40 , 70 , 90 , 5 , 20 , 40 , 70 , 90 , 5 , 20 , 40 , 70 ] } ,
404+ { label : "history lacks low bands" , scores : [ 40 , 70 , 90 , 40 , 70 , 90 , 70 , 70 , 70 , 70 ] } ,
405+ { label : "one older band" , scores : [ ...Array ( 20 ) . fill ( 40 ) , 70 , 70 , 70 , 70 ] } ,
406+ { label : "no-content gaps" , scores : [ 5 , 20 , 40 , 70 , 90 , 50 , 70 , 90 ] , markers : true } ,
407+ ...Array . from ( { length : 6 } , ( _ , count ) => ( { label : `young ${ count } ` , scores : Array ( count ) . fill ( 50 ) } ) ) ,
408+ ] ;
409+ const referenceCases = referenceSpecs . map ( ( spec , caseIndex ) => {
410+ const session_id = "calibration-🚀" ;
411+ const chunk_start = 42 + caseIndex ;
412+ const session_compartments : ReferenceCompartmentJson [ ] = spec . scores . map ( ( importance , i ) => ( {
413+ start_message : i * 10 + 1 , end_message : i * 10 + 10 ,
414+ title : `Compartment ${ i } ` , content : `Body & <${ i } >` , importance, episode_type : "feature" ,
415+ } ) ) ;
416+ if ( "markers" in spec && spec . markers ) {
417+ for ( const at of [ session_compartments . length , 4 , 0 ] ) session_compartments . splice ( at , 0 , {
418+ start_message : 999 , end_message : 999 , title : "" , content : "" , importance : 1 ,
419+ } ) ;
420+ }
421+ const seeds = selectSeeds ( session_id , chunk_start ) ;
422+ const selected = selectSessionReferences ( session_compartments . map ( toTsCompartment ) , seeds , session_id , chunk_start ) ;
423+ return {
424+ label : spec . label , session_id, chunk_start, session_compartments,
425+ seed_examples : renderSeedExamplesBlock ( seeds ) ,
426+ selected_starts : selected . map ( ( c ) => c . startMessage ) ,
427+ windows : Array . from ( { length : 8 } , ( _ , window ) => ( { window, block : renderSessionReferencesBlock ( selected , window ) } ) ) ,
428+ } ;
429+ } ) ;
430+ const golden = { seed_cases : seedCases , prompt_cases : promptCases , reference_cases : referenceCases } ;
398431const rendered = `${ JSON . stringify ( golden , null , 2 ) } \n` ;
399432const outPath = join ( import . meta. dir , ".." , "testdata" , "historian-prompt-golden.json" ) ;
400433
@@ -408,8 +441,8 @@ if (process.argv.includes("--check")) {
408441 console . error ( `historian prompt golden drifted; regenerate ${ outPath } ` ) ;
409442 process . exit ( 1 ) ;
410443 }
411- console . log ( `historian prompt golden up to date: ${ outPath } ` ) ;
444+ console . log ( `historian prompt golden up to date: ${ promptCases . length } prompts, ${ seedCases . length } seeds, ${ referenceCases . length } reference selections: ${ outPath } ` ) ;
412445} else {
413446 writeFileSync ( outPath , rendered ) ;
414- console . log ( `wrote ${ promptCases . length } historian prompt cases + ${ seedCases . length } seed cases → ${ outPath } ` ) ;
447+ console . log ( `wrote ${ promptCases . length } prompts + ${ seedCases . length } seed cases + ${ referenceCases . length } reference selections → ${ outPath } ` ) ;
415448}
0 commit comments