Skip to content

Run the main process on Cottontail; fix DOCX open and a startup crash - #32

Merged
GijungKim merged 3 commits into
mainfrom
cottontail-runtime
Aug 24, 2026
Merged

GijungKim merged 3 commits into
mainfrom
cottontail-runtime

Conversation

@GijungKim

Copy link
Copy Markdown
Owner

Summary

Ports the main process from Bun to Cottontail, Electrobun 2's JavaScriptCore runtime, and fixes two bugs found while verifying it — one pre-existing, one from #31.

1. fix: DOCX files failed to open (pre-existing, since the initial commit)

parseDocx passed { arrayBuffer } to Mammoth, but that option only exists in Mammoth's browser build. The Node build that gets bundled into the main process accepts { path | buffer | file } and rejects everything else with Could not find file in options — so every DOCX open threw, on Bun and Cottontail alike. Now passes { buffer: Buffer.from(arrayBuffer) } (a view, no copy).

2. fix: word-count selector crashed the UI before the editor mounted (regression from #31)

The useEditorState selector called editor.getText(), which reads editor.state/editor.schema — both unset until EditorContent mounts a view. On the welcome screen the selector runs first, threw, and the error boundary replaced the whole app. The selector now reads editor.state?.doc guardedly. Also removes the standalone @tiptap/extension-underline (StarterKit v3 already registers it; the duplicate logged a warning at startup).

3. feat: run the main process on Cottontail

build.mainProcess: "cottontail". Bun remains the dev tool (install/scripts/tests); src/bun/ keeps its name and its Bun.file/Bun.write calls, which Cottontail implements. README updated. .cottontail-tmp/ (Hutch scratch) added to .gitignore.

Verification

  • Headless: the real src/bun/fileParser.ts executed under the exact cottontail binary from the built bundle (SHA-matched to the Hutch store copy) — MuPDF opens an 8-page PDF and renders page 1 at 2× to a PNG data URL; Mammoth converts a DOCX with heading/bold/italic to HTML; Bun.file().arrayBuffer(), .exists(), Bun.write, and Buffer base64 round-trips all pass.
  • Dev app (electrobun build + run --env=dev) launches with a clean main-process log and no webview console errors (the first launch, before fix 2, showed the error-boundary crash).
  • bun test 38 pass, tsc --noEmit clean, vite build clean.
  • Not done: opening files through the GUI (my automation lacks Accessibility permission). Please open one PDF and one DOCX in the running dev app before merging.

Size (dev build, macOS arm64)

Bun Cottontail
.app on disk 79 MB 73 MB
runtime binary, raw 60.6 MB 55.2 MB
runtime binary, zipped 24.4 MB 20.9 MB

Smaller, but well short of Electrobun's ~15 MiB headline for a Cottontail hello-world — this is the --env=dev build, and the remaining bulk is the runtime binary itself (ICU etc.). Worth re-measuring build:stable before drawing conclusions.

https://claude.ai/code/session_01Y1BX9DkxUarJzFn2oVp12k

parseDocx passed { arrayBuffer } to mammoth.convertToHtml, but that
option only exists in Mammoth's browser build. The Node build bundled
into the main process reads { path | buffer | file } and rejects
anything else with "Could not find file in options", so every DOCX
open threw. Pass { buffer } instead (a Buffer view over the same
ArrayBuffer — no copy).

Claude-Session: https://claude.ai/code/session_01Y1BX9DkxUarJzFn2oVp12k
The useEditorState selector added in #31 called editor.getText(), which
dereferences editor.state / editor.schema — both unset until
EditorContent mounts a view. On the welcome screen the selector runs
first, threw, and the error boundary took over the whole app. Read
editor.state?.doc guardedly and count words from textBetween instead.

Also drop the standalone @tiptap/extension-underline: StarterKit v3
already registers underline, and the duplicate logged a TipTap warning
at startup.

Claude-Session: https://claude.ai/code/session_01Y1BX9DkxUarJzFn2oVp12k
Switch build.mainProcess to "cottontail", Electrobun 2's JavaScriptCore
runtime, so the packaged app no longer ships the Bun binary. Bun stays
the dev tool (install, scripts, tests); src/bun/ keeps its name and its
Bun.file/Bun.write calls, which Cottontail implements.

Verified with the real src/bun/fileParser.ts under the exact cottontail
binary that ships in the bundle: MuPDF WASM renders pages, Mammoth
parses DOCX, Bun.file/Bun.write/Buffer all behave. The dev app launches
with a clean main-process and webview log.

Size (dev build, macOS arm64): 79 MB -> 73 MB on disk; the runtime
binary is 60.6 MB -> 55.2 MB raw, 24.4 MB -> 20.9 MB zipped.

Also ignore .cottontail-tmp/, Hutch's scratch directory.

Claude-Session: https://claude.ai/code/session_01Y1BX9DkxUarJzFn2oVp12k
@GijungKim
GijungKim merged commit 7e48f76 into main Aug 24, 2026
1 check passed
@GijungKim
GijungKim deleted the cottontail-runtime branch August 24, 2026 11:47
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.

1 participant