Skip to content

Commit d94733a

Browse files
committed
refactor: make phase context sharing optional to system prompt generation
1 parent c806f9d commit d94733a

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

worker/agents/operations/PhaseImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class PhaseImplementationOperation extends AgentOperation<PhaseImplementa
405405
// Notify phase start
406406
const codeGenerationFormat = new SCOFFormat();
407407
// Build messages for generation
408-
const messages = getSystemPromptWithProjectContext(SYSTEM_PROMPT, context, CodeSerializerType.SCOF);
408+
const messages = getSystemPromptWithProjectContext(SYSTEM_PROMPT, context, CodeSerializerType.SCOF, false);
409409

410410
// Create user message with optional images
411411
const userPrompt = userPromptFormatter(phase, issues, userContext?.suggestions) + codeGenerationFormat.formatInstructions();

worker/agents/operations/common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { CodingAgentInterface } from "../services/implementations/CodingAgent";
1010
export function getSystemPromptWithProjectContext(
1111
systemPrompt: string,
1212
context: GenerationContext,
13-
serializerType: CodeSerializerType = CodeSerializerType.SIMPLE
13+
serializerType: CodeSerializerType = CodeSerializerType.SIMPLE,
14+
sharePhases: boolean = true
1415
): Message[] {
1516
const { query, blueprint, templateDetails, dependencies, allFiles, commandsHistory } = context;
1617

@@ -23,7 +24,7 @@ export function getSystemPromptWithProjectContext(
2324
})),
2425
createUserMessage(
2526
USER_PROMPT_FORMATTER.PROJECT_CONTEXT(
26-
context.getCompletedPhases(),
27+
sharePhases ? context.getCompletedPhases() : [],
2728
allFiles,
2829
context.getFileTree(),
2930
commandsHistory,

worker/agents/prompts.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

13911393
export 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

Comments
 (0)