Skip to content

Commit e069e0b

Browse files
committed
feat: Enhance XML escaping and improve Claude format handling
1 parent f74d95c commit e069e0b

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

index.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,16 @@
947947
cls: '' // No custom classes needed - icons are already colored
948948
};
949949
};
950-
const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '<').replace(/>/g, '>');
950+
// Escape text for HTML/XML contexts
951+
const esc = s => String(s)
952+
.replace(/&/g, '&amp;')
953+
.replace(/</g, '&lt;')
954+
.replace(/>/g, '&gt;')
955+
.replace(/\"/g, '&quot;')
956+
.replace(/'/g, '&apos;');
957+
958+
// XML-specific escape (alias for clarity)
959+
const xmlEscape = esc;
951960
// ============================================================================
952961
// CUSTOM MODAL - NO ALERTS
953962
// ============================================================================
@@ -1571,10 +1580,10 @@
15711580
parts.push(`### ${full}\n`);
15721581
parts.push('```', ext, '\n', content, '\n```\n\n');
15731582
} else if (S.model === 'claude') {
1574-
// Claude format: XML-style with clear metadata
1575-
parts.push(`<file path="${full}">\n`);
1576-
parts.push(`<language>${ext}</language>\n`);
1577-
parts.push(`<content>\n${content}\n</content>\n`);
1583+
// Claude format: XML-style with proper escaping
1584+
parts.push(`<file path="${xmlEscape(full)}">\n`);
1585+
parts.push(`<language>${xmlEscape(ext)}</language>\n`);
1586+
parts.push(`<content>\n${xmlEscape(content)}\n</content>\n`);
15781587
parts.push('</file>\n\n');
15791588
} else if (S.model === 'gemini') {
15801589
// Gemini format: Structured with clear delimiters
@@ -1584,9 +1593,9 @@
15841593
}
15851594
});
15861595

1587-
// Add closing tags for Claude
1596+
// Add closing tags for Claude (match opening tag)
15881597
if (S.model === 'claude') {
1589-
parts.push('</source_files>\n</context>\n');
1598+
parts.push('</source_files>\n</codebase_context>\n');
15901599
}
15911600

15921601
let ctx;
@@ -1609,6 +1618,13 @@
16091618
S.ctx = ctx;
16101619
S.isArray = false;
16111620

1621+
// Debugging: log generated output summary
1622+
try {
1623+
console.log('Generated context:', { model: S.model, size: ctx.length, preview: ctx.substring(0, 200) });
1624+
} catch (e) {
1625+
console.log('Generated context (unable to preview):', { model: S.model });
1626+
}
1627+
16121628
if (isLarge) {
16131629
const prev = ctx.substring(0, 50000);
16141630
const rem = ctx.length - 50000;
@@ -1820,9 +1836,9 @@
18201836
parts.push(`### ${full}\n`);
18211837
parts.push('```', ext, '\n', content, '\n```\n\n');
18221838
} else if (S.model === 'claude') {
1823-
parts.push(`<file path="${full}">\n`);
1824-
parts.push(`<language>${ext}</language>\n`);
1825-
parts.push(`<content>\n${content}\n</content>\n`);
1839+
parts.push(`<file path="${xmlEscape(full)}">\n`);
1840+
parts.push(`<language>${xmlEscape(ext)}</language>\n`);
1841+
parts.push(`<content>\n${xmlEscape(content)}\n</content>\n`);
18261842
parts.push('</file>\n\n');
18271843
} else if (S.model === 'gemini') {
18281844
parts.push(`## File: ${full}\n`);
@@ -1852,9 +1868,9 @@
18521868
}
18531869
}
18541870

1855-
// Add closing tags for Claude format
1871+
// Add closing tags for Claude format (match opening tag)
18561872
if (S.model === 'claude') {
1857-
parts.push('</source_files>\n</context>\n');
1873+
parts.push('</source_files>\n</codebase_context>\n');
18581874
}
18591875

18601876
await new Promise(r => setTimeout(r, 0));

0 commit comments

Comments
 (0)