HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
fix(console): parse CSV and TSV previews as logical records (#292)
Yominma6f210d2f7abe
diff --git a/ui/src/components/FilePreview.tsx b/ui/src/components/FilePreview.tsxindex a3f5caf1..b11de39a 100644--- a/ui/src/components/FilePreview.tsx+++ b/ui/src/components/FilePreview.tsx@@ -11,6 +11,7 @@ import oneLight from 'react-syntax-highlighter/dist/esm/styles/prism/one-light';import { FileTypeIcon, extOf } from './FileTypeIcon';import { harnessFetch } from '@/lib/hfetch';import { authHeaders, downloadFile, fetchFileBlob } from '@/lib/chat';+import { csvToTable } from './csvToTable';const LANG: Record<string, string> = {js: 'javascript', mjs: 'javascript', cjs: 'javascript', jsx: 'jsx', ts: 'typescript', tsx: 'tsx',@@ -117,7 +118,7 @@ export function FilePreview({ file, onClose }: { file: { url: string; name: striif (kind === 'code' || kind === 'markdown' || kind === 'csv') {const t = await r.text();if (!alive) return;- if (kind === 'csv') setSt({ kind: 'csv', html: csvToTable(t) });+ if (kind === 'csv') setSt({ kind: 'csv', html: csvToTable(t, extOf(name) === 'tsv' ? '\t' : ',') });else setSt({ kind, text: t.slice(0, 400000) });} else if (kind === 'binary') {if (alive) setSt({ kind: 'binary' });@@ -183,23 +184,5 @@ export function FilePreview({ file, onClose }: { file: { url: string; name: stri);}-function csvToTable(text: string): string {- const rows = text.split(/\r?\n/).filter((r) => r.length).slice(0, 1000);- const esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');- const split = (line: string) => {- const out: string[] = []; let cur = ''; let q = false;- for (const ch of line) {- if (ch === '"') q = !q;- else if ((ch === ',' || ch === '\t') && !q) { out.push(cur); cur = ''; }- else cur += ch;- }- out.push(cur); return out;- };- return '<table>' + rows.map((r, i) => {- const cells = split(r).map((c) => `<${i === 0 ? 'th' : 'td'}>${esc(c.replace(/^"|"$/g, ''))}</${i === 0 ? 'th' : 'td'}>`).join('');- return `<tr>${cells}</tr>`;- }).join('') + '</table>';-}-const IcDownload = () => <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="M7 10l5 5 5-5" /><path d="M12 15V3" /></svg>;const IcX = () => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round"><path d="M18 6 6 18M6 6l12 12" /></svg>;diff --git a/ui/src/components/csvToTable.js b/ui/src/components/csvToTable.jsnew file mode 100644index 00000000..30de1b1c--- /dev/null+++ b/ui/src/components/csvToTable.js@@ -0,0 +1,69 @@+/**+ * Render delimited text as a small HTML table without changing cell values.+ * The delimiter is explicit so commas in TSV cells are never treated as separators.+ * @param {string} text+ * @param {string} delimiter+ * @returns {string}+ */+function csvToTable(text, delimiter = ",") {+ // Spreadsheet exports often include a UTF-8 BOM; it is metadata, not part of the first cell.+ text = text.replace(/^\uFEFF/, "");+ const rows = [];+ let row = [];+ let cell = "";+ let quoted = false;++ for (let i = 0; i < text.length && rows.length < 1000; i += 1) {+ const ch = text[i];++ if (quoted) {+ if (ch === '"') {+ if (text[i + 1] === '"') {+ cell += '"';+ i += 1;+ } else {+ quoted = false;+ }+ } else {+ cell += ch;+ }+ continue;+ }++ if (ch === '"' && cell.length === 0) {+ quoted = true;+ } else if (ch === delimiter) {+ row.push(cell);+ cell = "";+ } else if (ch === "\r" || ch === "\n") {+ row.push(cell);+ // Match the previous preview behavior by ignoring physically blank lines.+ if (row.length > 1 || row[0] !== "") rows.push(row);+ row = [];+ cell = "";+ if (ch === "\r" && text[i + 1] === "\n") i += 1;+ } else {+ cell += ch;+ }+ }++ if (rows.length < 1000 && (cell.length > 0 || row.length > 0)) {+ row.push(cell);+ if (row.length > 1 || row[0] !== "") rows.push(row);+ }++ const esc = (value) =>+ value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");+ return (+ "<table>" ++ rows+ .map((values, rowIndex) => {+ const tag = rowIndex === 0 ? "th" : "td";+ return `<tr>${values.map((value) => `<${tag}>${esc(value)}</${tag}>`).join("")}</tr>`;+ })+ .join("") ++ "</table>"+ );+}++module.exports = { csvToTable };diff --git a/ui/src/components/csvToTable.test.js b/ui/src/components/csvToTable.test.jsnew file mode 100644index 00000000..71d58c84--- /dev/null+++ b/ui/src/components/csvToTable.test.js@@ -0,0 +1,43 @@+const { test } = require("@jest/globals");+const assert = require("node:assert/strict");+const { csvToTable } = require("./csvToTable");++test("CSV preserves quoted delimiters, escaped quotes, and multiline fields", () => {+ const html = csvToTable('name,note\r\nAlice,"hello, ""world""\r\nagain"\r\n');+ assert.equal(+ html,+ '<table><tr><th>name</th><th>note</th></tr><tr><td>Alice</td><td>hello, "world"\r\nagain</td></tr></table>',+ );+});++test("TSV uses tabs as separators and keeps commas inside a cell", () => {+ const html = csvToTable("name\tnote\nAlice\thello, world", "\t");+ assert.equal(+ html,+ "<table><tr><th>name</th><th>note</th></tr><tr><td>Alice</td><td>hello, world</td></tr></table>",+ );+});++test("HTML metacharacters in values are escaped", () => {+ const html = csvToTable('name,note\nAlice,"<script>&"');+ assert.equal(+ html,+ "<table><tr><th>name</th><th>note</th></tr><tr><td>Alice</td><td><script>&</td></tr></table>",+ );+});++test("UTF-8 BOM is not included in the first header", () => {+ const html = csvToTable("\uFEFFname,note\nAlice,ok");+ assert.equal(+ html,+ "<table><tr><th>name</th><th>note</th></tr><tr><td>Alice</td><td>ok</td></tr></table>",+ );+});++test("preview remains capped at 1000 logical rows", () => {+ const input = [+ "h",+ ...Array.from({ length: 1002 }, (_, i) => String(i)),+ ].join("\n");+ assert.equal((csvToTable(input).match(/<tr>/g) || []).length, 1000);+});