'use strict'; const assert = require('assert/strict'); const path = require('path'); const { AgentKnowledgeStore, stripRetrievalAliases, scoreKnowledgeChunk } = require('../mcp/src/core/agent-knowledge'); function main() { const knowledge = new AgentKnowledgeStore({ knowledgeDir: path.resolve(__dirname, '..', 'knowledge'), }); const rules = knowledge.compactRulesText(); assert.match(rules, /把客户当前问题闭环/); assert.match(rules, /像真人微信交流,普通回复限定 1-3 句、优先 50-80 字、问号最多 1 个/); assert.match(rules, /不是每轮必须提问/); assert.doesNotMatch(rules, /接触即邀约|默认朝向邀约带看|每一轮沟通的真实目的都是把客户约出来带看/); assert.doesNotMatch(rules, /专业房产经纪人|促成有效带看/); const index = knowledge.knowledgeIndex(); assert.match(index, /knowledge\/customer-service\/chat-role\.md/); assert.doesNotMatch(index, /knowledge\/real-estate\//); const stats = knowledge.stats(); assert(stats.knowledgeChunks >= 8, `expected knowledge chunks, got ${stats.knowledgeChunks}`); const headingHit = scoreKnowledgeChunk({ heading: '北极星目标', content: '辅助说明', }, ['北极星']); const bodyHit = scoreKnowledgeChunk({ heading: '其他', content: '这里也提到北极星作为背景', }, ['北极星']); assert(headingHit > bodyHit, `heading should outrank body: ${headingHit} vs ${bodyHit}`); const billing = knowledge.search('怎么收费', 5); assert(billing.length > 0); assert(billing.some(item => /收费|费用|人工/.test(`${item.heading}\n${item.content}`))); const aliasQuery = knowledge.search('客服机器人', 5); assert(aliasQuery.some(item => item.source === 'faq.md')); for (const item of aliasQuery) { assert.doesNotMatch(item.content, /常见说法/); } assert.equal(stripRetrievalAliases('> 常见说法:客服机器人\n\n正文').includes('常见说法'), false); process.stdout.write(`${JSON.stringify({ status: 'ok', chunks: stats.knowledgeChunks, billingHits: billing.length, }, null, 2)}\n`); } try { main(); } catch (error) { process.stderr.write(`${error.stack || error.message}\n`); process.exit(1); }