# How I Built a 200MB Streaming JSONL Eval Diff Viewer for VS Code and Cursor With Zero Runtime Dependencies

> Source: <https://dev.to/miaoduitwcreator/how-i-built-a-200mb-streaming-jsonl-eval-diff-viewer-for-vs-code-and-cursor-with-zero-runtime-3926>
> Published: 2026-11-30 03:39:31+00:00

**Recommendation:** For large JSONL eval diffs, stream with readline under explicit file-size and buffered-byte caps, and escape every dynamic field behind a nonce CSP before rendering in a Webview.
More in the playbook "Evals and testing for LLM apps": <https://wpnews.pro/playbooks/evals-testing>

When you iterate on LLM prompts, RAG pipelines, or local model quantizations, your most important artifact is usually two boring `.jsonl` files: `baseline.jsonl` and `candidate.jsonl`.

Yet inspecting what actually regressed between those two files inside an editor is surprisingly painful:

`fs.readFileSync()` a 120MB JSONL file, `JSON.parse()` every row, and shove the entire array into `webview.postMessage()`. The renderer stalls or crashes.`<script>alert("xss")</script>` payloads in prompts and completions. Dropping raw eval text into an HTML report or Webview is an instant security bug.
To solve this for my own workflow, I built **EvalDiff** (`v0.2.0`)—a 100% local, strictly read-only extension for Cursor, Windsurf, VSCodium, Antigravity, and VS Code with **zero third-party runtime npm dependencies**.

Here are the four concrete engineering patterns that made it fast, safe, and crash-proof.

Instead of buffering an entire file into memory, `src/diffEngine.js` uses only Node.js built-ins (`fs.createReadStream` and `readline`) with three explicit safety guards:

`maxFileSizeMB`, default 200MB)` fs.promises.stat`.` maxFieldChars`, default 8,000 chars)` maxBufferedBytes`, default 64MB)

``` js
const stream = fs.createReadStream(filePath, {
  encoding: 'utf8',
  highWaterMark: 64 * 1024
});
const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });

try {
  for await (const line of rl) {
    totalLines += 1;
    const trimmed = line.trim();
    if (!trimmed) {
      blankLines += 1;
      continue;
    }

    let parsed;
    try {
      parsed = JSON.parse(trimmed);
    } catch (parseErr) {
      malformedCount += 1;
      malformedLines.push({
        lineNumber: totalLines,
        rawPreview: trimmed.slice(0, 160),
        error: parseErr.message
      });
      continue;
    }

    const normalized = normalizeRecord(parsed, totalLines, maxFieldChars);
    const recBytes = estimateRecordBytes(normalized);

    if (bufferedBytes + recBytes > maxBufferedBytes && records.length > 0) {
      truncated = true;
      truncationReason = 'MEMORY_LIMIT';
      break;
    }

    bufferedBytes += recBytes;
    records.push(normalized);
  }
} finally {
  rl.close();
  stream.destroy();
}
```

Notice two details:

`finally` block guarantees file descriptors are closed immediately if the memory circuit breaker trips.
A common VS Code extension anti-pattern is sending the full parsed array to the Webview and filtering in browser JS. In EvalDiff, all filtering (`status: regression | improvement | unchanged | added | removed`), keyword search, sorting (` regressionFirst`), and human review state stay inside the Extension Host.

The Webview only sends tiny query messages (`{ status: 'regression', search: 'SELECT', page: 1 }`) and receives:

`summary` object (< 2KB)`50` cases by default)
When the panel closes (`panel.onDidDispose`), the Extension Host drops its reference immediately so GC reclaims memory.

Unlike generic data tools that open local SQLite databases in read-write mode (risking WAL locks or file corruption), EvalDiff never opens source `.jsonl` files for writing. Our unit test suite verifies SHA-256 hashes of both input files before and after diffing to prove zero bytes changed.

Human Pass/Fail review annotations live separately in VS Code `context.workspaceState`, keyed by a SHA-1 hash of the file pair.

Meanwhile, both the Webview UI and exported standalone HTML audit reports lock down a strict nonce CSP (`default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-...'`) and escape every dynamic field:

```
function escapeHtml(value) {
  if (value === null || value === undefined) return '';
  return String(value)
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}
```

AI teams rarely agree on JSONL column names. OpenAI Evals writes `sample_id` + `messages` + `completion`, Promptfoo often exports `case_id` + `response` + `duration_ms`, and custom Python scripts use `score` or boolean `passed`.

Instead of forcing users to write a YAML mapping config, `normalizeRecord` resolves common aliases in priority order—even flattening OpenAI `messages` arrays and summing `usage.prompt_tokens + usage.completion_tokens` when `total_tokens` is absent.

If you want framework-specific setup notes:

For monetization, I wanted an honest split that never compromises offline privacy:

`.jsonl` inspection, side-by-side diff up to 100 cases with KPI summary, malformed line diagnostics, local Pass/Fail review, and one-click Markdown PR summary copy.
License activation uses Polar's public Customer Portal endpoint (`POST /v1/customer-portal/license-keys/activate`) with no private tokens in the extension—and it only fires when a user explicitly runs `EvalDiff: Activate Pro License Key`. After activation, the license state is cached in VS Code `globalState`, so everyday usage remains 100% offline.

```
git clone https://github.com/miaoduitw-creator/evaldiff-workbench.git
cd evaldiff-workbench
npm test
```

All 12 unit tests (streaming fault tolerance, read-only SHA-256 verification, regression math, OOM circuit breakers, XSS escaping, and mocked Polar license lifecycle) run on Node's built-in `node:test` runner with zero `npm install` step.

Or install directly from Open VSX for Cursor / Windsurf / VSCodium / Antigravity:

[https://open-vsx.org/extension/miaodui/evaldiff-workbench](https://open-vsx.org/extension/miaodui/evaldiff-workbench)
