UNPKG

scai

Version:

> **A local-first AI CLI for understanding, querying, and iterating on large codebases.** > **100% local • No token costs • No cloud • No prompt injection • Private by design**

28 lines (27 loc) 905 B
/** * Strict helper to extract tagged content. * - Requires the tag to be present * - Throws on missing or empty content * - No markdown fallback */ export function extractTaggedContent(rawText, tag) { const safeTag = escapeRegex(tag); const tagRegex = new RegExp(`<${safeTag}>([\\s\\S]*?)<\\/${safeTag}>`, 'gi'); const notesRegex = /<NOTES>([\s\S]*?)<\/NOTES>/i; const matches = [...rawText.matchAll(tagRegex)]; if (!matches.length) { throw new Error(`Missing <${tag}> tag in LLM response`); } const content = matches[matches.length - 1][1].trim(); if (!content) { throw new Error(`<${tag}> tag is present but empty`); } const notesMatch = rawText.match(notesRegex); return { content, notes: notesMatch ? notesMatch[1].trim() : null }; } function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }