Skip to content

Commit 14e5ddf

Browse files
committed
feat: Enhance project context templates for AI models with structured formatting and instructions
1 parent 3a21dbe commit 14e5ddf

File tree

1 file changed

+90
-9
lines changed

1 file changed

+90
-9
lines changed

index.js

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,20 +1194,59 @@
11941194
const parts = [];
11951195
// === AI Model Template Logic ===
11961196
if (S.model === 'gpt') {
1197-
parts.push('### GPT-4 CONTEXT TEMPLATE\n');
1197+
parts.push('# Project Context for GPT-4\n\n');
1198+
parts.push('## Instructions\n');
1199+
parts.push('You are being provided with a complete codebase context. Please:\n');
1200+
parts.push('- Analyze the code structure and architecture\n');
1201+
parts.push('- Understand dependencies between files\n');
1202+
parts.push('- Maintain consistency with existing code patterns\n');
1203+
parts.push('- Reference specific files when answering questions\n\n');
1204+
parts.push('## Project Structure\n```\n', struct, '```\n\n');
1205+
parts.push('## Source Files\n\n');
11981206
} else if (S.model === 'claude') {
1199-
parts.push('### CLAUDE CONTEXT TEMPLATE\n');
1207+
parts.push('# Codebase Context for Claude\n\n');
1208+
parts.push('<context>\n');
1209+
parts.push('<purpose>\n');
1210+
parts.push('This is a complete project codebase provided for analysis, code review, or implementation tasks.\n');
1211+
parts.push('Please analyze the architecture, patterns, and maintain consistency when making changes.\n');
1212+
parts.push('</purpose>\n\n');
1213+
parts.push('<project_structure>\n', struct, '</project_structure>\n\n');
1214+
parts.push('<source_files>\n');
12001215
} else if (S.model === 'gemini') {
1201-
parts.push('### GEMINI CONTEXT TEMPLATE\n');
1216+
parts.push('# Complete Project Context for Gemini\n\n');
1217+
parts.push('## Overview\n');
1218+
parts.push('Complete codebase with file structure and contents for analysis and development tasks.\n\n');
1219+
parts.push('## Directory Structure\n```\n', struct, '```\n\n');
1220+
parts.push('## File Contents\n\n');
12021221
}
1203-
parts.push('<folder-structure>\n', struct, '</folder-structure>\n');
12041222
// Binary files are intentionally excluded from the generated output (they remain visible in the tree)
12051223
// Build document sections faster - no UI updates during build
12061224
contents.forEach(({ path, content }) => {
12071225
const full = getFullPath(path);
1208-
parts.push(`=== FILE: ${full} ===\n`);
1209-
parts.push(`<document path=\"${path}\">\n`, content, '\n</document>\n');
1226+
const ext = path.split('.').pop().toLowerCase();
1227+
1228+
if (S.model === 'gpt') {
1229+
// GPT-4 format: Clear markdown with code blocks
1230+
parts.push(`### ${full}\n`);
1231+
parts.push('```', ext, '\n', content, '\n```\n\n');
1232+
} else if (S.model === 'claude') {
1233+
// Claude format: XML-style with clear metadata
1234+
parts.push(`<file path="${full}">\n`);
1235+
parts.push(`<language>${ext}</language>\n`);
1236+
parts.push(`<content>\n${content}\n</content>\n`);
1237+
parts.push('</file>\n\n');
1238+
} else if (S.model === 'gemini') {
1239+
// Gemini format: Structured with clear delimiters
1240+
parts.push(`## File: ${full}\n`);
1241+
parts.push(`**Language:** ${ext}\n\n`);
1242+
parts.push('```', ext, '\n', content, '\n```\n\n');
1243+
}
12101244
});
1245+
1246+
// Add closing tags for Claude
1247+
if (S.model === 'claude') {
1248+
parts.push('</source_files>\n</context>\n');
1249+
}
12111250

12121251
let ctx;
12131252
try {
@@ -1256,7 +1295,34 @@
12561295

12571296
const genAndDL = async (struct, textFiles, binaryFiles) => {
12581297
const parts = [];
1259-
parts.push('<folder-structure>\n', struct, '</folder-structure>\n');
1298+
1299+
// Add model-specific headers for download
1300+
if (S.model === 'gpt') {
1301+
parts.push('# Project Context for GPT-4\n\n');
1302+
parts.push('## Instructions\n');
1303+
parts.push('You are being provided with a complete codebase context. Please:\n');
1304+
parts.push('- Analyze the code structure and architecture\n');
1305+
parts.push('- Understand dependencies between files\n');
1306+
parts.push('- Maintain consistency with existing code patterns\n');
1307+
parts.push('- Reference specific files when answering questions\n\n');
1308+
parts.push('## Project Structure\n```\n', struct, '```\n\n');
1309+
parts.push('## Source Files\n\n');
1310+
} else if (S.model === 'claude') {
1311+
parts.push('# Codebase Context for Claude\n\n');
1312+
parts.push('<context>\n');
1313+
parts.push('<purpose>\n');
1314+
parts.push('This is a complete project codebase provided for analysis, code review, or implementation tasks.\n');
1315+
parts.push('Please analyze the architecture, patterns, and maintain consistency when making changes.\n');
1316+
parts.push('</purpose>\n\n');
1317+
parts.push('<project_structure>\n', struct, '</project_structure>\n\n');
1318+
parts.push('<source_files>\n');
1319+
} else if (S.model === 'gemini') {
1320+
parts.push('# Complete Project Context for Gemini\n\n');
1321+
parts.push('## Overview\n');
1322+
parts.push('Complete codebase with file structure and contents for analysis and development tasks.\n\n');
1323+
parts.push('## Directory Structure\n```\n', struct, '```\n\n');
1324+
parts.push('## File Contents\n\n');
1325+
}
12601326

12611327
let done = 0;
12621328
const FAST_BATCH = 100;
@@ -1292,8 +1358,23 @@
12921358
return;
12931359
}
12941360

1295-
parts.push('=== FILE: ' + getFullPath(p) + ' ===\n');
1296-
parts.push('<document path="' + p + '">\n', content, '\n</document>\n');
1361+
// Format based on selected AI model
1362+
const full = getFullPath(p);
1363+
const ext = p.split('.').pop().toLowerCase();
1364+
1365+
if (S.model === 'gpt') {
1366+
parts.push(`### ${full}\n`);
1367+
parts.push('```', ext, '\n', content, '\n```\n\n');
1368+
} else if (S.model === 'claude') {
1369+
parts.push(`<file path="${full}">\n`);
1370+
parts.push(`<language>${ext}</language>\n`);
1371+
parts.push(`<content>\n${content}\n</content>\n`);
1372+
parts.push('</file>\n\n');
1373+
} else if (S.model === 'gemini') {
1374+
parts.push(`## File: ${full}\n`);
1375+
parts.push(`**Language:** ${ext}\n\n`);
1376+
parts.push('```', ext, '\n', content, '\n```\n\n');
1377+
}
12971378

12981379
const sFileIndex = S.files.findIndex(sf => sf.path === p);
12991380
if (sFileIndex !== -1) {

0 commit comments

Comments
 (0)