Skip to content

Open CSV in the spreadsheet grid the product already has, not as raw text #41

Closed

Description

@bencode

Problem

A .csv file opens as raw text: csv sits in textExtensions and falls through to the text preview kind (files.ts:49,75), which the README documents as designed ("a .csv opens as text"). But CSV is the most common plain-data interchange format a reader imports — exports, logs, datasets — and as raw text it wraps or scrolls sideways with no column alignment, no way to scan a row, and no sheet tabs.

The asymmetry is sharper because the product already owns the right machinery: the spreadsheet grid (xlsx-reader, virtualized rows, sheet tabs, column letters) and the assistant's structure-aware sheet tools (features/agent/xlsx/ — sheet inventory with extents, read by A1 range) both consume the same Worksheet[] model from core/xlsx.ts. An xlsx gets all of that; a csv gets neither — the assistant reads it as flat lines with no range tools, and the human reads wrapped commas.

Proposal

  • Parse CSV into the existing Worksheet[] model (comma-delimited UTF-8, BOM tolerated, quoted and multiline fields per RFC 4180) and map it to the spreadsheet grid preview.
  • Keep CSV's current editing capability: unlike xlsx (read-only by nature), CSV today is an editable text document with a Source panel — the grid must not remove it. Give CSV the preview-plus-Source shape SVG already has.
  • Degrade safely: a CSV that fails structured parsing (odd encodings, exotic delimiters) falls back to today's text preview rather than an error.
  • The assistant's sheet tools apply to CSV workbooks unchanged, since they already operate on Worksheet[].

Goal

After this, importing a CSV opens the same grid an xlsx gets — sheet tab, aligned columns, row numbers — with Source editing preserved and the assistant reading sheets and ranges instead of flat text; unparsable files still open as text.

Verification

grep -q "extension === 'csv'" ui-packages/web/src/core/files.ts
pnpm --filter @gamma-reader/web test --silent
pnpm check

Refs

  • ui-packages/web/src/core/files.ts:49,75 — csv in textExtensions, falls to text kind
  • ui-packages/web/src/features/reader/xlsx-reader/index.tsx — existing grid consuming Worksheet[]
  • ui-packages/web/src/features/agent/xlsx/tools.ts — sheet tools consuming the same model
  • ui-packages/web/src/core/xlsx.ts — readSpreadsheet / Worksheet to extend
  • README.md "Document support" — Excel row ("search, and read by sheet and A1 range") vs the csv-as-text note

Activity

  1. added
    enhancement
    source:scheduled
    on Sep 30, 2026
  2. bencode commented on Sep 30, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire source:scheduled proposals.

    Evidence audit (against main@d28fe0b): core claims confirmed.

    • ✅ csv sits in textExtensions and falls through to the text preview kind (files.ts:49,75) — exactly as cited; README line 67 confirms "a .csv opens as text" is by design.
    • ✅ The reuse story is real: readSpreadsheet returns Worksheet[] (core/xlsx.ts:127), consumed by both the grid and features/agent/xlsx/ tools.
    • ✅ CSV is today an editable text document: the Source editor is wired through TextDocumentWorkspace (text-document-workspace/index.tsx:49-64, sourceOpen/synchronizeSource).
    • ✅ Sensor: lint passed; verify fails today as it should → stays open.

    Verdict: valid, keep open. Strong asymmetry argument (the machinery exists and serves xlsx only), and the safe-degrade clause is well chosen.

    One factual correction (should be fixed, non-blocking): the Proposal says "Give CSV the preview-plus-Source shape SVG already has" — SVG has no such shape. svg routes to the image preview kind (files.ts:46) and image-reader.tsx has no Source wiring; the preview-plus-Source shape belongs to text documents via TextDocumentWorkspace. Since CSV is currently a text document, the correct precedent is "the shape text documents already have" (which is also what "Source editing preserved" in the Goal actually requires). The sentence as written points an implementer at the wrong template.

  3. bencode commented on Sep 30, 2026

    @bencode
    OwnerAuthor

    Correction to my earlier review above. I flagged "the preview-plus-Source shape SVG already has" as a factual error, citing that svg routes to the image preview kind with no Source wiring. That was wrong: files.ts routing is overridden at the tab level — document-tabs.tsx:42-50 gives .svg a dedicated TextReaderDefinition (SvgReader preview + sourceLanguage: 'plain'), which is exactly the preview-plus-Source shape. The issue's sentence stands as written; the rest of my audit (including the verdict: valid, keep open) is unaffected. An implementer can use the SVG reader definition as the template the issue implies.

  4. bencode commented on Oct 1, 2026

    @bencode
    OwnerAuthor

    Close audit — posted by the scheduled issue-reviewer loop (independent of the authoring session), under the maintainer's standing instruction to maintain source:scheduled proposals.

    Auto-closed by the merge of #51 (7108d78), bypassing the relay close gate. Audit at main@fe2c123:

    • ✅ Implemented, beyond the proposal: dedicated RFC 4180 parser (core/csv.ts — quoted/multiline fields, BOM, CRLF, plus delimiter sniffing for ;/\t exports the proposal never asked for), CsvReader reusing the grid via the extracted shared sheet-grid.tsx, and Source editing preserved through the TextReaderDefinition shape (document-tabs.tsx:44,53). Safe degrade shipped as isTabular — a single-column file (prose named .csv) falls back to text reading. README note updated (f393022).
    • ✅ Unit suite green at this commit (parser + reader both have dedicated tests).
    • ⚠️ The Verification anchor fails despite genuine implementation: it expected extension === 'csv' in core/files.ts, but the implementation routed at the tab level (the same pattern SVG uses) and never touched files.ts — csv still sits in textExtensions. The gate would have refused a correct close. Recording this as the concrete failure mode of implementation-shaped anchors: the goal was met by a different, equally defensible route.

    Action: added state:needs-verification to normalize the lifecycle. Maintainer: swap to state:verified after opening a CSV in person (grid + Source + a semicolon-delimited export if handy), or reopen if it misses.

  5. added
    state:needs-verification
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduledstate:needs-verification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions