| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #!/usr/bin/env node
- const fs = require('fs');
- const path = require('path');
- const { parseList } = require('./industry-trend-report');
- 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 readJson(filePath) {
- return fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : {};
- }
- function cleanPreferenceItems(value) {
- return parseList(value)
- .map(item => item
- .replace(/^(这些|这类|这种|方向是|方向:|方向:)/, '')
- .replace(/(这些方向|这些内容|这类方向|这类内容|这种方向|这种内容|方向|内容)$/g, '')
- .trim())
- .filter(Boolean);
- }
- function main() {
- const args = parseArgs(process.argv.slice(2));
- const output = path.resolve(args.output || args.memory || 'memory/industry-trend-memory.json');
- const memory = {
- preferredSignals: [],
- blockedDirections: [],
- preferredOutput: [],
- highValueKeywords: [],
- ...readJson(output)
- };
- memory.preferredSignals = [...new Set([...(memory.preferredSignals || []), ...cleanPreferenceItems(args.keep || args.preferredSignals)])];
- memory.blockedDirections = [...new Set([...(memory.blockedDirections || []), ...cleanPreferenceItems(args.drop || args.blockedDirections)])];
- memory.preferredOutput = [...new Set([
- ...(memory.preferredOutput || []),
- ...parseList(args['output-preference'] || args.outputPreference || args.preferredOutput)
- ])];
- memory.highValueKeywords = [...new Set([...(memory.highValueKeywords || []), ...parseList(args.keywords)])];
- memory.updatedAt = new Date().toISOString();
- fs.mkdirSync(path.dirname(output), { recursive: true });
- fs.writeFileSync(output, JSON.stringify(memory, null, 2), 'utf8');
- console.log(`INDUSTRY_TREND_MEMORY_RESULT=${JSON.stringify({
- status: 'ok',
- memoryPath: output,
- memory,
- assistantMessage: '✅ 行业趋势偏好已保存。'
- })}`);
- }
- if (require.main === module) {
- try {
- main();
- } catch (error) {
- console.error(error && error.stack ? error.stack : String(error));
- process.exit(1);
- }
- }
|