UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

36 lines • 1.64 kB
export const INLINE_WORDS = { comment: (text) => text, typed: (_header, text) => text }; const reference = (label) => `(see [${label}] below)`; export function separatedWords(requestId) { const words = []; const place = (base, text) => { const taken = words.filter((word) => word.label === base || word.label.startsWith(`${base} (`)).length; const label = taken === 0 ? base : `${base} (${taken + 1})`; words.push({ label, text }); return reference(label); }; return { words, comment: (text) => place(`The user's comment for question ${requestId}`, text), typed: (header, text) => place(`The user's answer to ${header} for question ${requestId}`, text), }; } /** Puts each word back where its reference stands, for display. */ export function resolveUserWordReferences(text, words) { return words.reduce((resolved, word) => resolved.split(reference(word.label)).join(word.text), text); } /** The label and word blocks after a later answer's frame block, as `userWordBlocks` wrote them. */ export function readUserWordBlocks(content) { const texts = content.flatMap((block) => (block.type === "text" ? [block.text] : [])); if (texts.length % 2 !== 0) return undefined; const words = []; for (let index = 0; index < texts.length; index += 2) { const label = /^\[(.+)\]$/s.exec(texts[index] ?? "")?.[1]; const text = texts[index + 1]; if (label === undefined || text === undefined) return undefined; words.push({ label, text }); } return words; } //# sourceMappingURL=user-words.js.map