// Структура и сверка короткого протокола (§D5/§D7). Отменённое зачёркивается, не удаляется. export function EMPTY_PROTOCOL() { return { subject: '', status: 'открыто', decisions: [], alternatives: [], consequences: [], will: [], open: [], doneNext: [], history: [], steps: [], }; } // Провенанс: первый ход — где внесено [→N]; последующие — где снова касались [M]. function prov(turns) { if (!Array.isArray(turns) || !turns.length) return ''; const [first, ...rest] = turns; return ` [→${first}]${rest.map((t) => `, [${t}]`).join('')}`; } // Провенанс в обычных строках — только [→N]; имя файла/сессии живёт в разделе «Шаги». const line = (e) => `${e.struck ? `~~${e.text}~~` : e.text}${prov(e.turns)}`; // Шаги (Слой 1): человекочитаемая строка на КАЖДЫЙ ход («спросил → ответил»), в конце — // ссылка(и) на сырьё для подробностей. Шаги ведёт хук (по ходу), не модель. function stepsSection(p) { const steps = (p.steps || []).slice().sort((a, b) => (a.turn || 0) - (b.turn || 0)); // Ссылка на отдельный файл хода (file=«ходы/turn-N.log»), проставленный при остановке; // до нарезки — запасной вариант на общий лог сессии. return steps.map((s) => { const ref = s.file || (s.session ? `${s.session}.log` : ''); return `- ${s.text}${ref ? ` · ${ref}` : ''}`; }); } // Полная форма протокола (§D7): шапка «Дело» + 8 корзин (2–9) + навигация Шаги→Слой 1. export function renderProtocol(protocol, opts = {}) { const L = []; if (opts.work) { L.push(`**Дело:** ${opts.work} · **Статус:** ${protocol.status || 'открыто'} · ` + `**Дата:** ${opts.date || ''} · **Хозяин:** владелец · **Цель:** ${protocol.subject || ''}`, ''); } L.push('## Решения'); for (const d of protocol.decisions || []) { const body = d.struck ? `~~${d.text}~~` : d.text; const why = d.why ? ` — ${d.why}` : ''; L.push(`- ${body}${why}${prov(d.turns)}`); } L.push('', '## Альтернативы'); for (const a of protocol.alternatives || []) L.push(`- ${line(a)}`); L.push('', '## Последствия / цена'); for (const c of protocol.consequences || []) L.push(`- ${line(c)}`); L.push('', '## Твоя воля / запреты'); for (const w of protocol.will || []) L.push(`- ${line(w)}`); L.push('', '## Открытые вопросы'); for (const o of protocol.open || []) L.push(`- ${line(o)}`); L.push('', '## Сделано / дальше'); for (const s of protocol.doneNext || []) L.push(`- [${s.done ? 'x' : ' '}] ${s.struck ? `~~${s.text}~~` : s.text}${prov(s.turns)}`); L.push('', '## История (заменено, не стёрто)'); for (const hh of protocol.history || []) { if (Array.isArray(hh.events) && hh.events.length) { // Тайм-линия: внёс [→N], вынес [←N]; может повторяться (вернул/снова вынес). const seq = hh.events.map((ev) => (ev.dir === 'out' ? `[←${ev.turn}]` : `[→${ev.turn}]`)).join(' '); const removed = hh.events[hh.events.length - 1].dir === 'out'; L.push(`- ${removed ? `~~${hh.text}~~` : hh.text} ${seq}`); } else { L.push(`- ~~${hh.oldText}~~ → ${hh.newText}${prov(hh.turns)}`); // legacy-формат } } L.push('', '## Шаги (Слой 1)'); for (const s of stepsSection(protocol)) L.push(s); return L.join('\n'); }