import { heuristicExtract } from "../extract.js"; // --- Input generators --- const SHORT_PLAIN = `Here's the analysis of the codebase. ## Structure The project uses a monorepo layout with the following packages: - Core library in \`packages/core\` - CLI tool in \`packages/cli\` - Extension API in \`packages/api\` ### Dependencies All packages share a common tsconfig. The build uses esbuild for bundling. ### Testing We use Bun's built-in test runner. Coverage is tracked via \`bun test --coverage\`. ### Current Status The core library is stable. The CLI tool needs more work on the argument parser. The extension API is experimental and may change. Which package should we focus on first?`; const MEDIUM_MIXED = Array.from({ length: 4 }, (_, section) => { const headers = ["Preflight checks", "Build pipeline", "Test results", "Deployment"]; return `## ${headers[section]} Here's the status for ${headers[section]}: | Check | Status | Notes | |-------|--------|-------| | Lint | ✅ | No warnings | | Types | ✅ | Strict mode | | Build | ✅ | 2.3s | | Tests | ❌ | 3 failures | \`\`\`typescript interface Config { port: number; host: string; verbose: boolean; } const defaultConfig: Config = { port: 3000, host: "localhost", verbose: false, }; \`\`\` Some notes: - Port can be overridden via env var - Host defaults to localhost - Verbose mode logs all requests \`\`\`bash curl https://api.example.com?query=test&format=json \`\`\` > This should work in production. You can configure it via environment variables. > Does not require authentication for local development. Should we proceed with ${headers[section].toLowerCase()}?`; }).join("\n\n"); const LONG = Array.from({ length: 40 }, (_, i) => { const lines: string[] = []; lines.push(`## Section ${i + 1}`); lines.push(""); lines.push("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore."); lines.push(""); lines.push("```javascript"); lines.push(`const result = items.filter(x => x.active !== null ? x.value : defaultValue);`); lines.push(`// See https://docs.example.com?section=api for details`); lines.push("```"); lines.push(""); lines.push("| Name | Type | Default |"); lines.push("|------|------|---------|"); lines.push(`| field${i} | string | "value${i}" |`); lines.push(`| active | boolean | ${i % 2 === 0 ? "true" : "false"} |`); lines.push(""); lines.push("┌──────────┬──────────┐"); lines.push("│ Key │ Value │"); lines.push("├──────────┼──────────┤"); lines.push(`│ config │ ${i} │`); lines.push("└──────────┴──────────┘"); lines.push(""); lines.push("- First item with some detail"); lines.push("- Second item with more text"); lines.push("- Third item"); lines.push(""); lines.push("> This should work fine. Can be configured via env vars."); lines.push("> Does not require authentication."); lines.push(""); lines.push(`See https://api.example.com/v2/endpoint?param=value&other=${i} for reference.`); lines.push(""); if (i % 10 === 9) { lines.push(`What should we do about section ${i + 1}?`); lines.push("- Option A"); lines.push("- Option B"); lines.push("- Option C"); } return lines.join("\n"); }).join("\n\n"); const PATHOLOGICAL_TABLE = ` Here's every failure mode in order of the flow: 1. Preflight ┌──────────────────────────────┬────────────────┬──────────────────────────────────────────┐ │ What goes wrong │ Prompt │ Gap? │ │ │ reaction │ │ ├──────────────────────────────┼────────────────┼──────────────────────────────────────────┤ │ Dirty worktree │ Stops │ ✅ │ │ (unstaged/uncommitted) │ │ │ ├──────────────────────────────┼────────────────┼──────────────────────────────────────────┤ │ Ongoing merge/rebase in │ Stops │ ✅ │ │ progress │ │ │ ├──────────────────────────────┼────────────────┼──────────────────────────────────────────┤ │ Detached HEAD (git) │ — │ Gap — prompt doesn't check │ └──────────────────────────────┴────────────────┴──────────────────────────────────────────┘ 2. Fetch ┌─────────────────────────┬─────────────────┬──────────────────────────────────────────────┐ │ What goes wrong │ Prompt reaction │ Gap? │ ├─────────────────────────┼─────────────────┼──────────────────────────────────────────────┤ │ Network / auth failure │ Fails loudly │ ✅ │ ├─────────────────────────┼─────────────────┼──────────────────────────────────────────────┤ │ Remote force-pushed │ — │ Gap — fetch succeeds │ └─────────────────────────┴─────────────────┴──────────────────────────────────────────────┘ Want me to patch these into the prompt?`; // --- Benchmark runner --- function bench(name: string, fn: () => void, iterations: number) { // Warmup for (let i = 0; i < Math.min(iterations, 100); i++) fn(); const times: number[] = []; for (let i = 0; i < iterations; i++) { const start = performance.now(); fn(); times.push(performance.now() - start); } times.sort((a, b) => a - b); const mean = times.reduce((a, b) => a + b, 0) / times.length; const p50 = times[Math.floor(times.length * 0.5)]; const p99 = times[Math.floor(times.length * 0.99)]; const min = times[0]; console.log( `${name.padEnd(35)} mean=${mean.toFixed(3).padStart(8)}ms p50=${p50.toFixed(3).padStart(8)}ms p99=${p99.toFixed(3).padStart(8)}ms min=${min.toFixed(3).padStart(8)}ms (n=${iterations})`, ); } console.log("\n=== heuristicExtract baseline ===\n"); bench("short plain (~50 lines)", () => heuristicExtract(SHORT_PLAIN), 10000); bench("medium mixed (~200 lines)", () => heuristicExtract(MEDIUM_MIXED), 5000); bench("long (~2000 lines)", () => heuristicExtract(LONG), 1000); bench("pathological table", () => heuristicExtract(PATHOLOGICAL_TABLE), 10000);