Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/unclemoc/factscribe/.minimax-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"name": "factscribe",
"displayName": "FactScribe 论文工作台",
"version": "1.1.0",
"version": "1.2.0",
"description": "A local workbench for writing papers: open your manuscript projects, read the check report, the fact ledger and the knowledge base, and let the assistant propose edits you approve before anything reaches the file. Numbers and citations stay pinned to the ledger; the AI proposes, you decide.",
"author": "UncleMoc · BGISMALL",
"icon": "icon.png",
Expand Down
49 changes: 43 additions & 6 deletions plugins/unclemoc/factscribe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,52 @@ Code and ask the Agent to "Open the FactScribe paper workbench".
MiniMax Code 3.1.11 and later can also import the package straight from a Git repository: paste the
repository URL, pick the package directory, and confirm the preview.

### Python interpreter (the machine needs ≥3.10)

The engine is written in Python. Its source is vendored into the package, so there is nothing to `pip install`, but the machine still needs a **Python ≥3.10** interpreter. The Mini App looks for one in PATH and in the usual install locations, and the settings page states what it found, what is missing and whether the version is high enough.

**Windows**: download the 3.10 or newer installer from <https://www.python.org/downloads/windows/> and tick **Add python.exe to PATH**; open a fresh command prompt afterwards and run `py -3 --version` to confirm. A `py` launcher on its own is enough (the Mini App tries `py`, `py -3`, `py -3.14` down to `py -3.10`). An interpreter outside PATH is found too: `%LOCALAPPDATA%\Programs\Python\Python3xx\`, `%PROGRAMFILES%\Python3xx\` and `C:\Python3xx\` are all probed. If it still finds nothing, point the `FS_PYTHON` environment variable at the absolute path and restart MiniMax Code.

**Why 3.9 does not work**: the engine needs ≥3.10 (on 3.10 it falls back to the TOML parser bundled with the package, on 3.11 and newer it uses the standard library `tomllib`), so Python 3.9 and older cannot run this engine. The Mini App therefore reports the highest version it found (3.9) and which executable it came from. An old version can stay installed next to 3.10 or newer.

**macOS / Linux**: unchanged. The Mini App tries `python3`, `python`, `/usr/bin/python3`, `/opt/homebrew/bin/python3` and `/usr/local/bin/python3` in that order, and `FS_PYTHON` can point at an absolute path there too.

### Line endings

A save keeps the line endings your file already had. 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 therefore
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: 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 was running, the endings are left alone instead of being overwritten.

On first use the page asks for your paper root directory: any directory that contains a
`factscribe.toml` is treated as a paper project. It can be changed later from the settings page.

## Tested environment

- MiniMax Code 3.1.16 on macOS 26.6.2 (arm64). Installed from this directory, opened through the
Agent, page rendered, and all 17 MCP tools called end to end over the Host's MCP runtime.
- Node 26.7 and Python 3.14 on the same machine. The Python engine is vendored inside the
package, so nothing has to be installed.
- Node 26.7 and Python 3.14 on the same machine. The Python engine source is vendored inside the
package, so nothing has to be `pip install`ed; the machine still needs a Python ≥3.10
interpreter (see above).
- Minimum client version: 3.1.2. The package declares `agentAccess: ["session.run"]`, which
needs 3.1.2; no `engines` bound is declared, so clients from 3.1.2 on still install it and
only lose the assistant model picker when their client does not expose the model catalogue.
- Node 26.7 with the package's own 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 line-ending round trip was 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 the same file as 667 bytes with 0 CRLF endings — every CR byte lost.
- Not verified: Windows and Linux hosts. The package ships no platform-specific binary and the
Node entry uses only Node built-ins, but no run on those platforms has been done.
Node entry uses only Node built-ins, but no run on those platforms has been done. The Windows
interpreter discovery (`py` launcher, versioned commands, common install directories) is
covered by unit tests, but no end-to-end run on a real Windows machine has been done; the 36
Windows candidates are generated from the platform string, not measured on Windows.

## Data & access

