Escape Markdown in alert signals and cap OSINT text in ideas prompt
Addresses PR review: escape Markdown-sensitive characters in _formatTieredAlert signal bullets to prevent Telegram Bot API rejections, and add a 1500-char budget for URGENT_OSINT in compactSweepForLLM to bound prompt size while keeping full text upstream. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -730,7 +730,7 @@ Respond with ONLY valid JSON:
|
|||||||
if (evaluation.signals?.length) {
|
if (evaluation.signals?.length) {
|
||||||
lines.push('', `*Signals:*`);
|
lines.push('', `*Signals:*`);
|
||||||
for (const sig of evaluation.signals) {
|
for (const sig of evaluation.signals) {
|
||||||
lines.push(`• ${sig}`);
|
lines.push(`• ${escapeMd(sig)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,6 +742,11 @@ Respond with ONLY valid JSON:
|
|||||||
|
|
||||||
// ─── Helpers ──────────────────────────────────────────────────────────────
|
// ─── Helpers ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function escapeMd(text) {
|
||||||
|
if (!text) return '';
|
||||||
|
return text.replace(/([_*\[\]()~`>#+\-=|{}.!\\])/g, '\\$1');
|
||||||
|
}
|
||||||
|
|
||||||
function parseJSON(text) {
|
function parseJSON(text) {
|
||||||
if (!text) return null;
|
if (!text) return null;
|
||||||
let cleaned = text.trim();
|
let cleaned = text.trim();
|
||||||
|
|||||||
@@ -88,10 +88,20 @@ function compactSweepForLLM(data, delta, previousIdeas) {
|
|||||||
sections.push(`SUPPLY_CHAIN: GSCPI=${data.gscpi.value} (${data.gscpi.interpretation})`);
|
sections.push(`SUPPLY_CHAIN: GSCPI=${data.gscpi.value} (${data.gscpi.interpretation})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Geopolitical signals
|
// Geopolitical signals (cap total OSINT text to ~1500 chars to keep prompt compact)
|
||||||
const urgentPosts = (data.tg?.urgent || []).slice(0, 5);
|
const urgentPosts = (data.tg?.urgent || []).slice(0, 5);
|
||||||
if (urgentPosts.length) {
|
if (urgentPosts.length) {
|
||||||
sections.push(`URGENT_OSINT:\n${urgentPosts.map(p => `- ${p.text || ''}`).join('\n')}`);
|
const MAX_OSINT_CHARS = 1500;
|
||||||
|
let remaining = MAX_OSINT_CHARS;
|
||||||
|
const lines = [];
|
||||||
|
for (const p of urgentPosts) {
|
||||||
|
const text = p.text || '';
|
||||||
|
if (remaining <= 0) break;
|
||||||
|
const trimmed = text.length > remaining ? text.substring(0, remaining) + '…' : text;
|
||||||
|
lines.push(`- ${trimmed}`);
|
||||||
|
remaining -= trimmed.length;
|
||||||
|
}
|
||||||
|
sections.push(`URGENT_OSINT:\n${lines.join('\n')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thermal / fire detections
|
// Thermal / fire detections
|
||||||
|
|||||||
Reference in New Issue
Block a user