Files
aigen/utils/parseShots.ts
T
TowstyandCursor e334cb7a7a Move library collections as a group and map v2 identity refs.
Collapsed collection actions now move, rename, delete, and rerun every part so chains stay together. Identity mode follows the v2u3 Ref2VA picture wiring.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-26 22:56:37 -05:00

44 lines
1.4 KiB
TypeScript

export interface ParsedShot {
n: number
prompt: string
role: 'initial' | 'extension'
}
export function parseShotScript(text: string): ParsedShot[] {
const src = String(text || '').replace(/\r\n/g, '\n')
const marker = /^[ \t]*shot\s+(\d+)\b/gim
const markers: { n: number; start: number; end: number }[] = []
for (const match of src.matchAll(marker)) {
markers.push({
n: Number(match[1]),
start: match.index || 0,
end: (match.index || 0) + match[0].length
})
}
const blocks: { n: number; prompt: string }[] = []
if (!markers.length) {
const prompt = src.trim()
return prompt ? [{ n: 1, prompt, role: 'initial' }] : []
}
const preamble = src.slice(0, markers[0].start).trim()
if (preamble) blocks.push({ n: 1, prompt: preamble })
for (let i = 0; i < markers.length; i++) {
const from = markers[i].end
const to = i + 1 < markers.length ? markers[i + 1].start : src.length
const prompt = src.slice(from, to).trim()
if (prompt) blocks.push({ n: markers[i].n, prompt })
}
const byN = new Map<number, string>()
for (const block of blocks) {
const prev = byN.get(block.n)
byN.set(block.n, prev ? `${prev}\n${block.prompt}` : block.prompt)
}
return [...byN.entries()]
.sort((a, b) => a[0] - b[0])
.map(([n, prompt], index) => ({
n,
prompt,
role: index === 0 ? 'initial' : 'extension'
}))
}