Skip to content

feat(factscribe): re-vendored package, CRLF draft fix, and Python probe fix - #174

Merged
MyPrototypeWhat merged 2 commits into
MiniMax-AI:mainfrom
UncleMoc:feature/factscribe-revendor-20260127
Nov 28, 2026
Merged

MyPrototypeWhat merged 2 commits into
MiniMax-AI:mainfrom
UncleMoc:feature/factscribe-revendor-20260127

Conversation

@UncleMoc

@UncleMoc UncleMoc commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

FactScribe — re-vendored package, CRLF draft fix, and probe fix

What this package is

A local paper workbench. The Mini App opens the manuscript projects on your machine, shows the
check report, the fact ledger and the knowledge base, and lets the assistant propose edits that
you approve before anything reaches the file. Numbers and citations stay pinned to the ledger —
the AI proposes, you decide.

What this PR does

It re-vendors the package from the FactScribe repository, so the published package contains the
engine and the front end that the repository actually ships today.

Base note. This branch is based on the current main of this repository
(6f01a0f). The plugins/unclemoc/factscribe/ directory is byte-for-byte identical
to the state that #160 left it in (be73247c) — the commits that landed on main after
#160 touch only the minimax-bot and minimax-pet plugins. No rebase was needed and the
file-level diff below is therefore the same one that was prepared against #160.

Concretely:

  • miniapp/node/engine/factscribe/** is a byte-for-byte copy of the repository's factscribe/
    directory. It is generated — please do not hand-edit it in review comments; tell us what to
    change in the repository source and we re-vendor.
  • miniapp/client/** is a copy of factscribe/workbench/static/, so the two front ends cannot
    drift apart any more.

Because the engine moved on, this PR also carries a few user-visible fixes:

1. The Python probe waits for the pipe to close

The version probe decided "this is not a usable Python" in the child's exit event. Node's exit
only means "the process exited" — it does not guarantee that the bytes in the pipe have reached
the parent. On a busy machine (a CI runner with five matrices in parallel, for example) exit
arrives before the data event, the captured output is still empty, and a perfectly good
interpreter is reported as broken.

The decision now happens in the close event ("process exited and stdout/stderr drained").
The four possible states (ready / old / missing / broken) and all wording are unchanged — only the
moment of the judgement moved.

2. The front end moves to the paragraph level

Three capabilities that used to live in the retired section-level web front end now live in the
paragraph-level front end this package ships:

  • adding and removing citations,
  • previewing images,
  • installing the sample paper.

3. Line endings survive a save — and #160's draft regression is undone

This one deserves a note, because it partly reverts part of #160.

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 without a second step every save
rewrites the whole file with LF endings — a CRLF manuscript loses all its CR bytes on the first
edit. The Node shell added in #160 handles this from the outside: it reads the real endings from
the file on disk before the save, hands the engine an LF-only body, and puts the original endings
back afterwards.

#160 also changed the AI draft block insertion back to a hardcoded "\n" — the engine's own
line-ending handling was dropped for that path. In workbench/write.py, #160's
_draft_insertion builds the block with "\n".join(lines) and wraps it in "\n" + region + "\n".
As a result, inserting an AI draft into a CRLF manuscript left a run of LF lines inside a CRLF file.
This PR restores the behaviour that was there before: the draft block is written with the
dominant line ending of the file it goes into — eol = dominant_newline(source), and the
block itself goes through the same restore_newlines call that every other write path in that
file already used.

Both layers are kept, and they were measured against each other rather than assumed to agree:
the same nine scenarios (CRLF / LF / mixed-ending manuscripts, each saved with and without a
content change, plus an AI draft insertion) were run with the shell pass enabled and disabled, and
the resulting bytes compared. In eight of the nine the two are byte-identical; in the ninth the
shell pass is the one that keeps the untouched line's original ending. No case produces a doubled
\r\r\n, and no LF manuscript is turned into CRLF.

Measured on the vendored sample paper, inserting an AI draft into a CRLF manuscript:

before after
this PR 678 bytes, 11 CRLF, 0 lone LF 818 bytes, 18 CRLF, 0 lone LF
#160 as merged 678 bytes, 11 CRLF, 0 lone LF 811 bytes, 11 CRLF, 7 lone LF

(The byte totals include the inserted draft text; the CRLF / lone-LF counts are the part that does
not move with the wording of the draft. The draft block itself is 5 CRLF lines here and 5 lone LF
lines in #160, and outside the inserted block the file is byte-for-byte what it was.)

This is not a claim about a reading — it is locked by a regression test. The same test file
(tests/save-draft-eol.test.mjs, added by this PR) fails against #160's engine and passes
against this one:

# against this branch
✔ CRLF 稿子插 AI 草稿:草稿块也是 CRLF,原正文逐字节不变
✔ LF 稿子插 AI 草稿:不会被改成 CRLF

# against #160 as merged, same test file, same assertions
✖ CRLF 稿子插 AI 草稿:草稿块也是 CRLF,原正文逐字节不变
  AssertionError: 全文不该出现落单的 LF
✔ LF 稿子插 AI 草稿:不会被改成 CRLF

4. Python 3.10 reads TOML with the same verdict as 3.11+

The bundled fallback parser for 3.10 was lenient: it accepted some malformed TOML that tomllib
rejects. The same broken file could then be "readable" on 3.10 and an error on 3.11+, which means
the audit verdict depended on the interpreter. The fallback now follows the standard library's
rules: the same input is accepted or rejected, and the values read are identical.

5. Smaller fixes carried along

  • symlinked fact ledgers that point outside the project are reported instead of being read
    silently; writes that would land outside the project root are refused; a symlink loop or a
    broken link is named explicitly;
  • the paragraph fingerprint and the write path use one line-ending basis;
  • the decision-code set is closed (ASSET_NOT_FOUND is registered);
  • the retired serve --ui entry point returns a plain 404 with one honest sentence instead of a
    500.

How this was verified

  • The package's own tests: node --test tests/*.test.mjs — 32 cases, all green, none skipped,
    on Node 20.20.2, 22.23.5 and 26.7.0. They are the line-ending unit tests, the end-to-end save
    tests (they start the vendored Python engine and save into a copy of the sample paper), the AI
    draft line-ending tests and the status-code passthrough tests.
  • The status-code passthrough was measured, not assumed: the shell's /api/* route is a byte-level
    reverse proxy (response.writeHead(res.statusCode) plus res.pipe(response)), so the engine's
    decision codes and error bodies reach the page unchanged. The tests pin that, including that a
    409 BLOCK_STALE stays a 409 and is not flattened into a 502.
  • The Python engine suites pass on Python 3.10, 3.11, 3.12, 3.13 and 3.14 (2605 core tests, 216
    integration tests).
  • Nothing in the audited behaviour moved: the golden file audit_findings_baseline.json is
    byte-for-byte identical to the one on main, and audit --json over all 27 sample projects
    (26 locked plus fixtures/legal-demo) is byte-for-byte identical to main, 27 out of 27.
  • The package contract self-check passes (125 files, 5.1 MiB, ASCII paths, no symlinks) and the
    vendored engine imports cleanly.
  • This repository's own gate was run against this exact package content:
    node scripts/validate.mjs reports plugins/unclemoc/factscribe: OK with no errors and no
    warnings, and node --test "test/**/*.test.mjs" passes 96 / 96.

