feat(czat): karta podmiotu w turze czatu i przełącznik A/B (B8-B9)

chatTurn liczy plan mapy na obu ramionach (graf: false zapisuje tylko
grafDry). Przy graf: true/'tabela' i trasie data: dopytanie przy dwóch
kandydatach, karta podmiotu/sprawy/osoby za przepisami albo krótka karta
powiązań za nazwanym rekordem; found przycięte do składowych i rekordów
nazywających podmiot (z zachowaniem found.top), chatPick, want i bramka
CHAT_SCOPE wyłączone przy karcie, dopisek chatCardHint na końcu. Domyślnie
graf = chat.graf !== false; harnessy podają graf jawnie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uwxqFLC3q51VqQzdfk12g
This commit is contained in:
tobayah
2026-11-11 03:00:38 +01:00
co-authored by Claude Opus 5.5
parent ff3b18ea98
commit 1bf95309fd
+32 -8
View File
@@ -3700,7 +3700,8 @@ const CHAT_ADVICE = /naj(?:ważn|piln|pierw)|priorytet|co\s+(?:\p{L}+\s+){0,3}?(
// One turn of the conversation without the page: sources, messages, the model round and the gates. It fills
// and returns `answer`; `turns` are the turns before this question; the page renders through `onUpdate`.
// The evaluation harness (testy/czat-v2/run.mjs) runs this very function from Node, so no DOM in here.
async function chatTurn({ model, question, turns, index, answer = { role: 'assistant', content: '', status: '', refs: [], trace: [] }, onUpdate = () => {} }) {
async function chatTurn({ model, question, turns, index, answer = { role: 'assistant', content: '', status: '', refs: [], trace: [] }, onUpdate = () => {},
graf = chat.graf !== false }) {
const done = (content, extra = {}) => Object.assign(answer, { content, status: '', ...extra });
try {
// "Umowa o dzieło" in a question about the law is not a question about Compass's contracts.
@@ -3758,7 +3759,18 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
const focus = [...named, ...resolved].filter((r) => r.kind === 'umowa');
let review = [];
let topic = [];
const route = chatRoute(question, focus, named.length + resolved.length);
// Computed on both arms: on A it only records whether B would have had a card (coverage without extra turns).
let gt = null;
try { gt = index.graph && chatGraphTurn({ question, index, named, resolved, back }); } catch (ex) { console.warn('chat map off:', ex); }
if (graf && gt && gt.ask) return done(gt.ask, { coded: 'ask', mentioned: gt.mentioned, graf: gt });
// "Wypowiedzenie umowy z Velmora Pompy" names a client, so it is a data question, not one for Insider.
const route = chatRoute(question, focus, named.length + resolved.length + (graf && gt && (gt.root || gt.link) ? 1 : 0));
// A card only for a data question: a cited article stays Insider's.
const card = !graf || !gt || route !== 'data' ? null : gt.root ? chatCard(gt.root, index, today, { table: graf === 'tabela' })
: gt.link ? chatLinkCard(gt.link, index, today) : null;
// Set here, so turns that end early (done) carry it too; the harness reads it from every answer.
if (graf) answer.graf = gt && { root: gt.root || null, link: gt.link || null, why: gt.why || null, card: card && card.rec.key, members: card ? [...card.members] : [] };
else answer.grafDry = gt && { root: gt.root || null, link: gt.link || null, why: gt.why || null, ask: !!gt.ask };
// A cited provision with no Insider access: given no text, Bielik answered from memory and cited a [2] it had not.
if (route === 'law_cite' && !index.law) {
return done('Nie masz dostępu do Insidera, więc nie pobiorę tekstu tego przepisu i nie sprawdzę, czy obowiązuje. O dostęp poproś administratora.', { coded: 'refusal' });
@@ -3792,10 +3804,21 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
let found = topic.length ? [] : chatSearch(index.records, question + (ana.demonstrative && prevQ ? ' ' + prevQ : ''));
// "z nich": the rest of the slots stay with that kind and the totals, not with whatever shares a word.
if (back.length) found = found.filter((r) => r.kind === back[0].kind || r.kind === 'zestawienie');
// The card replaces what search found around the name: the activity list, the firm's whole deadline summary
// and the 30/60/90-day windows were what misled both models on 2026-11-10. Records naming the subject stay.
// filter() drops `top`, which the CHAT_SCOPE gate reads.
if (card && card.rec.kind === 'karta') {
const top = found.top;
found = Object.assign(found.filter((r) => card.members.has(r.key) || card.names(r)), { top });
}
const seen = new Set();
const pick = review.length || law.length || topic.length || named.length || resolved.length || back.length ? null : chatPick(question, index);
const pick = review.length || law.length || topic.length || named.length || resolved.length || back.length || card ? null : chatPick(question, index);
if (pick && !pick.table.rows.length) return done(pick.empty, { coded: 'pick', refs: [], verify: [] });
const sources = [...(pick ? [pick.rec] : []), ...review, ...law, ...topic, ...named, ...resolved, ...backSum, ...back, ...clauses, ...chatCarry(prev, index), ...found]
// The entity's card right after law and topic; a one-record link card behind its record, so [1] stays the record.
const sources = [...(pick ? [pick.rec] : []), ...review, ...law, ...topic,
...(card && card.rec.kind === 'karta' ? [card.rec] : []), ...named, ...resolved,
...(card && card.rec.kind !== 'karta' ? [card.rec] : []), ...backSum, ...back, ...clauses, ...chatCarry(prev, index),
...(card ? card.lead : []), ...found]
.filter((r) => !seen.has(r.key) && seen.add(r.key)).slice(0, CHAT_TOP + law.length + review.length + topic.length + clauses.length);
const name = (slug) => (chatModules().find((m) => m.slug === slug) || { name: slug }).name;
const toRef = (r, i) => ({ n: i + 1, key: r.key, kind: r.kind, slug: r.slug, module: name(r.slug), title: r.title, text: r.text,
@@ -3804,9 +3827,9 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
answer.trace = sources.map((r, i) => `[${i + 1}] ${name(r.slug)}: ${r.title}`);
answer.status = 'Myślę…';
onUpdate(answer);
const about = resolved.map((r) => `[${sources.indexOf(r) + 1}] ${r.title}`);
const about = [...resolved, ...(card && card.rec.kind === 'karta' ? [card.rec] : [])].map((r) => `[${sources.indexOf(r) + 1}] ${r.title}`);
const count = pick ? null : chatCount(question);
const want = count || pick ? null : chatListFor(sources, question);
const want = count || pick || card ? null : chatListFor(sources, question);
// Without it the model named only what failed and called "the rest" current, hiding which the rest were.
const hint = review.length ? '\n(Odpowiedz listą: każdy przepis z przeglądu [1] w osobnym punkcie, z jego oceną, także te aktualne.)'
// The search matches words, so a found article may not answer; the model says which one does, or none.
@@ -3835,7 +3858,7 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
'Jeśli źródła nie pozwalają ocenić, co ważniejsze albo co zrobić, napisz to wprost zamiast zgadywać. Krótko.)' : '') +
(risk && clauses.length ? '\n(Wymień ryzykowne klauzule, każdą w jednym wierszu: jej §, na czym polega ryzyko i którą stronę obciąża. Klauzuli, która chroni nas, nie nazywaj ryzykiem. Krótko.)' : '') +
(clauses.length ? '\n(Warunki umowy bierz tylko z klauzul w źródłach i podawaj ich oznaczenie §; czego w klauzulach nie ma, tego nie twierdź.)' : '');
const messages = chatMessages(index.blind, question, sources, chatHistory(turns, answer.refs), about, hint + shape);
const messages = chatMessages(index.blind, question, sources, chatHistory(turns, answer.refs), about, hint + shape + chatCardHint(card, sources, graf));
const round = async (msgs) => {
const got = await chatRound(model, msgs, answer, onUpdate);
const { finish } = got;
@@ -3870,7 +3893,7 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
if (!cited.length &&!/nie znalazłem|nie masz dostępu|nie mam dostępu|pomagam|did not find|could not find|couldn't find|no access|don't have access/i.test(text)) {
// Uncited and nothing in the data matched the question well (a poem, small talk): out of scope, said by
// code. Uncited although records matched stays an error: that answer came from the model's memory.
if (!named.length && !resolved.length && !law.length && !review.length && !topic.length && found.top < CHAT_OFFTOPIC) {
if (!named.length && !resolved.length && !law.length && !review.length && !topic.length && found.top < CHAT_OFFTOPIC && !card) {
return done(CHAT_SCOPE, { coded: 'refusal', refs: [], verify: [] });
}
throw new Error(_tr('model odpowiedział bez wskazania źródła, czyli z pamięci. Zapytaj jeszcze raz albo inaczej.'));
@@ -3888,6 +3911,7 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
}
}
if (pick && pick.table.rows.length) answer.table = pick.table;
if (card && graf === 'tabela' && card.table.rows.length) answer.table = card.table;
if (answer.table) answer.content = text = text + '\n\n' + chatTableText(answer.table);
answer.mentioned = chatMentioned(text, sources, index);
answer.quotes = chatQuotes(answer);