@@ -1126,15 +1126,7 @@ PROJECT_CONTEXT: `Here is everything you will need about the project:
11261126
11271127<PROJECT_CONTEXT>
11281128
1129- <COMPLETED_PHASES>
1130-
1131- The following phases have been completed and implemented:
1132-
1133- {{redactionNotice}}
1134-
1135- {{phases}}
1136-
1137- </COMPLETED_PHASES>
1129+ {{phasesText}}
11381130
11391131<CODEBASE>
11401132
@@ -1387,10 +1379,21 @@ ${staticAnalysisText}
13871379- **FOCUS** on deployment-blocking runtime errors over linting issues`
13881380}
13891381
1382+ const COMPLETED_PHASES_CONTEXT = `
1383+ <COMPLETED_PHASES>
1384+
1385+ The following phases have been completed and implemented:
1386+
1387+ {{redactionNotice}}
1388+
1389+ {{phases}}
1390+
1391+ </COMPLETED_PHASES>`
13901392
13911393export const USER_PROMPT_FORMATTER = {
13921394 PROJECT_CONTEXT : ( phases : PhaseConceptType [ ] , files : FileState [ ] , fileTree : FileTreeNode , commandsHistory : string [ ] , serializerType : CodeSerializerType = CodeSerializerType . SIMPLE , recentPhasesCount : number = 1 ) => {
13931395 let lastPhaseFilesDiff = '' ;
1396+ let phasesText = '' ;
13941397 try {
13951398 if ( phases . length > 1 ) {
13961399 const lastPhase = phases [ phases . length - 1 ] ;
@@ -1408,37 +1411,35 @@ export const USER_PROMPT_FORMATTER = {
14081411 }
14091412 } ) ;
14101413 }
1411- }
1412- } catch ( error ) {
1413- console . error ( 'Error processing project context:' , error ) ;
1414- }
14151414
1416- // TODO: Instead of just including diff for last phase, include last diff for each file along with information of which phase it was modified in
1415+ // Split phases into older (redacted) and recent (full) groups
1416+ const olderPhases = phases . slice ( 0 , - recentPhasesCount ) ;
1417+ const recentPhases = phases . slice ( - recentPhasesCount ) ;
1418+
1419+ // Serialize older phases without files, recent phases with files
1420+ if ( olderPhases . length > 0 ) {
1421+ const olderPhasesLite = olderPhases . map ( ( { name, description } ) => ( { name, description } ) ) ;
1422+ phasesText += TemplateRegistry . markdown . serialize ( { phases : olderPhasesLite } , z . object ( { phases : z . array ( PhaseConceptLiteSchema ) } ) ) ;
1423+ if ( recentPhases . length > 0 ) {
1424+ phasesText += '\n\n' ;
1425+ }
1426+ }
1427+ if ( recentPhases . length > 0 ) {
1428+ phasesText += TemplateRegistry . markdown . serialize ( { phases : recentPhases } , z . object ( { phases : z . array ( PhaseConceptSchema ) } ) ) ;
1429+ }
1430+
1431+ const redactionNotice = olderPhases . length > 0
1432+ ? `**Note:** File details for the first ${ olderPhases . length } phase(s) have been redacted to optimize context. Only the last ${ recentPhasesCount } phase(s) include complete file information.\n`
1433+ : '' ;
14171434
1418- // Split phases into older (redacted) and recent (full) groups
1419- const olderPhases = phases . slice ( 0 , - recentPhasesCount ) ;
1420- const recentPhases = phases . slice ( - recentPhasesCount ) ;
1421-
1422- // Serialize older phases without files, recent phases with files
1423- let phasesText = '' ;
1424- if ( olderPhases . length > 0 ) {
1425- const olderPhasesLite = olderPhases . map ( ( { name, description } ) => ( { name, description } ) ) ;
1426- phasesText += TemplateRegistry . markdown . serialize ( { phases : olderPhasesLite } , z . object ( { phases : z . array ( PhaseConceptLiteSchema ) } ) ) ;
1427- if ( recentPhases . length > 0 ) {
1428- phasesText += '\n\n' ;
1435+ phasesText = COMPLETED_PHASES_CONTEXT . replaceAll ( '{{phases}}' , phasesText ) . replaceAll ( '{{redactionNotice}}' , redactionNotice ) ;
14291436 }
1437+ } catch ( error ) {
1438+ console . error ( 'Error processing project context:' , error ) ;
14301439 }
1431- if ( recentPhases . length > 0 ) {
1432- phasesText += TemplateRegistry . markdown . serialize ( { phases : recentPhases } , z . object ( { phases : z . array ( PhaseConceptSchema ) } ) ) ;
1433- }
1434-
1435- const redactionNotice = olderPhases . length > 0
1436- ? `**Note:** File details for the first ${ olderPhases . length } phase(s) have been redacted to optimize context. Only the last ${ recentPhasesCount } phase(s) include complete file information.\n`
1437- : '' ;
14381440
14391441 const variables : Record < string , string > = {
1440- phases : phasesText ,
1441- redactionNotice : redactionNotice ,
1442+ phasesText : phasesText ,
14421443 files : PROMPT_UTILS . serializeFiles ( files , serializerType ) ,
14431444 fileTree : PROMPT_UTILS . serializeTreeNodes ( fileTree ) ,
14441445 lastDiffs : lastPhaseFilesDiff ,
0 commit comments