Not verified

  • No end-to-end run on a real Windows host or on Linux. The Windows interpreter discovery is
    covered by unit tests, but the Windows candidate list is generated from the platform string
    (31 to 37 entries, depending on which environment variables are set), not measured on Windows.
  • The upstream CI has not been run on a real runner for this branch. The gate above was run
    locally against the same package content.

Files

  • miniapp/node/engine/factscribe/** — re-vendored engine (generated from the repository sources;
    the directory is a copy, not hand-edited code).
  • miniapp/client/** — front end (copy of the repository sources).
  • miniapp/node/python_discovery.mjs — the probe timing fix.
  • miniapp/tests/** — the package's own tests.
  • README.md, README.zh-CN.md — documentation.

47 files changed, +5853 / −560.

Note on the vendored directory

miniapp/node/engine/factscribe/ is a generated copy of the repository's factscribe/
directory. Please do not hand-edit it in review comments — tell us what to change in the repository
source and we re-vendor.


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

…be fix

Re-vendor plugins/unclemoc/factscribe/ from the FactScribe repository, so the
published package carries the engine and the front end that the repository
actually ships today.

- miniapp/node/engine/factscribe/** is a byte-for-byte copy of the repository's
  factscribe/ directory. It is generated: please do not hand-edit it in review
  comments, tell us what to change in the repository source and we re-vendor.
- miniapp/client/** is a copy of factscribe/workbench/static/, so the two front
  ends cannot drift apart any more.

Because the engine moved on, this PR also carries a few user-visible fixes:

- The Python probe now judges usability on the child's "close" event (the
  process exited and stdout/stderr are drained) instead of "exit", so a busy
  machine no longer reports a perfectly good interpreter as broken.
- The paragraph-level front end gains citation add/remove, image preview and
  the sample-paper install, formerly living in the retired section-level front
  end.
- Saving preserves the manuscript's original line endings end to end, and the
  AI draft block is written with the dominant line ending of the file it goes
  into instead of a hardcoded "\n" (this partly reverts MiniMax-AI#160; the behaviour is
  locked by a regression test that fails against MiniMax-AI#160's engine and passes
  here).
- The bundled Python 3.10 TOML fallback parser follows the standard library's
  rules, so the audit verdict no longer depends on the interpreter version.
- Symlinked fact ledgers that point outside the project are reported instead
  of being read silently, and writes that would land outside the project root
  are refused.

47 files changed, +5853 / -560.

Verified locally against this exact content: node scripts/validate.mjs reports
plugins/unclemoc/factscribe: OK with no errors and no warnings, and
node --test "test/**/*.test.mjs" passes 96/96.

