backend: let a model ask for a line break, and read the 参考文献 list back

The paper model gained two things while the MCP layer was not looking, and
both were invisible from a tool call.

`paper_sentence.line_break_before` — the flag a paragraph needs so a formula,
a list of items or an author line can start a line of its own — was not in
`SentenceSpec`, and `sentence_inputs` dropped it on the floor: a model could
write the field, watch the call succeed, and get prose back. It is now part of
every write path (`paragraph_write`, `paper_write`, `sentence_add`,
`sentence_update`) and of every read path (`sentence_row` reports it, so a
model can see the lines before moving one). Two bugs fell out of doing it
properly:

* `paragraph_move` rebuilt its sentences without the flag, so moving a
  paragraph that carried a formula turned it into prose. It also passed the
  *source* sorts through, which interleaved the moved sentences with the
  target's own — the merged paragraph read in an order neither writer wrote.
  Both are fixed; the tool now appends, as its own description promised.
* `document_text` printed a formula run into the sentence before it. The paper
  view renders `$$…$$` as a block, so the seam rules are now the same in both
  places, with a comment on each side naming the other.

`PaperDocumentRead.references` and `reference_style` — the per-work 参考文献
list the backend now assembles and formats — were reachable over REST but not
over MCP: `paper_document(format="json")` returned citations and nothing to
point them at, even though docs/MCP.md already described the list. The json
form now carries the entries (index, reference_id, text, missing, citations)
and the style name, so a model quotes the bibliography instead of assembling a
second one out of the same fields.

smoke_mcp.py grows from 76 checks to 99 over two new steps — the line-break
step pins the display-formula rule, the marker toggle and the moving case; the
bibliography step cites one work from two sentences and checks that the text,
the entry and both markers agree on one number.
This commit is contained in:
2026-09-23 11:49:39 +08:00
parent 960450f744
commit 9f2bbe50eb
11 changed files with 483 additions and 34 deletions
+23 -2
View File
@@ -85,6 +85,15 @@ def register(server: MCPServer) -> None:
citations: Annotated[
list[CitationSpec] | None, Field(description="这句引用了哪些文献")
] = None,
line_break_before: Annotated[
bool,
Field(
description=(
"这一句前面另起一行(默认 false):公式、分条列举、作者行用得上。"
"break 会顶掉句间的空格"
)
),
] = False,
sort: Annotated[
int | None, Field(description="段内位置;不传则排在段尾")
] = None,
@@ -99,6 +108,7 @@ def register(server: MCPServer) -> None:
SentenceCreate(
paper_template_filed_sort=field_sort,
content=content,
line_break_before=line_break_before,
citations=_citations(citations or []),
sort=sort,
),
@@ -123,13 +133,23 @@ def register(server: MCPServer) -> None:
sort: Annotated[
int | None, Field(description="段内排序值;不传则不动")
] = None,
line_break_before: Annotated[
bool | None,
Field(description="这一句是否另起一行;不传则不动,false 表示取消换行"),
] = None,
citations: Annotated[
list[CitationSpec] | None,
Field(description="引用整组替换;传 [] 表示清空引用"),
] = None,
) -> str:
"""修改一句话的正文、所属段落、排序或引用(引用是整体替换)。"""
if content is None and position is None and sort is None and citations is None:
"""修改一句话的正文、所属段落、排序、换行或引用(引用是整体替换)。"""
if (
content is None
and position is None
and sort is None
and line_break_before is None
and citations is None
):
s.fail("没有给出任何要修改的内容")
with s.session() as db:
@@ -143,6 +163,7 @@ def register(server: MCPServer) -> None:
content=content,
paper_template_filed_sort=position,
sort=sort,
line_break_before=line_break_before,
citations=None if citations is None else _citations(citations),
),
)