mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-04 05:47:59 +01:00
Two things seen live on 2026-10-24 after #229: - Chile: the buyers gap said twice — the computed sentence code inserted, and the model's own paraphrase beside it. - Russia: the answer opened "You are right: the `producers_in` rows do carry the `companies` cells … I summarized those out on the first pass. Rewriting below", went on with "`read_as` splits this to operator = …" — it was answering the wall send-back, in our vocabulary, to a reader who never saw it. - uncited.ts: the computed gap sentence is inserted only when no sentence already says that link is missing, in any words (gapSentences, matched by the link's box); oneGapEach keeps the first and drops later paraphrases with their "what would settle it". - internal.ts, last in finishInCode: a sentence that replies to a send-back ("you are right", "as you said", "sorry", "rewriting below", "on the first pass") goes; `companies` cell / `capacity` are put in words; a sentence still naming a tool (snake_case names from the registry) or a field (read_as, printed_once, null, [W#], …) goes. Fenced blocks are left alone. - turn.ts REVISION_RULE, at the end of every send-back (wall, figures, counts): write for the reader as if for the first time, never reply to the check, never name a tool, a field, a row or a lookup. The wall and figure send-backs no longer name producers_in, `companies` or `display`. - Evals (wall:false, verbatim live recordings on recorded tool output): the Russia answer as markdown and as the page, and the Chile gap-twice answer. Every recorded answer is graded: each gap said once, no line with a tool or field name or a reply to a check. Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE Co-authored-by: Claude <noreply@anthropic.com>
86 lines
4.0 KiB
TypeScript
86 lines
4.0 KiB
TypeScript
/**
|
||
* The reader's words only (lib/chat-agent/internal.ts): no tool or field name,
|
||
* no reply to a send-back — and the send-backs themselves name none, so the
|
||
* model is not invited to talk about them (turn.ts REVISION_RULE).
|
||
*/
|
||
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { readFileSync } from 'node:fs';
|
||
|
||
import { internalProblem, withoutInternals } from '../lib/chat-agent/internal';
|
||
import { reviseUnsupported } from '../lib/chat-agent/grounding';
|
||
import { missingLinks, wallInstruction } from '../lib/chat-agent/ladder';
|
||
import { claimInstruction } from '../lib/chat-agent/table-guard';
|
||
import { REVISION_RULE, type ModelTurn } from '../lib/chat-agent/turn';
|
||
import { gapSentences, oneGapEach } from '../lib/chat-agent/uncited';
|
||
|
||
const russia = readFileSync(
|
||
new URL('./fixtures/ask-live-ru-rare-earth-nickel-2026-10-24.md', import.meta.url),
|
||
'utf8',
|
||
);
|
||
const INTERNAL =
|
||
/producers_in|read_as|resource_production|`companies`|`display`|printed_once|send-back/;
|
||
|
||
test('a sentence that talks to the send-back, or names our machinery, is internal', () => {
|
||
for (const s of [
|
||
'You are right: the `producers_in` rows do carry the `companies` cells.',
|
||
"I'm sorry for the confusion above.",
|
||
'As you said, the owners are in the table.',
|
||
'I summarized those out on the first pass.',
|
||
'Rewriting below, quoting the printed cells.',
|
||
'`read_as` splits this to operator = OAO Apatit.',
|
||
'The resource_production lookup returned 23,270 t.',
|
||
])
|
||
assert.ok(internalProblem(s), s);
|
||
for (const s of [
|
||
'Ownership of the plants is in the table below.',
|
||
'Kazakhstan mined 23,270 t of uranium in 2024.',
|
||
'The buyers of Kazakhstan’s uranium output are not in our sources.',
|
||
'These companies operate the mines.',
|
||
])
|
||
assert.equal(internalProblem(s), null, s);
|
||
});
|
||
|
||
test('the recorded Russia answer reaches the reader without our vocabulary', () => {
|
||
assert.match(russia, /^You are right: the `producers_in` rows/);
|
||
const out = withoutInternals(russia);
|
||
assert.ok(!INTERNAL.test(out), out);
|
||
assert.ok(!/you are right|rewriting below|first pass/i.test(out));
|
||
for (const keep of ['OAO Apatit', 'PAO GMK Norilskiy Nickel (Nornickel)', '300000 metric tons'])
|
||
assert.ok(out.includes(keep), keep);
|
||
assert.match(out, /the USGS entry as printed: \*\*OAO Apatit\*\*/);
|
||
// A chart or code block is left as it is.
|
||
const fenced = '```chat_ui\n{"type":"chart"}\n```';
|
||
assert.equal(withoutInternals(fenced), fenced);
|
||
});
|
||
|
||
test('no send-back names a tool or a field, and every one says how to rewrite', async () => {
|
||
const kz = 'Which companies mine uranium in Kazakhstan, who owns them, and who do they sell to?';
|
||
const wall = wallInstruction(
|
||
{ kind: 'denies', what: ['facilities', 'owners'] },
|
||
missingLinks(kz, []),
|
||
);
|
||
const counts = claimInstruction(['17 ventures.'], ['The table has 17 rows.']);
|
||
let figures = '';
|
||
const turn: ModelTurn = async ({ messages }) => {
|
||
figures = String(messages[messages.length - 1].content);
|
||
return { text: 'ok', calls: [] } as never;
|
||
};
|
||
await reviseUnsupported({ messages: [], answer: 'x', figures: ['6 kt'], turn, onText: () => {} });
|
||
for (const text of [wall, counts, figures]) {
|
||
assert.ok(!INTERNAL.test(text), text);
|
||
assert.ok(text.includes(REVISION_RULE), 'tells the model not to reply to the check');
|
||
}
|
||
});
|
||
|
||
test('each missing link is said once, whatever the words', () => {
|
||
const twice =
|
||
"The buyers of Chile's lithium output are not in our sources. A source that would settle it: offtake records.\n\nThe buyers of Chile's output are not in our sources. A source that would settle it: customs records.\n\n### Unchecked web leads";
|
||
const gaps = [{ box: 'buyers' } as Parameters<typeof oneGapEach>[1][number]];
|
||
assert.equal(gapSentences(twice, 'buyers').length, 2);
|
||
const once = oneGapEach(twice, gaps);
|
||
assert.equal(gapSentences(once, 'buyers').length, 1);
|
||
assert.ok(once.includes('offtake records') && !once.includes('customs records'));
|
||
assert.ok(once.includes('### Unchecked web leads'));
|
||
});
|