Files
brain/tools/secretary-protocol.mjs
T

48 lines
2.3 KiB
JavaScript

// Структура и сверка короткого протокола (§D5/§D7). Отменённое зачёркивается, не удаляется.
export function EMPTY_PROTOCOL() {
return { decisions: [], will: [], open: [], doneNext: [], history: [] };
}
function prov(turns) {
return Array.isArray(turns) && turns.length ? ` [${turns.map((t) => `${t}`).join(', ')}]` : '';
}
export function applyExtraction(protocol, extraction = {}) {
const p = {
decisions: [...protocol.decisions], will: [...protocol.will], open: [...protocol.open],
doneNext: [...protocol.doneNext], history: [...protocol.history],
};
for (const d of extraction.decisions || []) {
p.decisions.push({ text: d.text, why: d.why || null, turns: d.turns || [], struck: false });
}
for (const s of extraction.supersede || []) {
const old = p.decisions.find((d) => d.text === s.oldText && !d.struck);
if (old) old.struck = true;
p.decisions.push({ text: s.newText, why: s.why || null, turns: s.turns || [], struck: false });
p.history.push({ oldText: s.oldText, newText: s.newText, turns: s.turns || [] });
}
for (const w of extraction.will || []) p.will.push({ text: w.text, turns: w.turns || [] });
for (const o of extraction.open || []) p.open.push({ text: o.text, turns: o.turns || [] });
for (const s of extraction.doneNext || []) p.doneNext.push({ text: s.text, done: !!s.done, turns: s.turns || [] });
return p;
}
export function renderProtocol(protocol) {
const L = [];
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 w of protocol.will) L.push(`- ${w.text}${prov(w.turns)}`);
L.push('', '## Открытые вопросы');
for (const o of protocol.open) L.push(`- ${o.text}${prov(o.turns)}`);
L.push('', '## Сделано / дальше');
for (const s of protocol.doneNext) L.push(`- [${s.done ? 'x' : ' '}] ${s.text}${prov(s.turns)}`);
L.push('', '## История (заменено, не стёрто)');
for (const h of protocol.history) L.push(`- ~~${h.oldText}~~ → ${h.newText}${prov(h.turns)}`);
return L.join('\n');
}