chore(ab-corpus): add prompt-size measurement helper

One-shot diagnostic that prints char + token-estimate sizes for every
(variant, difficulty) combination of buildSystemPrompt. Used to verify
the elements-cookbook diet is shaving the bytes the test floor
predicts (>10kb) before running an actual sweep. Confirms today's
numbers: B 15kb, T-obvious 57kb, T-composite 75kb — diet saves ~17kb
(~4.4k tokens) on every obvious prompt. Phase 2 (per-domain split)
still needed to hit the 6-8k target.
This commit is contained in:
Fini 2026-04-29 09:49:43 +08:00
parent f385f433e1
commit 2f31b62ca9

View file

@ -0,0 +1,35 @@
#!/usr/bin/env bun
/**
* Quick inline diagnostic — prints character + 4:1-token-estimate sizes
* for every (variant, difficulty) combination of `buildSystemPrompt`.
* Run when tuning the elements-cookbook diet to confirm the gate is
* actually shaving the bytes the test floor predicts:
*
* bun scripts/ab-corpus/measure-prompt-sizes.ts
*
* Not wired into the harness — purely for human inspection. The
* authoritative regression guard is build-prompt.test.ts (>10kb floor).
*/
import { buildSystemPrompt } from './build-prompt';
const cases: Array<{ label: string; variant: 'B' | 'T'; difficulty?: 'obvious' | 'optional' | 'composite' }> = [
{ label: 'B (any difficulty) ', variant: 'B' },
{ label: 'T + difficulty="obvious" ', variant: 'T', difficulty: 'obvious' },
{ label: 'T + difficulty="optional" ', variant: 'T', difficulty: 'optional' },
{ label: 'T + difficulty="composite" ', variant: 'T', difficulty: 'composite' },
{ label: 'T + (no difficulty, safe default) ', variant: 'T' },
];
const tObvious = buildSystemPrompt('T', { difficulty: 'obvious' }).system.length;
const tComposite = buildSystemPrompt('T', { difficulty: 'composite' }).system.length;
const savings = tComposite - tObvious;
process.stdout.write(`Variant / Difficulty | Chars | ~Tokens (chars/4)\n`);
process.stdout.write(`---------------------+---------+------------------\n`);
for (const c of cases) {
const built = buildSystemPrompt(c.variant, c.difficulty ? { difficulty: c.difficulty } : {});
const len = built.system.length;
process.stdout.write(`${c.label} | ${String(len).padStart(7)} | ${String(Math.round(len / 4)).padStart(6)}\n`);
}
process.stdout.write(`\nObvious-vs-composite savings: ${savings} chars (~${Math.round(savings / 4)} tokens)\n`);