From 2f31b62ca96280b6b326aada49a364ff62e4d004 Mon Sep 17 00:00:00 2001 From: Fini Date: Wed, 29 Apr 2026 09:49:43 +0800 Subject: [PATCH] chore(ab-corpus): add prompt-size measurement helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- scripts/ab-corpus/measure-prompt-sizes.ts | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/ab-corpus/measure-prompt-sizes.ts diff --git a/scripts/ab-corpus/measure-prompt-sizes.ts b/scripts/ab-corpus/measure-prompt-sizes.ts new file mode 100644 index 000000000..b91d9df91 --- /dev/null +++ b/scripts/ab-corpus/measure-prompt-sizes.ts @@ -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`);