#!/usr/bin/env node const path = require('path'); const { runXiaohongshuTrend } = require('../mcp/src/tools/xiaohongshu-trend-run'); const { updateXiaohongshuPreference } = require('../mcp/src/tools/xiaohongshu-preference-update'); const { Client } = require('@modelcontextprotocol/sdk/client/index.js'); const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js'); const ROOT = path.resolve(__dirname, '..'); const OUTPUT_ROOT = path.resolve(ROOT, 'outputs', 'claude-code-package-smoke'); const MEMORY_PATH = path.join(OUTPUT_ROOT, 'xiaohongshu-trend-memory.json'); async function smokeMcpTools() { const client = new Client({ name: 'voc-intelligence-package-smoke', version: '0.1.2' }); const transport = new StdioClientTransport({ command: process.execPath, args: ['mcp/src/server.js'], cwd: ROOT, stderr: 'pipe' }); await client.connect(transport); try { const tools = await client.listTools(); return tools.tools.map(tool => tool.name); } finally { await client.close(); } } async function main() { const sample = await runXiaohongshuTrend({ collectionMode: 'sample', profile: path.join(ROOT, 'memory-templates', 'xiaohongshu-trend-profile.json'), output: path.join(OUTPUT_ROOT, 'sample') }); if (sample.status !== 'ok') { throw new Error(`sample failed: ${sample.status}`); } const preference = await updateXiaohongshuPreference({ message: '保留奶油风和全屋定制翻车方向,不要纯风格美图,下一版更偏门店转化话术', memory: MEMORY_PATH }); if (preference.status !== 'ok') { throw new Error(`preference failed: ${preference.status}`); } const withMemory = await runXiaohongshuTrend({ collectionMode: 'sample', profile: path.join(ROOT, 'memory-templates', 'xiaohongshu-trend-profile.json'), memory: MEMORY_PATH, output: path.join(OUTPUT_ROOT, 'with-memory') }); if (withMemory.status !== 'ok' || !withMemory.summary.preferenceMemoryApplied) { throw new Error('sample-with-memory did not apply preference memory'); } const toolNames = await smokeMcpTools(); const requiredTools = [ 'voc_xiaohongshu_token_check', 'voc_xiaohongshu_trend_run', 'voc_xiaohongshu_preference_update' ]; for (const tool of requiredTools) { if (!toolNames.includes(tool)) { throw new Error(`missing MCP tool: ${tool}`); } } console.log(JSON.stringify({ status: 'ok', checks: [ 'sample report', 'preference memory', 'sample report with memory', 'MCP tools' ], mcpTools: toolNames, reportPreview: String(withMemory.assistantMessage || '').split('\n').slice(0, 8).join('\n'), files: withMemory.files }, null, 2)); } main().catch(error => { console.error(JSON.stringify({ status: 'error', message: error.message }, null, 2)); process.exit(1); });