Skip to content

feat(editor): open spreadsheets and Word documents (xlsx/csv editable, docx preview) - #20363

Open
excellence-wh wants to merge 12 commits into
stablyai:mainfrom
excellence-wh:feat/spreadsheet-preview-edit
Open

excellence-wh wants to merge 12 commits into
stablyai:mainfrom
excellence-wh:feat/spreadsheet-preview-edit

Conversation

@excellence-wh

@excellence-wh excellence-wh commented Sep 12, 2026 •

Copy link
Copy Markdown

ELI5

Orca's editor already previews images and PDFs. This change makes it open the everyday Office files too: .xlsx and .csv open in an editable spreadsheet grid, and .docx opens as a read-only rendered document — instead of falling back to the "binary file can't be displayed" state.

What Changed

Read path (local + SSH relay)

  • New shared model src/shared/spreadsheet/ (workbook/sheet/row/cell; string/number/boolean/null) and an exceljs wrapper (excel-xlsx.ts) that parses and serializes xlsx.
  • .xlsx is now classified as isSpreadsheet, .docx as isOfficeDocument; both are delivered to the renderer as base64 content with the right MIME type. Classification lives in one helper (resolvePreviewableBinaryMime) so the single-shot and streamed SSH read paths agree.
  • Shared modules avoid the global Buffer (the renderer has none) — base64 uses atob/btoa + Uint8Array.

Write path

  • xlsx saves go through the existing save pipeline with an encoding: 'base64' target; local writes use Buffer, SSH writes reuse the existing provider.writeFileBase64 (SFTP). Binary writes bypass editorDrafts and carry their content directly.

Renderer

  • SpreadsheetFileSurface + EditableSpreadsheetGrid: a virtualized, editable grid with worksheet tabs and a Save action for .xlsx; .csv edits go through the normal text-draft pipeline (Cmd/Ctrl+S, autosave, dirty state). Both are lazy-loaded.
  • OfficeDocumentViewer: read-only .docx rendering via docx-preview (MIT), currently pages rendered into a scrollable surface.

Other

  • New UI strings across en/zh/ja/ko/fr/es.
  • Unit tests for xlsx parse/serialize, CSV serialization, and the binary classification helper.

Why

Opening a spreadsheet or a Word document is a common thing to do in a workspace, and today Orca shows nothing useful for either. This extends the existing previewable-binary pattern (images, PDFs) rather than adding a new subsystem: classify by extension, ship the blob as base64, render with a focused viewer. .xlsx editing is a grid round-trip (formulas/formatting/merged cells are not preserved); .docx is preview-only by design.

Scope: .xlsx/.csv editable, .docx read-only. .pptx is intentionally out of scope for this PR.

Linked Issue

Fixes #20362

Visual Proof

BEFORE — .xlsx and .docx fell back to the generic panel. This shot opens a legacy .doc (still unsupported) to show that same "binary file — cannot display" panel:

before

AFTER — .xlsx opens in the editable grid (worksheet header + Save button, cell editing), and .docx renders as a document (CJK text and embedded images):

after xlsx

after docx

.csv uses the same grid as .xlsx.

