Files
paper-doc/deploy/build-mcp-image.sh
govin 9f2bbe50eb 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.
2026-09-23 11:49:39 +08:00

136 lines
4.8 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Build the paper-doc image and push it to the registry the cluster pulls from.
#
# Why a pod builds it
# -------------------
# There is no container runtime on this host: k3s runs containerd, and the
# binaries on the node are the k3s ones (`ctr`, `crictl`), neither of which
# builds from a Dockerfile. So the build runs where a builder already exists —
# a privileged docker-in-docker pod inside the cluster — and the source reaches
# it through a hostPath mount rather than `kubectl cp`, which keeps the build
# context exactly the working tree you are looking at, uncommitted edits
# included.
#
# The credentials are read out of the cluster's own pull secret rather than
# taken as arguments, so this script has none in it and nothing is pasted into a
# shell history.
#
# Usage (from anywhere):
#
# deploy/build-mcp-image.sh # tag :v1
# deploy/build-mcp-image.sh v2 # tag :v2
# IMAGE=... deploy/build-mcp-image.sh # a different repository entirely
#
# Prerequisite: `export KUBECONFIG=$HOME/.kube/config` (the k3s binary defaults
# to /etc/rancher/k3s/k3s.yaml, which is root-only on this host).
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TAG="${1:-v1}"
IMAGE="${IMAGE:-registry.cn-hangzhou.aliyuncs.com/mcp_skill/paper-doc-mcp:${TAG}}"
BUILD_NAMESPACE="${BUILD_NAMESPACE:-default}"
BUILD_POD="${BUILD_POD:-dind-build-paper-doc}"
REGISTRY_HOST="${IMAGE%%/*}"
# The old build pod is what proved this image is already on the node; the same
# one is used here so a rebuild does not have to reach docker.io, which this
# network cannot.
BUILDER_IMAGE="${BUILDER_IMAGE:-docker:27-dind}"
export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
log() { printf '\n=== %s\n' "$*"; }
cleanup() {
log "removing the build pod"
kubectl -n "$BUILD_NAMESPACE" delete pod "$BUILD_POD" --ignore-not-found --wait=false >/dev/null 2>&1 || true
}
trap cleanup EXIT
log "build context: $REPO_ROOT/backend"
log "image: $IMAGE"
kubectl -n "$BUILD_NAMESPACE" delete pod "$BUILD_POD" --ignore-not-found >/dev/null 2>&1 || true
log "starting the docker-in-docker builder"
# `DOCKER_TLS_CERTDIR=""` keeps the daemon on tcp://localhost:2375 inside the
# pod, so `docker` in the same container needs no certificate dance. The pod is
# privileged because that is what a docker daemon needs; it lives for the length
# of one build and is deleted by the trap.
cat <<YAML | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: ${BUILD_POD}
namespace: ${BUILD_NAMESPACE}
labels:
app.kubernetes.io/name: paper-doc
app.kubernetes.io/component: image-build
spec:
restartPolicy: Never
containers:
- name: dind
image: ${BUILDER_IMAGE}
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
volumeMounts:
- name: workspace
mountPath: /workspace
- name: docker-storage
mountPath: /var/lib/docker
volumes:
- name: workspace
hostPath:
path: ${REPO_ROOT}
type: Directory
- name: docker-storage
emptyDir: {}
YAML
log "waiting for the daemon"
kubectl -n "$BUILD_NAMESPACE" wait --for=condition=Ready "pod/$BUILD_POD" --timeout=180s
for _ in $(seq 1 30); do
if kubectl -n "$BUILD_NAMESPACE" exec "$BUILD_POD" -- docker info >/dev/null 2>&1; then
break
fi
sleep 2
done
kubectl -n "$BUILD_NAMESPACE" exec "$BUILD_POD" -- docker info --format 'daemon ok: {{.ServerVersion}}'
log "logging in to $REGISTRY_HOST"
# Read out of the pull secret the cluster already uses: the push credential and
# the pull credential are the same account, and a second copy of it in a script
# is a second place it can go stale.
kubectl -n default get secret aliyun-acr-secret -o jsonpath='{.data.\.dockerconfigjson}' \
| base64 -d \
| python3 -c '
import json, sys
auth = next(iter(json.load(sys.stdin)["auths"].values()))
print(auth["username"], auth["password"])
' \
| kubectl -n "$BUILD_NAMESPACE" exec -i "$BUILD_POD" -- sh -c \
'read -r user pass; printf "%s" "$pass" | docker login -u "$user" --password-stdin "$0"' "$REGISTRY_HOST"
log "building"
# --network=host: the build needs the same mirror access the node has for pip,
# and the pod's own network namespace would otherwise be a second, untested path
# to the internet.
kubectl -n "$BUILD_NAMESPACE" exec "$BUILD_POD" -- \
docker build --network=host --tag "$IMAGE" /workspace/backend
log "pushing"
kubectl -n "$BUILD_NAMESPACE" exec "$BUILD_POD" -- docker push "$IMAGE"
log "done: $IMAGE"
cat <<EOF
Next:
kubectl -n paper-doc apply -f deploy/k8s/10-paper-doc-mcp.yaml # 或 set image,tag 要先改进去
kubectl -n paper-doc set image deployment/paper-doc-mcp mcp=$IMAGE
kubectl -n paper-doc rollout status deployment/paper-doc-mcp
# 换镜像后 DSH 的 mcp-client 插件会攥着旧 Pod 的会话,记得触发热加载重连
EOF