Skip to content

fix(factscribe): find Python on Windows, keep CRLF line endings on save - #160

Open
UncleMoc wants to merge 2 commits into
MiniMax-AI:mainfrom
UncleMoc:feature/factscribe-windows-and-eol
Open

UncleMoc wants to merge 2 commits into
MiniMax-AI:mainfrom
UncleMoc:feature/factscribe-windows-and-eol

Conversation

@UncleMoc

@UncleMoc UncleMoc commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Two fixes for the FactScribe Paper Workbench package: on Windows the Mini App can now find the Python interpreter the machine already has, and saving a manuscript no longer rewrites its line endings. The vendored Python engine has been upgraded to a newline-faithful build as well, so the engine itself keeps the file's own line endings instead of leaving that to the Node shell to put back afterwards.

Written by MiniMax Code (MCode)

Windows interpreter discovery

The candidate list had no Windows shape at all — no py launcher, no versioned command, no common install directory — and a failed probe was collapsed into "not installed". A user with Python 3.9 on the machine was told to "install Python >=3.10", with nothing they could act on.

  • New miniapp/node/python_discovery.mjs. Candidates are now {command, args} pairs and cover py, py -3, py -3.10 … py -3.14, py.exe, the versioned commands, python.exe, and absolute paths under %LOCALAPPDATA%, %PROGRAMFILES% and C:\Python3xx — 36 candidates on Windows. The macOS/Linux list is unchanged, word for word.
  • The probe classifies the outcome: version high enough / version too low / command missing / command present but the version cannot be read. The message therefore names the version it found and the executable it came from.
  • Discovery and engine start share one "command + prefix arguments" pair, so py -3 starts the engine too, not only the probe.
  • The settings page and the engine start failure now share one message, which distinguishes: nothing installed / installed but older than 3.10 (3.9 and below cannot run this engine) / installed but not on PATH (point FS_PYTHON at it) / a Microsoft Store placeholder alias that cannot report its version.

The requirement itself is unchanged: the engine needs Python >= 3.10.

Browser-layer CRLF preservation

The engine used to read sections with Python's universal-newline mode — CRLF became LF before the text ever reached the page — and wrote the file back byte for byte. Every save therefore rewrote the whole file with LF endings, so a CRLF manuscript lost all its CR bytes on the first edit. The browser layer is the first line of defence and stays.

  • New miniapp/node/eol.mjs: split the text with the endings kept apart, recognise crlf / lf / mixed, and put the original endings back.
  • The Node shell reads the real endings from the file on disk before the save, hands the engine an LF-only body, and restores the endings afterwards. Lines the save did not touch keep their exact endings (a file with mixed endings stays mixed), the edited lines take the file's dominant ending, and the text itself is never altered — only the endings move. If the file changed underneath while the save ran, the endings are left alone instead of overwriting someone else's work.

The vendored Python engine keeps line endings too

The package ships a copy of the Python engine under miniapp/node/engine/, and that copy was still the older build. It read user files in universal-newline mode, so a CRLF file was already LF by the time the text reached the page, and it wrote several user-owned files in platform default text mode, where a CRLF string is written as \r\r\n on Windows. The Node shell puts the endings back after each save, so the file on disk looked right — but the engine had already lost the endings, and the Node layer can only repair a file whose line contents still match.

The vendored engine has been re-vendored from the engine source tree:

  • New factscribe/textio.py: read_text_exact / write_text_exact / append_text_exact read and write with the file's own line endings — no universal-newline translation on the way in, no platform translation on the way out — and to_lf gives the analysis layer one explicit place where line endings are normalised in memory. Machine-generated artefacts (JSON reports, audit matrices, manifests) keep the platform default, so their format stays predictable.
  • The read side of the manuscript, fact ledger, glossary and workbench paths now uses read_text_exact; the write side uses write_text_exact.
  • The vendored tree is generated by the engine repository's miniapp/build.sh and is byte-identical to the source tree apart from the excluded web/ directory.