Copy link
Copy Markdown
Collaborator

Thanks for the re-vendored FactScribe update. We re-checked on b41f117. This isn't a code blocker.

The manifest is still 1.2.0, but the contents are no longer the tree that landed in #160. Please bump this to 1.2.1, or the next patch version, before it is merged, so it doesn't share a release identity with that 1.2.0.

We also noted that the legal pages are not reachable on the Mini App paths. That isn't something we're asking you to change.

Package tests were 32/32 on this head. We have not run this on Host or Electron.

…ed engine

The package ships the 1.3.0 engine (factscribe/constants.py → VERSION = "1.3.0"),
but the manifest was left at 1.2.0 when the tree was re-vendored — so the
package advertised 1.2.0 while running a 1.3.0 engine. Bump the manifest to
1.3.0 so the published version matches what the package actually contains.

This also keeps the package off MiniMax-AI#160's release identity: that 1.2.0 shipped
an older engine tree, and the re-vendor replaced both the engine tree and the
front-end tree — a structural change, not a patch on top of 1.2.0.
@UncleMoc

Copy link
Copy Markdown
Contributor Author

Thanks for the review — bumped to 1.3.0, and here is the reasoning behind the number.

Why 1.3.0. The manifest version is meant to match the engine the package actually ships. This package contains the 1.3.0 engine — factscribe/constants.py has VERSION = "1.3.0", and python3 -m factscribe --version prints factscribe 1.3.0 both from the repo tree and from the vendored copy under miniapp/node/engine/. The manifest was left at 1.2.0 when we re-vendored the tree: we installed the new engine into the package but did not bump the package version along with it, which left the package advertising 1.2.0 while running a 1.3.0 engine. So 1.3.0 is not a deliberate version policy on our side — it is the version that was already in there, and leaving it at 1.2.0 was our own oversight.

That also answers your point about not sharing a release identity with #160: the 1.2.0 in #160 shipped an older engine tree, so 1.3.0 is genuinely different release content — not the same release under a second name. The plugin ID is unchanged and only version in plugin.json is raised, per the rule in AGENTS.md.

Version sequence. This package is the paper-side workbench. The legal-side workbench is planned to join the Mini App in a later version, so keeping this one at 1.3.0 leaves the package version sequence continuous for that release.

On the legal pages. Noted — and to be clear about the direction: the legal workbench is planned to join the Mini App paths in a later version. The read-side interfaces and the sample pages are already merged in our own repository's main; what this PR does not carry is only the Mini App path wiring itself, because this PR is focused on the full re-vendor plus the line-ending fix. When the legal side ships, it will come with the Mini App paths attached, so no separate change is needed on your side for that to work.

Package tests. Re-ran the package test suite on this head after the version bump: 32/32 pass, 0 fail, 0 skipped — unchanged from the run you did. The upstream npm run check job is green on this head as well.

The version change is one line in miniapp/.minimax-plugin/plugin.json; nothing else in the package was touched.

@MyPrototypeWhat
MyPrototypeWhat merged commit 7af6450 into MiniMax-AI:main Nov 28, 2026
2 checks passed
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.

2 participants