fix(skills): 转义内置技能提示中的字面标签 - #640
Open
LucasIcarus wants to merge 3 commits into
Open
Conversation
LucasIcarus
marked this pull request as ready for review
July 28, 2026 13:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
<botmux_builtin_skills>的原始设计是与<botmux_routing>并列的独立提示块:prompt/global/off注入模式时,用前者承载按需技能目录,并在正文里引用后者;这里的引用本意都是普通文字,但渲染时直接拼接了
<botmux_routing>、<name>、<cmd>/<子命令>。模型最终看到的内容因此像是<botmux_builtin_skills>内又打开了若干未闭合子标签,偏离了原本“外层标签负责分区、内层是目录/帮助正文”的设计。最小复现
由修复前的 opening prompt 缩成关键几行:
如果按 XML-like 标签阅读,顺序就是:打开
botmux_builtin_skills→ 又打开botmux_routing→ 又打开name→ 直接关闭botmux_builtin_skills。后两个标签从未闭合,父标签还先于子标签关闭;off模式中的<cmd>/<子命令>也有同样问题。修复后,同一段正文变为纯文本引用:
这样只有
<botmux_builtin_skills>是结构标签,内部的标签名和命令占位符都明确是文字。与现有 hidden-context 转义的关系
#564 加入“以下 XML/配置块是隐藏运行上下文……”时,是把
<...>直接手写在中英文文案里,并没有经过统一的转义函数。它的输出是对的,但和本修复若各自维护,就会形成“手写实体 + 运行时转义”两套机制。本 PR 因此把 prompt 块正文的 XML 文本转义收口到同一个
escapeXmlText:hidden-context 源码恢复为可读的原始<...>,在渲染时与 builtin-skills 一样统一转义,并显式测试不会二次编码成&lt;。改动
src/utils/xml.ts#escapeXmlText,统一 prompt XML-like 块正文的&、<、>转义;<botmux_builtin_skills>的目录正文和off帮助提示通过该函数渲染;prompt/off、未来技能描述中的字面标签/&、转义顺序与防二次编码回归测试。影响面
skillInjection=prompt/off的中英文提示;包括 Codex、Gemini、OpenCode 等首轮内联路径,以及 Genius/Grok 的 system-prompt 路径;hidden-context 的最终输出保持不变。global模式、原生 session skill 通道、<identity>/<role>与 profile 渲染、用户注册技能块、平台路径/进程逻辑、PTY/Tmux 后端及 IM 路由。验证
pnpm exec vitest run --project unit test/xml.test.ts test/prompt-builder.test.ts test/skill-injection-mode.test.ts test/session-skill-injection.test.ts test/pi-initial-prompt.test.ts test/initial-user-turn-opening.test.ts test/cli-adapters.test.ts:7 文件、415 项通过pnpm exec vitest run --project unit test/xml.test.ts test/prompt-builder.test.ts test/skill-injection-mode.test.ts:3 文件、82 项通过pnpm test:719 文件通过、3 文件按环境跳过;11026 项通过、35 项跳过pnpm build:通过(含 domain audit、TypeScript、dashboard bundle、dist audit)git diff --check:通过按本次协作要求未执行
pnpm switch:here,也未重启 live daemon。