Tested environment and results

  • MiniMax Code 3.1.16 on macOS 26.6.2 (arm64); Node 26.7; Python 3.14.
  • Upstream checker: plugins/unclemoc/factscribe: OK — 0 errors, 0 warnings. npm run check exits 0 (92/92 checker self-tests).
  • Package tests: node --test tests/*.test.mjs — 19 cases, all green (16 unit cases for the line-ending module, plus 3 end-to-end cases that start the vendored Python engine and save into a copy of the sample paper).
  • The engine's own Python test suite (2399 cases and 397 subtests, all green on Python 3.14) passes against the vendored copy inside this package.
  • Measured on the vendored sample paper, saving through this package's own write path:
    • a CRLF section — 678 bytes, 11 CRLF endings — came back as 678 bytes with 11 CRLF endings, the same sha256 and the same text;
    • an LF section — 667 bytes, 11 LF endings — came back byte-identical, with no CRLF introduced;
    • a mixed section — 668 bytes, 1 CRLF + 10 LF — came back byte-identical, still mixed, not unified.
  • The same three saves with the previous engine needed the Node layer to repair the file afterwards (repaired: 1 for the CRLF file and for the mixed file); with the new engine the engine's own write is already faithful and nothing has to be repaired.
  • At the engine level: reading a CRLF file with the previous code returned line1\nline2\n; the new read_text_exact returns line1\r\nline2\r\n.

What was not verified

  • Windows, end to end. There is no Windows machine here. The 36 Windows candidates are generated from the platform string and are covered by unit tests, but no run on a real Windows host has been done.
  • Linux hosts, as before: the package ships no platform-specific binary and the Node entry uses only Node built-ins, but nothing has been run on Linux.
  • Passing on macOS does not mean passing on Windows. On POSIX the platform default text mode is the identity when writing (\n stays \n), so the write-side corruption cannot be observed on this machine at all; only the read side is observable here. The write-side claim rests on Python's documented Windows text-mode behaviour, not on a measurement taken on a Windows host.

npm run check warnings

None — the package reports 0 errors and 0 warnings, so there is nothing to explain.

Access and minimum client version

No new access is declared, and the minimum client version is unchanged at 3.1.2. plugin.json moves from 1.1.0 to 1.2.0.


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

UncleMoc added 2 commits November 25, 2026 19:11
Two fixes: one for Windows machines, one for manuscripts that use CRLF.

1. Windows interpreter discovery

   The candidate list had no Windows shape at all -- no "py" launcher, no
   versioned command, no common install directory -- and a failed probe was
   collapsed into "not installed". A user with Python 3.9 on the machine was
   told to "install Python >=3.10", with nothing to act on.

   - new miniapp/node/python_discovery.mjs: candidates are {command, args}
     and cover py, py -3, py -3.10 ... py -3.14, py.exe, versioned commands,
     python.exe and absolute paths under %LOCALAPPDATA%, %PROGRAMFILES% and
     C:\Python3xx -- 36 candidates on Windows. The macOS/Linux list is
     unchanged, word for word.
   - the probe classifies the outcome: version high enough / too low /
     command missing / present but the version cannot be read. The message
     therefore names the version it found and the executable it came from.
   - discovery and engine start share one "command + prefix arguments" pair,
     so "py -3" is used for both, not only for probing.
   - the settings page and the engine start failure share one message:
     not installed / too old (3.9 and below cannot run this engine) /
     installed but not on PATH (point FS_PYTHON at it) / Microsoft Store
     placeholder alias that cannot report its version.

   The requirement is unchanged: the engine needs Python >= 3.10.

2. Browser-layer CRLF preservation

   The engine reads sections with Python's universal-newline mode (CRLF
   becomes LF before the text ever reaches the page) and writes the file
   back byte for byte, so every save rewrote the whole file with LF
   endings -- a CRLF manuscript lost all its CR bytes on the first edit.

   - new miniapp/node/eol.mjs: split with the endings kept apart, recognise
     crlf / lf / mixed, put the original endings back.
   - the Node shell reads the real endings from disk before the save, hands
     the engine an LF-only body and restores the endings afterwards: lines
     the save did not touch keep their exact endings (a mixed file stays
     mixed), the edited lines take the file's dominant ending, and the text
     is never altered -- only the endings move. If the file changed
     underneath while the save ran, the endings are left alone.

The vendored Python engine is untouched by both changes.

Verified:
- upstream checker: plugins/unclemoc/factscribe OK (0 errors, 0 warnings);
  npm run check exits 0 (92/92 checker self-tests).
- package tests: node --test tests/*.test.mjs -- 19 cases, all green
  (16 unit cases for the line-ending module, plus 3 end-to-end cases that
  start the vendored Python engine and save into a copy of the sample
  paper).
- measured on the vendored sample paper: a 678-byte section with 11 CRLF
  endings came back with all 11 endings and the same text; without the fix
  the engine's own save rewrote it as 667 bytes with 0 CRLF.

Not verified:
- Windows end to end. There is no Windows machine here. The 36 Windows
  candidates are generated from the platform string and covered by unit
  tests, but no run on a real Windows host has been done.
- Linux hosts, as before.
…ackage

The vendored copy of the Python engine in this package predates the
newline-fidelity work. It read user files in universal-newline mode, so a
CRLF file was already LF by the time the text reached the page, and it
wrote several user-owned files in platform default text mode, where a CRLF
string is written as \r\r\n on Windows. The Node shell restored the
endings after each save, but the engine itself still lost them, and the
Node layer can only put a file back when its line contents still match.

Re-vendor the engine from the FactScribe source tree, which now carries
the newline-fidelity work:

- new factscribe/textio.py: read_text_exact / write_text_exact /
  append_text_exact keep the file's own line endings, and to_lf gives the
  analysis layer an explicit normalisation point;
- the read side uses read_text_exact, the write side write_text_exact;
- machine-generated artefacts (JSON reports, audit matrices, manifests)
  keep using the platform default, so their format stays predictable.

The vendored tree is produced by miniapp/build.sh and is byte-identical to
the source tree apart from the excluded web/ directory.

Measured on the vendored sample paper, saving through this package: a
678-byte section with 11 CRLF endings came back as 678 bytes with 11 CRLF
endings and the same sha256; the LF file (667 bytes, 11 LF) and the mixed
file (668 bytes, 1 CRLF + 10 LF) came back byte-identical. With the
previous engine the Node layer had to repair the file after every CRLF and
mixed save; with this engine the engine's own write is already faithful.

Not verified: Windows end to end, and Linux.
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