"""Last-pass repairs on a model reply, before the employee reads it. A system prompt is a request, not a guarantee. Production, 2026-08-17: the prompt said "when you name Helix, give the link", and the model answered 「在 PingCAP,你可以通过 **IT 系统** 申请邮箱别名」 — it dodged the rule by never naming Helix, and the employee was left with a noun instead of somewhere to tap. The same class of miss will recur with any instruction phrased as a condition the model can route around. So the prompt states the rule (it produces better replies when followed) and this module makes the outcome deterministic when it is not. Nothing here rewrites meaning: it only appends the destination the sentence already implied. """ from __future__ import annotations import re from app.core.locale import DEFAULT_LANG, Lang #: Markdown the model writes and a Feishu *text* message does not render, so #: 「你目前在 **12 个** 邮件组里」 reaches the employee with the asterisks in it. #: Stripped rather than converted: a text message has no bold, and leaving the #: markers in is the visible defect. #: Single-line, and neither end may touch a digit. ``re.S`` with a bare #: ``(.+?)`` — the first shape — let two unrelated literal ``**`` swallow #: everything between them: 「计算 2**3 的结果是 8,另外 5**2 是 25」 came out as #: 「计算 23 …,另外 52 是 25」, and 「手机 138**5678」 lost its mask. Exponent #: and masking notation is always digit-adjacent; emphasis, in every language #: the assistant speaks, is not. Kept digit-based rather than word-based on #: purpose — Chinese writes 「你的**保修期**是」 with no spaces, and a #: ``(?`` tag; other MCP # clients can safely treat it as visible text. FEISHU_MENTION = re.compile( r"\[\[helix_mention:(?P[0-9a-fA-F-]{36}):(?P