Expand All @@ -72,13 +104,18 @@ On first use the page asks for your paper root directory: any directory that con
`proposals/` (proposal records) and `custom-models.json` (an API key you typed yourself, mode
0600). Inside your paper directory, only where you click: `sections/*.tex` (atomic write plus a
`.bak` copy, refused when the file changed underneath) and `facts/draft/` for imported drafts.
Opening a disk also records `last_opened` in that disk's `factscribe.toml`.
Opening a disk also records `last_opened` in that disk's `factscribe.toml`. Restoring the
original line endings after a save writes the same file again through a sibling temporary file
(`<name>.eol-tmp-<pid>`) and renames it over the original, so no extra file is left behind; the
temporary file is removed if the write fails.
- **Network hosts**: none by default. The Node service and the Python engine listen on loopback
only (`127.0.0.1`). If you add a custom model in the panel, the Node shell sends the prompt to
the OpenAI-compatible endpoint you typed; the host Agent turn is run by the Host on your
MiniMax Code account and plan.
- **Processes spawned**: `python3 -B -m factscribe workbench --root <your root> --port 0 --json
--no-browser` (the engine; killed when the Mini App stops), `factscribe audit` (read-only
- **Processes spawned**: `<interpreter> -B -m factscribe workbench --root <your root> --port 0 --json
--no-browser` (the engine; killed when the Mini App stops; the interpreter is the Python ≥3.10
the Mini App found on this machine, possibly `python3`, `py -3` or the absolute path named by
`FS_PYTHON`), `factscribe audit` (read-only
re-run of the check report), `tectonic` (only for the optional PDF render button) and macOS
`open` (only for the "open folder" button).
- **Agent turns**: the panel runs Host Agent turns through `agentAccess: ["session.run"]`. The
Expand Down
38 changes: 33 additions & 5 deletions plugins/unclemoc/factscribe/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,43 @@ FactScribe 把它们变成可核对的读数:

MiniMax Code 3.1.11 起也可以直接从 Git 仓库导入:贴仓库地址、选中包目录、核对预览即可。

### Python 解释器(本机要有 ≥3.10)

引擎是 Python 写的,源码随包 vendor,所以不用 `pip install` 任何东西;但**本机仍要有一个 Python ≥3.10 解释器**。Mini App 会自己在 PATH 与常见安装目录里找它,找到什么、缺什么、版本够不够,设置页都会写清楚。

**Windows**:到 <https://www.python.org/downloads/windows/> 下载 3.10 或更高版本的安装包,安装时勾上 **Add python.exe to PATH**;装完开一个新的命令行窗口跑 `py -3 --version` 确认。只装了 `py` 启动器也行(会依次试 `py`、`py -3`、`py -3.14` 到 `py -3.10`)。装在 PATH 之外也能找到:`%LOCALAPPDATA%\Programs\Python\Python3xx\`、`%PROGRAMFILES%\Python3xx\`、`C:\Python3xx\` 这些常见位置都会被探到;实在找不到就设环境变量 `FS_PYTHON` 指到解释器绝对路径,设完重启 MiniMax Code。

**为什么 3.9 不行**:引擎要求 ≥3.10(3.10 走随包的兜底 TOML 解析器,3.11 以上用标准库 `tomllib`),3.9 及以下跑不了这份引擎,所以 Mini App 会直接报出「探到的最高版本是 3.9」和它来自哪个可执行文件。旧版本可以和 3.10 以上并存,两个都装不冲突。

**macOS / Linux**:行为不变,按 `python3`、`python`、`/usr/bin/python3`、`/opt/homebrew/bin/python3`、`/usr/local/bin/python3` 的顺序找,`FS_PYTHON` 同样能指到绝对路径。

### 行尾保真

保存会保留文件原来的行尾。引擎读章节用 Python 的通用换行模式(CRLF 在到达页面前就变成
LF 了),写文件又是逐字节写回,所以没有第二道工序的话,**每保存一次整篇就被改成 LF 行尾**——
CRLF 的稿子一编辑就把 CR 全丢了。Node 薄壳因此在保存前先从磁盘读出原文件真正的行尾,
交给引擎的正文一律是 LF 形态,引擎写完再按原风格把行尾摆回去:这次保存没碰到的行连原来的
行尾都原样留着(混合行尾的稿子保存后仍是混合的),被改动的那几行走该文件的主导行尾,正文
一个字都不动——只有行尾在动。保存期间文件被别处改过,就不去动行尾,不覆盖别人的改动。

首次打开会让你填**论文根目录**:含 `factscribe.toml` 的目录会被当作论文项目,之后可在设置页改。

## 测试环境

- MiniMax Code 3.1.16,macOS 26.6.2(arm64)。从本目录安装、经助手打开、页面渲染正常,
17 个 MCP 工具在宿主 MCP 运行时上逐个实调通过。
- 同一台机器上的 Node 26.7 与 Python 3.14。Python 引擎已随包 vendor,不用装任何东西。
- 同一台机器上的 Node 26.7 与 Python 3.14。Python 引擎源码已随包 vendor,不用 `pip install` 任何东西;但本机仍需一个 Python ≥3.10 解释器(见上)。
- 最低客户端版本:3.1.2。本包声明 `agentAccess: ["session.run"]`(该能力需要 3.1.2);
没有声明 `engines` 下限,所以 3.1.2 起的客户端都能装,只是客户端不提供模型目录时
面板里少一个模型下拉。
- Node 26.7 与随包测试:`node --test tests/*.test.mjs` —— 19 例全绿(行尾模块 16 例
单测,加上 3 例真引擎端到端:拉起随包 Python 引擎,在样例盘副本上真存一次)。
- 行尾往返在随包样例盘上实测过:678 字节、11 个 CRLF 的章节文件,保存后 11 个 CRLF 一个不少、
正文一字不差;不修的话,引擎自己那次保存会把它写成 667 字节、0 个 CRLF——CR 全丢。
- **未验证**:Windows 与 Linux 宿主。包内没有平台专属二进制、Node 入口只用内置模块,
但没有在这两个平台上实跑过。
但没有在这两个平台上实跑过。Windows 上的解释器发现(`py` 启动器、版本化命令、
常见安装目录)有单元测试覆盖,但没有在 Windows 真机上端到端跑过;那 36 个 Windows
候选是按平台字符串生成的,不是在 Windows 上量出来的。

## 数据与访问

Expand All @@ -62,12 +87,15 @@ MiniMax Code 3.1.11 起也可以直接从 Git 仓库导入:贴仓库地址、
- **写入的文件**:插件私有 `dataDir`——`config.json`(论文根目录)、`proposals/`(提议单记录)、
`custom-models.json`(你自己填的 API Key,权限 0600)。你的论文目录里只有你点了才写:
`sections/*.tex`(原子写+留 `.bak`,文件被别处改过就拒写)与 `facts/draft/`(草稿导入)。
另外「打开」一个稿盘会在该盘的 `factscribe.toml` 里记 `last_opened`。
另外「打开」一个稿盘会在该盘的 `factscribe.toml` 里记 `last_opened`。保存后把原行尾摆回去时,
会先写同目录的临时文件(`<文件名>.eol-tmp-<pid>`)再改名盖回原文件,不会留下多余文件;
写失败时临时文件会被清掉。
- **网络 host**:默认没有。Node 服务与 Python 引擎只绑回环(`127.0.0.1`)。若你在面板里
自加自定义模型,Node 薄壳会把你填的 OpenAI 兼容端点当作目标;面板里的助手回合由宿主代跑,
走你在 MiniMax Code 上的账号与额度。
- **拉起的进程**:`python3 -B -m factscribe workbench --root <你的根目录> --port 0 --json
--no-browser`(引擎,MiniApp 停止时被杀)、`factscribe audit`(只读重跑检查报告)、
- **拉起的进程**:`<解释器> -B -m factscribe workbench --root <你的根目录> --port 0 --json
--no-browser`(引擎,MiniApp 停止时被杀;解释器是本机探到的那个 ≥3.10 的 Python,可能是
`python3`、`py -3`,也可能是 `FS_PYTHON` 指定的绝对路径)、`factscribe audit`(只读重跑检查报告)、
`tectonic`(只用于可选的 PDF 渲染按钮)、macOS `open`(只用于「打开目录」按钮)。
- **Agent 回合**:面板通过 `agentAccess: ["session.run"]` 跑宿主 Agent 回合,用的是 MiniMax Code
自己配的模型、宿主账号与额度;插件不读你的 API key、不读宿主配置。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .texrules import (adjacency_hits, arith_hits, display_hits,
fsignore_quant_hits, numeric_macro_hits,
tabular_regions)
from .textio import read_text_exact, split_lines, to_lf
from .texscan import (_balanced, _blank, _extract_numbers,
_merge_number_units, has_auditable_content, scan_tex,
sentence_index, sentence_spans, structural_whitelist)
Expand Down Expand Up @@ -334,7 +335,7 @@ def _source_text_keys(text: str) -> set[str]:


def _source_line(text: str, line: int) -> str:
lines = text.split("\n")
lines = split_lines(text)
return lines[line - 1] if 1 <= line <= len(lines) else ""


Expand Down Expand Up @@ -558,7 +559,7 @@ def verify_sources(cfg: Config, facts: list[Fact]) -> tuple[list[Issue], list[Is
continue
try:
digest = sha256_file(full)
texts[src] = full.read_text(encoding="utf-8")
texts[src] = to_lf(read_text_exact(full))
except (OSError, UnicodeDecodeError) as exc:
red.append(Issue("UNREADABLE_SOURCE", "fact %r 的 source 读不了:%s(%s)"
% (f.id, src, exc), location=loc, token=f.id, params={"fact": repr(f.id), "src": str(src), "detail": str(exc)}))
Expand Down Expand Up @@ -980,14 +981,17 @@ def _needs_scan(cfg: Config, rel: str) -> bool:
「未扫描」是噪声。读不了的文件照旧报(fail-closed)。
"""
try:
text = _read_text(cfg.root / rel, cfg.root)
text = to_lf(_read_text(cfg.root / rel, cfg.root))
except ConfigError:
return True
return has_auditable_content(text)


def run_audit(cfg: Config, facts: list[Fact], sections: list[tuple[str, str]],
resolve: bool = False):
# 分析入口归一行尾:读盘侧按原样读(CRLF 不丢),分析层按行做事;
# 归一的是内存副本,磁盘字节不动。
sections = [(rel, to_lf(text)) for rel, text in sections]
if not facts:
raise ConfigError("facts 为空(%s 没匹配到任何 fact)——空账不算通过" % cfg.facts_glob)
if not sections:
Expand Down Expand Up @@ -1354,7 +1358,8 @@ def _line_bound_quant(line_no: int) -> list[Fact]:
for key, line, col in scan.cites:
used_keys[key] = used_keys.get(key, 0) + 1
entry = bib_by_key.get(key)
line_text = text.split("\n")[line - 1].strip() if line - 1 < len(text.split("\n")) else ""
_lines = split_lines(text)
line_text = _lines[line - 1].strip() if line - 1 < len(_lines) else ""
if entry is None:
red.append(Issue(
"MISSING_CITE", "引用了 bib 里不存在的 key %r" % key,
Expand Down Expand Up @@ -1510,7 +1515,7 @@ def _line_bound_quant(line_no: int) -> list[Fact]:
struct_root = cfg.root_tex
if not struct_root and (cfg.root / "main.tex").is_file():
struct_root = "main.tex"
shell = (cfg.root / "main.tex").read_text(encoding="utf-8")
shell = to_lf(read_text_exact(cfg.root / "main.tex"))
if all(rel != "main.tex" for rel, _text in sections):
struct_sections = list(sections) + [("main.tex", shell)]
structural = structural_whitelist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .evidence import suggest_evidence
from .style import _headings # 复用既有标题抽取,不另写一套
from .terms import Term, load_glossary
from .textio import read_text_exact, to_lf
from .texrules import strip_comments_and_verbatim
from .texscan import scan_tex

Expand Down Expand Up @@ -122,7 +123,7 @@ def _input_order(cfg: Config, known: set[str]) -> list[str]:
if root_file is None or not root_file.is_file():
return []
try:
text = root_file.read_text(encoding="utf-8")
text = to_lf(read_text_exact(root_file))
except (OSError, UnicodeDecodeError):
return []
body = strip_comments_and_verbatim(text)
Expand Down Expand Up @@ -243,6 +244,7 @@ def build_brief(project: Path | str, section: str | None = None) -> Brief:
"简报无从生成;请先补账。" % cfg.facts_glob)

sections = load_sections(cfg)
sections = [(rel, to_lf(text)) for rel, text in sections]
rows = build_sections(cfg, sections)
if not rows:
raise ConfigError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from . import fonts as fontcache
from .constants import EXIT_CONFIG, EXIT_INTERNAL, EXIT_MISSING, EXIT_OK
from .textio import read_text_exact, write_text_exact

TIMEOUT_SECONDS = 600
TAIL_LINES = 20
Expand Down Expand Up @@ -212,13 +213,13 @@ def auto_build(root: Path, output: str = "main.pdf",
% (cjk_font, _tail(out))), info
if font is not None:
patched = rewrite_cjk_font(
target.read_text(encoding="utf-8"), font)
read_text_exact(target), font)
info["font_source"] = "system"
info["cjk_font"] = str(font)
mode = "temp-cjk-font"
elif fandol_dir is not None:
patched = rewrite_cjk_font_fandol(
target.read_text(encoding="utf-8"), fandol_dir)
read_text_exact(target), fandol_dir)
info["font_source"] = "fandol"
info["font_dir"] = str(fandol_dir)
mode = "temp-fandol-font"
Expand All @@ -234,11 +235,12 @@ def auto_build(root: Path, output: str = "main.pdf",
"(先跑 `python3 -m factscribe fonts --fetch`,"
"或试 --cjk-font <路径>)。\n%s" % _tail(out)), info
patched = rewrite_cjk_font(
target.read_text(encoding="utf-8"), font)
read_text_exact(target), font)
info["font_source"] = "system"
info["cjk_font"] = str(font)
mode = "temp-cjk-font"
target.write_text(patched, encoding="utf-8")
# newline="":临时副本与源文件逐字节对应(不引入 CRLF 翻译)。
write_text_exact(target, patched)
rc, out = _run_engine(exe, work, tex.name)
info["attempts"].append({
"attempt": 2, "mode": mode, "returncode": rc,
Expand Down
Loading