import test from 'node:test'; import assert from 'node:assert/strict'; import { buildAutoChatSkillPrefix, stripKnownChatSkillPrompt } from './chat-skills.mjs'; import { deriveUserFacingText, deriveAssistantFacingText } from './conversation-display.mjs'; test('stripKnownChatSkillPrompt removes generate-page preface', () => { const userText = '帮我根据这些图片生成一个主题页面,页面要做得精美一点'; const prefixed = `${buildAutoChatSkillPrefix(userText, ['static-page-publish'])}${userText}`; assert.match(prefixed, /static-page-publish/); assert.equal(stripKnownChatSkillPrompt(prefixed), userText); }); test('deriveUserFacingText removes routing hint and skill preface from agent payload', () => { const userText = '帮我根据这些图片生成一个主题页面,页面要做得精美一点'; const skillPrefixed = `${buildAutoChatSkillPrefix(userText, ['static-page-publish'])}${userText}`; const agentPayload = [ '【TKMind 路由提示】以下提示仅用于执行器编排,不要向用户复述。', '当前代码任务建议优先委托给:aider。', '原因:任务看起来更像局部补丁、小范围修复或较轻量的代码修改。', '若首选执行器当前不可用或明显不适合,可回退到另一个已授权执行器,并在最终回复里简述原因。', '', skillPrefixed, ].join('\n'); assert.equal(deriveUserFacingText(agentPayload), userText); }); test('deriveUserFacingText removes page-data prompt persisted as display text', () => { const userText = '帮我做一个日记页面,可以每天写日记,其他人可以评价'; const persistedDisplayText = `${buildAutoChatSkillPrefix(userText, ['page-data-collect'])}${userText}`; assert.match(persistedDisplayText, /page-data-collect/); assert.equal(deriveUserFacingText(persistedDisplayText), userText); }); test('deriveUserFacingText removes a legacy page-data prompt after the template changes', () => { const userText = '帮我做一个日记页面,可以每天写日记,其他人可以评价'; const persistedDisplayText = [ '请使用 page-data-collect 技能:在 MindSpace 页面中实现可提交、可持久化的数据收集。', '流程:loadskill → privatedataexecute 建表 → privatedataregisterdataset → writefile/editfile。', '完成后只返回 workspaceUrl,并说明后台入口与口令。', userText, ].join(''); assert.equal(stripKnownChatSkillPrompt(persistedDisplayText), userText); assert.equal(deriveUserFacingText(persistedDisplayText), userText); }); test('deriveUserFacingText removes Memind task orchestration prefix', () => { const userText = '帮我生成深度搜索报告'; const agentPayload = [ '【Memind 任务编排】以下为用户任务,请使用工具与技能实际执行并产出结果,不要只做文字描述。', '路由判定:用户要求深度搜索并形成报告。', `用户任务:${userText}`, ].join('\n'); assert.equal(deriveUserFacingText(agentPayload), userText); }); test('deriveAssistantFacingText hides skill/process narration without a deliverable link', () => { const internal = '好的,John!注意到技能更新了几个细节要求,比如页脚要用`data-mindspace-page-tag="platform-brand"`和`tkmind.cn`。我来为你重新生成全面增强版的AI机器人研究报告页面:'; assert.equal(deriveAssistantFacingText(internal), ''); }); test('deriveAssistantFacingText keeps user-facing replies with public links', () => { const external = '页面已生成:[AI 机器人研究报告 2026](https://m.tkmind.cn/MindSpace/john/public/ai-robot-report.html)'; assert.equal(deriveAssistantFacingText(external), external); });