Testing

  • pnpm typecheck — pass

  • pnpm build — pass (renderer + native)

  • pnpm lint — code-quality / max-lines / i18n gates pass; verify:skill-bundle-manifest fails on this branch for a pre-existing, unrelated reason (resources/skills/*.json are stale on the base — no resources/skills change in this PR)

  • Automated tests: xlsx parse/serialize, CSV serialize, binary classification helper. (Full pnpm test suite was not run locally to completion.)

  • Manually verified on Windows: .xlsx opens in the grid and saves; .docx renders (including CJK text); the read path returns isOfficeDocument + base64 through the real IPC.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Platforms actually exercised: Windows (local). SSH/remote paths share the same classification helper and existing base64 SFTP write, but were not manually exercised against a live remote in this session.

AI Disclosure

Implemented with an AI coding agent (Hermes Agent), driving edits, typecheck, build, and on-machine verification.

Agent skill upstream boundary

  • Not applicable.

Notes

  • Security: no new network surface; files are read/written through existing IPC with the same path authorization.
  • Cross-platform: base64/binary handling is platform-neutral; write path keeps the existing local vs SSH split.
  • SSH/remote: classification and base64 read/write are implemented on both the local and relay paths.
  • Performance: viewers are lazy-loaded chunks; large spreadsheets render through a virtualized grid. Opening a very large .xlsx/.docx loads the whole blob (same as the existing image/PDF preview behavior).
  • Backwards compatibility: new IPC result fields are optional; existing text/binary handling is unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…tion

- add [email protected] (renderer dev dependency; passes the 4320h supply-chain
  policy on the full 1391-entry lockfile)
- add shared spreadsheet extension/mime classification (.xlsx/.xls)
- add a normalized SpreadsheetData model + exceljs-backed xlsx parse/serialize
  (round-trips the cell grid and worksheet names; formulas read as cached
  results, formatting intentionally dropped)
- 5 unit tests covering parse, sparse-cell normalization, invalid-buffer
  rejection and serialize round-trips
… SSH)

- classify .xlsx/.xls as previewable spreadsheets on both the local
  (filesystem read/write handlers) and relay/SSH (fs-handler) read paths,
  delivering the raw bytes as base64 with an isSpreadsheet marker instead of
  the generic "binary cannot display" empty blob; adds isSpreadsheet to the
  FileContent type
- base64 write-back: fs:writeFile accepts an encoding option (local writes
  the decoded buffer; SSH routes through the existing SFTP writeFileBase64),
  so an edited workbook can return to disk
- share mime classification via resolvePreviewableBinaryMime; move
  readFullStreamChunk into fs-handler-stream-chunk so fs-handler-file-read
  stays under the 300-line limit
- node typecheck + oxlint clean; existing fs-handler-file-range tests pass
- add an editable, virtualized SpreadsheetFileSurface grid for both formats:
  CSV keeps the text-draft path (Cmd+S / autosave / dirty indicator work
  unchanged via serialized drafts); XLSX renders a worksheet-tab grid and
  saves through the editor save pipeline with encoding='base64'
- thread an optional encoding through the editor save target -> autosave
  controller -> save queue -> writeRuntimeFile -> fs:writeFile, so a binary
  workbook returns to disk (local writes the decoded buffer, SSH reuses the
  existing SFTP writeFileBase64)
- wire EditorEditFileSurface: isSpreadsheet files render the grid; CSV rich
  mode switches from the read-only CsvViewer to the editable grid
- preload fs type gains isSpreadsheet + writeFile encoding
- i18n keys for Save/Saving/read-failed/save-failed across en/zh/ja/ko/fr/es
- tests: 3 csv-serialize round-trip cases; node+web typecheck and oxlint clean
excel-xlsx.ts used Buffer.from for base64 decode/encode; the renderer has no
global Buffer, so every xlsx open threw 'Buffer is not defined' and the grid
showed a generic read-failed message. Encode/decode with atob/btoa +
Uint8Array, which are available in both Node >= 16 and browsers, so the shared
module round-trips identically in node (tests) and the renderer (exceljs
browser build). Verified in-app: parsing a real xlsx returns the grid.

Also log the underlying parser error to the console for diagnosis.
Add a read-only .docx preview so Word documents open in the editor instead of
falling back to the generic 'binary file' state, mirroring the existing
image/PDF preview pattern.

- classify .docx in the shared office-file-extensions and both read paths
  (local fs:readFile + SSH relay) so the blob arrives as base64 content with a
  new isOfficeDocument flag, keeping isImage/isSpreadsheet single-valued
- render with docx-preview (MIT) in a lazy OfficeDocumentViewer; the viewer
  decodes base64 with atob (no global Buffer in the renderer) and renders pages
  into a scrollable, read-only surface
- thread isOfficeDocument through FileContent, the preload read type, and the
  relay StreamMetadata
- tests: 4 cases covering the image/spreadsheet/office/plain classification;
  i18n keys (loading + read-failed) across en/zh/ja/ko/fr/es; node+web typecheck
  and oxlint clean
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c353553c-8e74-4a6d-b414-4c0cd9d23b4c

📥 Commits

Reviewing files that changed from the base of the PR and between 2257fb9 and ae02dc1.

📒 Files selected for processing (2)
  • src/renderer/src/runtime/runtime-file-mutation-client.test.ts
  • src/renderer/src/runtime/runtime-file-mutation-client.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The editor classifies spreadsheet and Office files during file reads. It adds normalized spreadsheet parsing, CSV serialization, editable CSV/XLSX views, and read-only DOCX rendering. The save pipeline supports UTF-8 and base64 content for local and SSH-backed files. New tests cover MIME classification, CSV serialization, XLSX parsing and serialization, encoded saves, and DOCX link filtering.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to ae02d

The updated runtime save routing preserves separate base64 and text write paths with targeted tests. No unresolved merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 29 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: editor support for editable spreadsheets and read-only Word document previews.
Description check ✅ Passed The description follows the required template and covers the change, rationale, linked issue, visual proof, testing, AI disclosure, platform considerations, and checklist. It also clearly states that …
Linked Issues check ✅ Passed Issue [#20362] requires editable .xlsx and .csv support, worksheet tabs, save support, read-only .docx rendering, and local and SSH operation. The changes add spreadsheet classification, base64 …
Out of Scope Changes check ✅ Passed The changes remain within issue [#20362]. MIME classification, base64 file exchange, spreadsheet parsing and serialization, editable grid behavior, DOCX rendering and filtering, save integration, loca…

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 396725f0-4750-4321-bf00-f3b5ff2bec10

📥 Commits

Reviewing files that changed from the base of the PR and between 719c434 and e4ba7a1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (33)
  • package.json
  • src/main/ipc/filesystem/filesystem-read-handlers.ts
  • src/main/ipc/filesystem/filesystem-write-handlers.ts
  • src/preload/api/filesystem-api.ts
  • src/relay/fs-handler-classify.test.ts
  • src/relay/fs-handler-file-range.test.ts
  • src/relay/fs-handler-file-range.ts
  • src/relay/fs-handler-file-read.ts
  • src/relay/fs-handler-stream-chunk.ts
  • src/relay/fs-handler-utils.ts
  • src/renderer/src/components/editor/EditableSpreadsheetGrid.tsx
  • src/renderer/src/components/editor/EditorEditFileSurface.tsx
  • src/renderer/src/components/editor/OfficeDocumentViewer.tsx
  • src/renderer/src/components/editor/SpreadsheetFileSurface.tsx
  • src/renderer/src/components/editor/csv-serialize.test.ts
  • src/renderer/src/components/editor/csv-serialize.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-lazy-views.ts
  • src/renderer/src/components/editor/editor-panel-content-types.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/runtime/runtime-file-mutation-client.ts
  • src/shared/office-file-extensions.ts
  • src/shared/spreadsheet-file-extensions.ts
  • src/shared/spreadsheet/excel-xlsx.test.ts
  • src/shared/spreadsheet/excel-xlsx.ts
  • src/shared/spreadsheet/spreadsheet-data.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/shared/spreadsheet/excel-xlsx.ts Resolved
Comment thread src/shared/spreadsheet/excel-xlsx.ts Resolved
- save queue: a base64 (workbook) save writes the caller's payload instead of a
  stale text draft, which would have corrupted the file on disk; regression test
  covers the existing-draft case
- xlsx surface: keep the external-change banner on editable workbooks so a
  changed-on-disk file still warns before saving stale content
- csv: re-serialize with the delimiter detected at load time rather than
  re-detecting against an empty string (a tab-delimited file no longer rewrites
  with commas)
- csv: keep edited fields as raw text; numeric coercion rewrote identifiers like
  `00123` as `123` and dropped trailing zeros
- xlsx save: only clear dirty when no edit landed during the async write
- classification: drop `.xls` until BIFF parsing exists — it opened empty and
  then overwrote the file on save
- parser: flatten rich-text runs, keep error cell values, and preserve blank rows
  so later row indices do not shift
@excellence-wh

Copy link
Copy Markdown
Author

Addressed in 71b3e55 — each item mapped to its fix:

Review item Fix
base64 payload replaced by editorDrafts queueSave uses fallbackContent when encoding === 'base64'; regression test with an existing draft (editor-save-queue.test.ts)
external-change banner bypassed for editable XLSX the xlsx branch now renders inside the shared banner shell
CSV delimiter discarded on edit the delimiter detected at load time is stored and reused for every edit/save
edited CSV fields coerced to numbers CSV cells stay raw text (00123 no longer becomes 123)
dirty cleared during async XLSX save an edit revision gates the dirty reset
.xls claimed without BIFF support removed from SPREADSHEET_FILE_MIME_TYPES
rich-text / error cells normalizeCellValue flattens richText runs and keeps error values
blank rows dropped the parser walks the full row range, preserving row indices

Verification: pnpm typecheck clean (node + web); unit tests pass for the parser (incl. rich text, error cells, blank rows), CSV serializer, save queue, and binary classification.

@excellence-wh

Copy link
Copy Markdown
Author

On the two remaining pre-merge warnings:

Linked Issues check — the .xlsx branch is editable. EditorEditFileSurface renders <SpreadsheetFileSurface kind="xlsx" readOnly={activeFile.readOnly === true} onDirty={handleDirtyStateHint} />. Cell edits call markDirty() → onDirty → the tab dirty flag, and the surface's toolbar renders a Save button for kind === 'xlsx'. handleSave serializes the workbook and calls requestEditorFileSave({ fileId, fallbackContent: base64, encoding: 'base64' }), which the save queue now writes verbatim (the fix in 71b3e55). Worksheet tabs come from data.worksheets. Verified in-app on Windows by opening a real .xlsx, editing, and saving. The onCsvChange={noopEditorContentChange} you may have keyed on is the CSV text-draft channel, which does not apply to the binary XLSX path — XLSX dirty state goes through onDirty.

Docstring coverage — this repo's AGENTS.md asks for concise, non-obvious comments only ("WHY not HOW"), and the touched functions are mostly small internal helpers; I added // Why: notes at the non-obvious spots (delimiter reuse, revision-gated dirty reset, base64 payload selection, blank-row preservation, .xls exclusion) rather than docstrings on every function. Happy to add full docstrings if the maintainers prefer that here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1730b849-21fe-47f9-9597-596799f6ab75

📥 Commits

Reviewing files that changed from the base of the PR and between e4ba7a1 and 71b3e55.

📒 Files selected for processing (7)
  • src/renderer/src/components/editor/EditorEditFileSurface.tsx
  • src/renderer/src/components/editor/SpreadsheetFileSurface.tsx
  • src/renderer/src/components/editor/editor-save-queue.test.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/shared/spreadsheet-file-extensions.ts
  • src/shared/spreadsheet/excel-xlsx.test.ts
  • src/shared/spreadsheet/excel-xlsx.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/shared/spreadsheet/excel-xlsx.ts
  • src/shared/spreadsheet-file-extensions.ts
  • src/renderer/src/components/editor/SpreadsheetFileSurface.tsx
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/EditorEditFileSurface.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@excellence-wh

Copy link
Copy Markdown
Author

Done in 5612e02 — the serialize round-trip test now asserts rows[1] and rows[2] are blank as well, so a serializer that writes into either gap fails. 8/8 in that file pass.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

This PR renders untrusted .docx content with docx-preview's default options, so renderAltChunks stays enabled and document-supplied HTML runs in an unsandboxed same-origin iframe. A crafted document can execute script on open inside the renderer, where the preload bridge exposes api/electron and the main renderer sets no CSP. The inline comment on OfficeDocumentViewer.tsx carries the details and a one-line fix — please treat it as a merge blocker.

Reviewed changes

  • Shared classification + read path — new SPREADSHEET_FILE_MIME_TYPES / OFFICE_DOCUMENT_FILE_MIME_TYPES maps plus a shared resolvePreviewableBinaryMime; the single-shot IPC, streamed relay, and preload read paths now emit isSpreadsheet / isOfficeDocument alongside base64 content.
  • Binary write path — fs:writeFile gains encoding: 'base64'; local writes use Buffer, SSH writes use provider.writeFileBase64, base64 saves bypass editorDrafts, and remote-runtime writes throw.
  • Renderer surfaces — lazy SpreadsheetFileSurface + EditableSheetGrid (editable grid with sheet tabs and Save for xlsx; CSV through the normal text-draft/autosave path) and a read-only OfficeDocumentViewer for .docx.
  • Shared xlsx codec — excel-xlsx.ts parses/serializes via exceljs without the global Buffer, with unit tests for parse/serialize, CSV serialization, and the classification helper.

ℹ️ Saving an .xlsx silently strips formulas, formatting, and merged cells

The grid round-trips only cell values: normalizeCellValue reads the cached formula result and serializeXlsxWorkbook writes plain values. A user who opens a real workbook, edits one cell, and clicks Save therefore destroys every formula, style, and merged-cell layout in the file with no warning. The PR description and the excel-xlsx.ts header both disclose this, but the Save affordance itself gives no signal that it is lossy.

Technical details
# Lossy `.xlsx` save with no user warning

## Affected sites
- `src/shared/spreadsheet/excel-xlsx.ts` — parse keeps only the cached formula result; serialize writes plain values, dropping formulas/styles/merges.
- `src/renderer/src/components/editor/SpreadsheetFileSurface.tsx:298` — the grid exposes an unconditional Save button.

## Required outcome
- Decide whether a destructive first save is acceptable. If not, warn/confirm before writing a workbook that contained formulas or formatting, or preserve unsupported parts by re-writing only edited cells into the original package.

## Open questions for the human
- Is value-only xlsx round-tripping an intentional long-term contract for this surface, or a v1 limitation that should be surfaced in the UI?

ℹ️ Nitpicks

  • No automated test exercises the edit → save → reload round-trip for either grid, nor the .docx render path; the new tests cover only parse/serialize and classification.
  • CsvViewer is no longer referenced by EditorEditFileSurface but is still exported from editor-lazy-views.ts, leaving a dead export.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

The data-integrity fixes in 71b3e55a18 and 5612e02212 are correct, but the untrusted-.docx execution path flagged in the previous review is still untouched: OfficeDocumentViewer continues to call renderAsync with docx-preview defaults, so renderAltChunks stays enabled and a crafted document runs script on open in the unsandboxed same-origin iframe. The existing inline comment carries the one-line fix (renderAltChunks: false); please address it before merging.

Reviewed changes since e4ba7a1

  • CSV delimiter round-trip — LoadState now carries the delimiter detected at load; kindDelimiter/empty-content re-sniffing is gone, so a tab-delimited .csv stays tab-delimited on edit and save.
  • CSV numeric fidelity — buildPatchRows stores the raw edited string instead of parseCellValue, so 00123/1.50 no longer normalize (and no longer reset the caret via CellInput's value effect).
  • .xls declassified — removed from SPREADSHEET_FILE_MIME_TYPES, since exceljs has no BIFF reader and the file would otherwise open as an empty sheet that could be saved over.
  • xlsx blank rows / rich text / errors — parseXlsxWorkbook walks the full row range (blank rows no longer shift later rows) and normalizeCellValue handles richText runs and #DIV/0!-style .error values.
  • Save durability — the grid tracks a revision so an edit during an in-flight xlsx write keeps the tab dirty; editor-save-queue.test.ts pins base64-vs-text content selection and the new editor-save-queue.ts branch.
  • External-change banner — the spreadsheet surface now renders ExternalFileChangeBanner like the other editor tabs.

The previously-flagged .xls, CSV-delimiter, and CSV-numeric findings are all resolved by these commits; the new tests cover the blank-row and rich-text/error cases with exact assertions.

Pullfrog  | Fix it ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

docx-preview renders `w:altChunk` HTML parts into an unsandboxed same-origin
iframe (its `renderAltChunks` defaults on) and copies relationship targets into
`href` verbatim, so a crafted .docx could run script on open inside the
renderer, where the preload bridge is exposed.

- pass `renderAltChunks: false` to `renderAsync`
- after render, drop `href` values whose scheme is not http(s)/mailto; leading
  C0 control characters are stripped first so `\tjavascript:` cannot slip past
- unit tests cover the scheme allow-list
@excellence-wh

Copy link
Copy Markdown
Author

Thanks — addressing each:

Security (.docx → script execution on open) — fixed in 2257fb9.

  • renderAsync now passes renderAltChunks: false, so document-supplied HTML is not rendered into an iframe at all.
  • After render we walk a[href] and drop any absolute target whose scheme is not http/https/mailto; leading C0 control characters are stripped first, so \tjavascript: is still treated as absolute and rejected. Relative/fragment links are left alone.
  • Unit tests cover the allow-list (incl. javascript:, data:, vbscript:, file: and the leading-control-char variants).
  • Noted on CSP as defence in depth — happy to follow up separately if the maintainers want a renderer CSP, but that's a broader change than this PR.

The three other inline findings were already fixed in 71b3e55 (your review was written against e4ba7a1):

  • .xls removed from SPREADSHEET_FILE_MIME_TYPES (no BIFF reader).
  • CSV re-serializes with the delimiter detected at load time, not re-derived from an empty string.
  • CSV edits keep the raw string; numeric coercion no longer rewrites 007/1.50.

Lossy .xlsx save — this is a deliberate v1 contract: the surface round-trips cell values only, and the PR description plus the excel-xlsx.ts header say so. I agree the Save affordance itself gives no signal. If you'd like, I can add a one-time inline note next to Save (e.g. "Saves values only — formulas and formatting are not preserved"); say the word and I'll include it rather than guess at the maintainers' preference.

Test coverage nitpick — the grid's edit→save→reload path is covered indirectly (parse/serialize round-trip including blank rows, plus the save-queue encoding test); a full renderer-level grid test isn't practical in this environment (component tests here run through renderToStaticMarkup). Happy to add one if you can point at an existing pattern for interactive grid tests in this repo.

CsvViewer — it is still referenced by EditorContent.markdown-classification.test.tsx, so I left the export in place rather than delete a component a test depends on.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/runtime/runtime-file-mutation-client.ts (1)

51-55: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use files.writeBase64 for base64 saves on runtime environments.

When an active runtime environment owns the worktree, XLSX saves reach this guard, throw, and show the user “Failed to save the spreadsheet.” The runtime RPC already exposes files.writeBase64; dispatch the encoded payload through that method. Direct SSH routes correctly bypass this guard and use the filesystem provider’s writeFileBase64 path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a82bf66e-f0d0-4857-97cf-4ab46b4f6e55

📥 Commits

Reviewing files that changed from the base of the PR and between 5612e02 and 2257fb9.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/OfficeDocumentViewer.test.ts
  • src/renderer/src/components/editor/OfficeDocumentViewer.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

A base64 (binary workbook) save on a worktree owned by a remote runtime
environment hit the text-only guard and threw, so the user saw "Failed to save
the spreadsheet". Route the payload through the runtime's existing
`files.writeBase64` mutation; direct SSH already used the filesystem provider's
`writeFileBase64`.

Tests pin base64 -> files.writeBase64 and text -> files.write routing.
@excellence-wh

Copy link
Copy Markdown
Author

Fixed in ae02dc1 — thanks, good catch.

writeRuntimeFile no longer throws for encoding === 'base64' on a runtime-owned worktree: it now dispatches through the runtime's existing files.writeBase64 mutation ({ worktree, relativePath, contentBase64 } plus the same SSH expectation fields, 30s timeout), mirroring writeRuntimeBase64File in the upload client. I verified the method is implemented on both sides before wiring it (files-mutation-methods.ts → runtime.writeFileExplorerFileBase64), and direct SSH already used the filesystem provider's writeFileBase64, so the two paths are now consistent.

New test pins the routing: base64 → files.writeBase64 (with contentBase64), text → files.write.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

2257fb9 closes the altChunk auto-execution path, but the hyperlink sanitizer added alongside it can be bypassed. Browsers remove ASCII tab/newline from a URL anywhere in the input, while isSafeLinkTarget only strips leading control characters, so a .docx relationship target of jav\tascript:alert(1) survives sanitization and resolves to javascript:alert(1) when clicked. The one-line fix is inline.

Reviewed changes

  • Disabled docx-preview altChunks — renderAltChunks: false removes the unsandboxed srcdoc iframe that let a crafted document run script on open.
  • Added hyperlink sanitization — sanitizeLinkTargets walks the rendered anchors and strips any target whose scheme is not http/https/mailto via the new exported isSafeLinkTarget.
  • Added unit tests — OfficeDocumentViewer.test.ts covers script-capable schemes, allowed schemes, and relative/fragment links.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new files.writeBase64 routing sends runtime spreadsheet saves into the host's create-only base64 writer, so editing an existing .xlsx and saving on a runtime environment fails with EEXIST. The added test asserts only which method is chosen, so it passes while the actual overwrite path is broken.

Reviewed changes since 2257fb9

  • Routed base64 saves through the runtime RPC — writeRuntimeFile now dispatches encoding: 'base64' payloads to files.writeBase64 instead of throwing "not supported yet" (the behavior CodeRabbit flagged on runtime-file-mutation-client.ts).
  • Added a dispatch test — runtime-file-mutation-client.test.ts pins base64 → files.writeBase64 with contentBase64, and text → files.write, for a remote runtime context.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Saving an existing .xlsx failed with EEXIST whenever the write landed on a
create-only base64 writer: the runtime host resolved its own worktree to local
and took writeFile(..., { flag: 'wx' }), and the SSH provider's writeFileBase64
mapped to SFTP `exclusive`. Both call sites serve saves as well as upload
staging, so the binary path contradicted the text path, which overwrites.

Create-only stays the default and saves opt in:

- `FileBase64WriteOptions { overwrite }` on IFilesystemProvider's
  writeFileBase64/writeFileBase64Chunk, honoured by the SSH provider as
  `exclusive: !append && !overwrite`.
- writeFileExplorerFileBase64(-Chunk) passes overwrite, so uploads to a unique
  staging name keep their semantics and the no-clobber guarantee stays where it
  belongs, at commitFileExplorerUpload (COPYFILE_EXCL / provider copy).
- fs:writeFile's SSH branch passes overwrite for base64, matching its text
  branch; the preload bridge now declares the `encoding` it already forwarded.

Tests write a real workbook twice and read it back, so the overwrite itself is
the assertion rather than the RPC method chosen; the chunked staging write still
replaces on the first chunk and appends after.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in this commit — the base64 overwrite fix is clean. One earlier concern remains open: the isSafeLinkTarget embedded-tab bypass in OfficeDocumentViewer.tsx is untouched here and still needs its one-line normalization fix before merge.

Reviewed changes

  • Overwrite-capable base64 writes — FileBase64WriteOptions { overwrite } added to IFilesystemProvider.writeFileBase64/writeFileBase64Chunk; the SSH provider derives exclusive = !append && !overwrite, so create-only stays the default.
  • Saves opt in — runtime writeFileExplorerFileBase64/-Chunk pass overwrite for saves and the local branch drops wx for w/a, matching the text write above it.
  • Upload staging stays safe — staging writes keep their unique .orca-upload-<nonce> / .incoming-<transferId> temp names, and no-clobber remains at commitFileExplorerUpload (COPYFILE_EXCL / provider copy), so relaxing the write flag does not let an upload clobber a real file.
  • Direct SSH save path — fs:writeFile's base64 branch now passes overwrite: true, matching its text branch; the preload bridge declares the encoding it already forwarded.
  • Tests — SFTP-flag mapping for the SSH provider, plus a runtime double-write that reads the workbook back, so the overwrite itself is the assertion rather than the RPC method chosen.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…them

`isSafeLinkTarget` trimmed only leading control characters, so a relationship
target with a tab, LF or CR inside the scheme (`java\tscript:alert(1)`) matched
no scheme pattern and passed as a relative link, while the URL parser removes
those characters from anywhere in its input and resolves it to `javascript:` —
the anchor docx-preview renders would have run on click.

Normalize tab/LF/CR out before reading the scheme, and assert the embedded-tab
and embedded-CR spellings (of javascript: and data:) alongside the existing
leading-whitespace cases.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior review (8b215b3), the single follow-up commit da9684d9a4 closes the last open security thread:

  • Normalized link targets the way the URL parser does — isSafeLinkTarget now strips ASCII tab/LF/CR from the whole string (href.replace(/[\t\n\r]/g, '')) before the leading-whitespace skip and scheme regex, so java\tscript:alert(1) resolves to javascript: and is rejected instead of passing on the raw attribute.

  • Added regression tests — OfficeDocumentViewer.test.ts now asserts java\tscript:, java\nscript:, jav\rascript:, and da\tta: are rejected, alongside the existing leading-control-char and allowed-scheme cases.

All prior Pullfrog review threads are now resolved. The remaining informational notes (lossy value-only .xlsx round-trip, remote-runtime orcad preview not classifying Office files) are disclosed scope decisions, not merge blockers.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

The changed-code quality gate failed on SpreadsheetFileSurface.tsx: a
side-effecting call ran inside the setLoad updater (React may invoke an updater
more than once, so the previous workbook must not be mutated), and the sheet tabs
used an array index in their key.

Move the cell write into spreadsheet-cell-edit.ts as setSpreadsheetCell, which
returns a new workbook and leaves the one it was given untouched, and key the
tabs by sheet name. Coercion and row/column growth are unchanged, and the CSV
path still stores raw text. The extracted helper carries the unit tests the
inline version could not: immutability, growth, per-sheet targeting, and the
numeric-versus-text boundary.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior review (da9684d9a4), the single new commit e7bf4e42e0 is a behavior-preserving refactor:

  • Extracted the cell-edit logic into spreadsheet-cell-edit.ts — setSpreadsheetCell, cloneSpreadsheetData, and parseSpreadsheetCellValue now live in a standalone module, so the xlsx setLoad updater and CSV buildPatchRows share one pure clone-and-write path.
  • Added spreadsheet-cell-edit.test.ts — 7 exact-assertion tests pin input-workbook immutability, out-of-extent growth, per-sheet targeting, deep row copies, and numeric/text coercion.
  • Simplified the sheet-tab key — SpreadsheetToolbar keys on sheet.name alone; still unique for real .xlsx and the single-sheet CSV path.

The extraction is genuinely behavior-preserving: the old setLoad updater already cloned (cloneData) before mutating, so this commit moves that logic rather than fixing it. The new tests pass locally (pnpm test src/renderer/src/components/editor/spreadsheet-cell-edit.test.ts — 7 passed). All prior review threads remain resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: open spreadsheets and Word documents (xlsx/csv editable, docx preview)

1 participant