| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- #!/usr/bin/env node
- const fs = require('fs');
- const path = require('path');
- const { parseList } = require('./industry-trend-report');
- const DEFAULT_RESULT_PREFIX = 'INDUSTRY_TREND_PROFILE_RESULT';
- function parseArgs(argv) {
- const args = {};
- for (let i = 0; i < argv.length; i++) {
- const token = argv[i];
- if (!token.startsWith('--')) continue;
- const eq = token.indexOf('=');
- if (eq >= 0) {
- args[token.slice(2, eq)] = token.slice(eq + 1);
- } else {
- const key = token.slice(2);
- const next = argv[i + 1];
- if (next && !next.startsWith('--')) {
- args[key] = next;
- i++;
- } else {
- args[key] = true;
- }
- }
- }
- return args;
- }
- function ensureDir(dirPath) {
- fs.mkdirSync(dirPath, { recursive: true });
- }
- function inferFromMessage(message) {
- const text = String(message || '');
- const inferred = {};
- if (/家装|全屋定制|装修|衣柜|橱柜/.test(text)) {
- inferred.project = 'home-design-trend';
- inferred.industry = '家装全屋定制';
- inferred.businessType = '门店/设计服务/全屋定制服务商';
- inferred.targetAudience = ['女性客户', '家庭装修决策者', '门店到访客户'];
- inferred.decisionMakers = ['女主人', '夫妻共同决策者', '设计师影响者'];
- inferred.productsOrServices = ['全屋定制', '衣柜设计', '橱柜设计', '玄关柜', '小户型收纳'];
- inferred.trendQuestions = [
- '当季哪些装修风格正在升温?',
- '女性客户最关心哪些设计元素和翻车风险?',
- '下季度哪些风格、颜色、材质值得门店提前准备案例?',
- '哪些小红书内容角度适合设计师和门店获客?'
- ];
- inferred.keywords = ['全屋定制', '奶油风装修', '小户型收纳', '衣柜设计避坑', '厨房橱柜设计', '装修翻车'];
- inferred.mustTrackSignals = ['装修风格', '设计元素', '颜色材质', '收纳需求', '环保顾虑', '预算焦虑', '翻车风险'];
- inferred.outputPreference = {
- reportTone: '老板视角',
- actionType: '趋势判断、门店转化、设计师沟通话术'
- };
- }
- return inferred;
- }
- function mergeProfile(base, args, inferred) {
- const profile = {
- ...base,
- project: args.project || inferred.project || 'industry-trend-project',
- industry: args.industry || inferred.industry || '未填写行业',
- businessType: args.businessType || args['business-type'] || inferred.businessType || '',
- targetAudience: parseList(args.targetAudience || args['target-audience']).length
- ? parseList(args.targetAudience || args['target-audience'])
- : (inferred.targetAudience || []),
- decisionMakers: parseList(args.decisionMakers || args['decision-makers']).length
- ? parseList(args.decisionMakers || args['decision-makers'])
- : (inferred.decisionMakers || []),
- productsOrServices: parseList(args.productsOrServices || args['products-or-services']).length
- ? parseList(args.productsOrServices || args['products-or-services'])
- : (inferred.productsOrServices || []),
- priceBand: args.priceBand || args['price-band'] || inferred.priceBand || '',
- regions: parseList(args.regions || inferred.regions),
- trendQuestions: parseList(args.trendQuestions || args['trend-questions']).length
- ? parseList(args.trendQuestions || args['trend-questions'])
- : (inferred.trendQuestions || []),
- platforms: parseList(args.platforms || inferred.platforms || 'xiaohongshu'),
- keywords: parseList(args.keywords).length ? parseList(args.keywords) : (inferred.keywords || []),
- competitors: parseList(args.competitors || inferred.competitors),
- mustTrackSignals: parseList(args.mustTrackSignals || args['must-track-signals']).length
- ? parseList(args.mustTrackSignals || args['must-track-signals'])
- : (inferred.mustTrackSignals || []),
- blockedDirections: parseList(args.blockedDirections || args['blocked-directions'] || inferred.blockedDirections),
- outputPreference: {
- reportTone: args.reportTone || args['report-tone'] || inferred.outputPreference?.reportTone || '老板视角',
- actionType: args.actionType || args['action-type'] || inferred.outputPreference?.actionType || '趋势判断、内容建议、转化动作'
- },
- updatedAt: new Date().toISOString()
- };
- return profile;
- }
- function main() {
- const args = parseArgs(process.argv.slice(2));
- const output = path.resolve(args.output || 'memory/industry-trend-profile.json');
- const base = args.base && fs.existsSync(path.resolve(args.base))
- ? JSON.parse(fs.readFileSync(path.resolve(args.base), 'utf8'))
- : {};
- const inferred = inferFromMessage(args.message);
- const profile = mergeProfile(base, args, inferred);
- ensureDir(path.dirname(output));
- fs.writeFileSync(output, JSON.stringify(profile, null, 2), 'utf8');
- const needsMore = !profile.industry || profile.industry === '未填写行业' || !profile.keywords.length;
- const assistantMessage = needsMore
- ? [
- '我先建了一个行业档案草稿,但还缺关键信息。',
- '',
- '请补充 3 点:',
- '1. 你要追踪的行业/品类是什么?',
- '2. 主要决策人和影响决策的人是谁?',
- '3. 最想知道哪些趋势问题?'
- ].join('\n')
- : [
- `行业档案已建立:${profile.industry}`,
- '',
- `已记录关键词:${profile.keywords.slice(0, 8).join('、') || '待补充'}`,
- `重点信号:${profile.mustTrackSignals.slice(0, 8).join('、') || '待补充'}`,
- '',
- '下一步可以直接启动行业趋势情报官生成日报。'
- ].join('\n');
- const prefix = args['result-prefix'] || args.resultPrefix || DEFAULT_RESULT_PREFIX;
- console.log(`${prefix}=${JSON.stringify({
- status: 'ok',
- profilePath: output,
- profile,
- needsMore,
- assistantMessage
- })}`);
- }
- if (require.main === module) {
- try {
- main();
- } catch (error) {
- console.error(error && error.stack ? error.stack : String(error));
- process.exit(1);
- }
- }
|