claude-voc.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const os = require('os');
  4. const path = require('path');
  5. const { spawnSync } = require('child_process');
  6. const SOURCE_ROOT = path.resolve(__dirname, '..');
  7. const WORKSPACE_ROOT = process.cwd();
  8. const DEFAULT_TARGET = path.join(os.homedir(), '.claude', 'plugins', 'voc-intelligence');
  9. const WORKSPACE_TARGET = path.join(WORKSPACE_ROOT, '.claude', 'plugins', 'voc-intelligence');
  10. const WORKSPACE_PLUGINS_ROOT = path.join(WORKSPACE_ROOT, '.claude', 'plugins');
  11. const MIN_NODE_MAJOR = 18;
  12. const EXCLUDED_DIRS = new Set([
  13. 'node_modules',
  14. 'memory',
  15. 'outputs',
  16. '.tmp',
  17. '.git',
  18. '.claude'
  19. ]);
  20. const EXCLUDED_FILES = new Set([
  21. '.env',
  22. '.env.local',
  23. '.npmrc'
  24. ]);
  25. function usage() {
  26. return [
  27. 'Claude VOC skill package installer',
  28. '',
  29. 'Usage:',
  30. ' claude-voc install',
  31. ' claude-voc workspace',
  32. ' claude-voc install --workspace --smoke',
  33. ' claude-voc check',
  34. ' claude-voc smoke',
  35. ' claude-voc path',
  36. '',
  37. 'npx:',
  38. ' npx @gangvy/claude-code-voc-intelligence install',
  39. ' npx @gangvy/claude-code-voc-intelligence workspace --smoke',
  40. '',
  41. 'Options:',
  42. ' --workspace Install into ./.claude/plugins/voc-intelligence',
  43. ' --target <dir> Install into a custom directory',
  44. ' --force Allow overwriting an existing custom target',
  45. ' --skip-install Skip npm install after copying files',
  46. ' --smoke Run sample/preference/MCP smoke checks after install',
  47. ' --help, -h Show help'
  48. ].join('\n');
  49. }
  50. function expandHome(value) {
  51. return value.replace(/^~(?=$|[\\/])/, os.homedir());
  52. }
  53. function parseArgs(argv) {
  54. const first = argv[0] && !argv[0].startsWith('--') ? argv[0] : 'install';
  55. const opts = {
  56. command: first,
  57. target: DEFAULT_TARGET,
  58. skipInstall: false,
  59. smoke: false,
  60. force: false,
  61. help: false
  62. };
  63. if (first === 'workspace' || first === 'install-workspace') {
  64. opts.command = 'install';
  65. opts.target = WORKSPACE_TARGET;
  66. }
  67. for (let i = first === argv[0] ? 1 : 0; i < argv.length; i++) {
  68. const token = argv[i];
  69. if (token === '--target') {
  70. opts.target = argv[++i];
  71. } else if (token.startsWith('--target=')) {
  72. opts.target = token.slice('--target='.length);
  73. } else if (token === '--workspace') {
  74. opts.target = WORKSPACE_TARGET;
  75. } else if (token === '--force') {
  76. opts.force = true;
  77. } else if (token === '--skip-install') {
  78. opts.skipInstall = true;
  79. } else if (token === '--smoke') {
  80. opts.smoke = true;
  81. } else if (token === '--help' || token === '-h') {
  82. opts.help = true;
  83. }
  84. }
  85. opts.target = path.resolve(expandHome(opts.target));
  86. return opts;
  87. }
  88. function run(command, args, cwd) {
  89. const useCmd = process.platform === 'win32' && command === 'npm';
  90. const executable = useCmd ? 'cmd.exe' : command;
  91. const finalArgs = useCmd ? ['/d', '/s', '/c', 'npm', ...args] : args;
  92. const child = spawnSync(executable, finalArgs, {
  93. cwd,
  94. encoding: 'utf8',
  95. stdio: 'inherit',
  96. maxBuffer: 1024 * 1024 * 100
  97. });
  98. if (child.status !== 0) {
  99. const detail = child.error ? `: ${child.error.message}` : '';
  100. throw new Error(`${command} ${args.join(' ')} failed with exit ${child.status}${detail}`);
  101. }
  102. }
  103. function checkNodeVersion() {
  104. const major = Number(process.versions.node.split('.')[0]);
  105. if (!Number.isFinite(major) || major < MIN_NODE_MAJOR) {
  106. throw new Error(`Node.js ${MIN_NODE_MAJOR}+ is required. Current version: ${process.version}`);
  107. }
  108. }
  109. function ensureDir(dirPath) {
  110. fs.mkdirSync(dirPath, { recursive: true });
  111. }
  112. function isInside(parentDir, childDir) {
  113. const relative = path.relative(path.resolve(parentDir), path.resolve(childDir));
  114. return relative === '' || (!!relative && !relative.startsWith('..') && !path.isAbsolute(relative));
  115. }
  116. function isSafeDefaultTarget(targetDir) {
  117. return path.resolve(targetDir) === path.resolve(DEFAULT_TARGET);
  118. }
  119. function isSafeWorkspaceTarget(targetDir) {
  120. return isInside(WORKSPACE_PLUGINS_ROOT, targetDir);
  121. }
  122. function canOverwriteTarget(targetDir, opts) {
  123. return opts.force || isSafeDefaultTarget(targetDir) || isSafeWorkspaceTarget(targetDir);
  124. }
  125. function shouldCopyEntry(entry) {
  126. if (entry.isDirectory()) return !EXCLUDED_DIRS.has(entry.name);
  127. if (entry.isFile()) {
  128. if (EXCLUDED_FILES.has(entry.name)) return false;
  129. if (entry.name.endsWith('.tgz')) return false;
  130. return true;
  131. }
  132. return false;
  133. }
  134. function copyDirRecursive(srcDir, destDir) {
  135. ensureDir(destDir);
  136. let count = 0;
  137. for (const entry of fs.readdirSync(srcDir, { withFileTypes: true })) {
  138. if (!shouldCopyEntry(entry)) continue;
  139. const src = path.join(srcDir, entry.name);
  140. const dest = path.join(destDir, entry.name);
  141. if (entry.isDirectory()) {
  142. count += copyDirRecursive(src, dest);
  143. } else if (entry.isFile()) {
  144. ensureDir(path.dirname(dest));
  145. fs.copyFileSync(src, dest);
  146. count++;
  147. }
  148. }
  149. return count;
  150. }
  151. function assertInstalled(targetDir) {
  152. const required = [
  153. 'package.json',
  154. 'install.js',
  155. '.claude-plugin/plugin.json',
  156. '.mcp.json',
  157. 'skills/xiaohongshu-trend-intelligence/SKILL.md',
  158. 'skills/douyin-trend-intelligence/SKILL.md',
  159. 'skills/voc-issue-pool/SKILL.md',
  160. 'skills/voc-problem-deep-dive/SKILL.md',
  161. 'skills/voc-content-plan/SKILL.md',
  162. 'skills/voc-speaking-script/SKILL.md',
  163. 'skills/voc-competitor-map/SKILL.md',
  164. 'skills/voc-business-workflow/SKILL.md',
  165. 'mcp/src/server.js'
  166. ];
  167. const missing = required.filter(rel => !fs.existsSync(path.join(targetDir, rel)));
  168. if (missing.length) {
  169. throw new Error(`Missing required files in install target: ${missing.join(', ')}`);
  170. }
  171. }
  172. function writeMcpConfig(targetDir) {
  173. const serverPath = path.join(targetDir, 'mcp', 'src', 'server.js');
  174. const mcpConfig = {
  175. mcpServers: {
  176. voc: {
  177. command: 'node',
  178. args: [serverPath],
  179. cwd: targetDir
  180. }
  181. }
  182. };
  183. fs.writeFileSync(path.join(targetDir, '.mcp.json'), `${JSON.stringify(mcpConfig, null, 2)}\n`, 'utf8');
  184. }
  185. function readJsonIfExists(filePath) {
  186. if (!fs.existsSync(filePath)) return {};
  187. return JSON.parse(fs.readFileSync(filePath, 'utf8'));
  188. }
  189. function writeWorkspaceMcpConfig(targetDir) {
  190. const mcpConfigPath = path.join(WORKSPACE_ROOT, '.mcp.json');
  191. const existing = readJsonIfExists(mcpConfigPath);
  192. const mcpConfig = {
  193. ...existing,
  194. mcpServers: {
  195. ...(existing.mcpServers || {}),
  196. voc: {
  197. command: 'node',
  198. args: [path.join(targetDir, 'mcp', 'src', 'server.js')],
  199. cwd: targetDir
  200. }
  201. }
  202. };
  203. fs.writeFileSync(mcpConfigPath, `${JSON.stringify(mcpConfig, null, 2)}\n`, 'utf8');
  204. }
  205. function asForwardSlash(filePath) {
  206. return path.resolve(filePath).replace(/\\/g, '/');
  207. }
  208. function quotedPath(filePath) {
  209. return `"${asForwardSlash(filePath)}"`;
  210. }
  211. function workspaceTrendSkillText(options) {
  212. const trendRunner = path.join(options.targetDir, 'mcp', 'src', 'tools', options.trendTool);
  213. const preferenceUpdater = path.join(options.targetDir, 'mcp', 'src', 'tools', options.preferenceTool);
  214. const profilePath = path.join(options.targetDir, 'memory-templates', options.profileFile);
  215. const defaultMemoryPath = path.join(WORKSPACE_ROOT, 'outputs', options.memoryDir, options.memoryFile);
  216. const liveLimits = options.platform === '抖音'
  217. ? '--keyword-limit 1 --videos-per-keyword 1 --max-comment-pages 1'
  218. : '--keyword-limit 1 --notes-per-keyword 1 --max-comment-pages 1';
  219. return [
  220. '---',
  221. `name: ${options.skillName}`,
  222. `description: ${options.description}`,
  223. 'allowed-tools: Read Write Bash(node *)',
  224. '---',
  225. '',
  226. `# ${options.platform}趋势情报官`,
  227. '',
  228. `你是面向业务用户的“${options.platform}趋势情报官”。用户要的是第一轮样本观察、机会假设和待确认问题,不是技术日志。`,
  229. '',
  230. '## 必须执行',
  231. '',
  232. `- 用户要求${options.platform}趋势情报、内容趋势、评论分析、真实采集、live采集或社媒 VOC 时,必须运行本技能包的工具或 MCP,不要只凭经验回答。`,
  233. '- 用户说“live / 真实采集 / 进入 live / 实时采集 / 抓真实数据”时,必须运行 live 模式工具。不要回复“我不能实时抓取外部数据”。本技能包已经提供本地 VOC 采集入口。',
  234. '- live 模式返回 `needs_token`、`needs_recharge` 或 `needs_valid_token` 时,必须把工具输出里的 `assistantMessage` 原样转述给用户,尤其不能省略充值/开通链接。',
  235. '- 如果工具输出里有 `nextActions`,至少转述其中带 `apig-pay` 的充值链接。',
  236. '- 第一轮只说“初步判断 / 机会假设 / 待校准”,不要说成最终结论。',
  237. '- 后续用户说“保留、不要、更偏、这个不准”等反馈时,运行偏好更新命令沉淀记忆。',
  238. '',
  239. '## MANDATORY Live Rule',
  240. '',
  241. '- If the user asks for live collection, real collection, or entering live mode, run the local VOC tool in live mode.',
  242. '- Do not answer that you cannot fetch external data. The local VOC tool is the approved collection entry.',
  243. '- If the tool returns `needs_token`, `needs_recharge`, or `needs_valid_token`, paste its `assistantMessage` to the user and keep the payment URL visible.',
  244. '- The payment URL must be shown when there is no token or insufficient balance: `https://app.fmode.cn/dev/apig-pay/?apigid=Vo3ROWEvDy&fun_id=HOkkX72PMF`',
  245. '',
  246. '## sample 命令',
  247. '',
  248. '```bash',
  249. `node ${quotedPath(trendRunner)} --collection-mode sample --profile ${quotedPath(profilePath)} --output ${JSON.stringify(options.sampleOutput)} --assistant-message-only`,
  250. '```',
  251. '',
  252. '## live 命令',
  253. '',
  254. '```bash',
  255. `node ${quotedPath(trendRunner)} --collection-mode live --profile ${quotedPath(profilePath)} --output ${JSON.stringify(options.liveOutput)} ${liveLimits} --assistant-message-only`,
  256. '```',
  257. '',
  258. '运行后把命令输出正文直接发给用户。不要展示 JSON、summary、data、files 或调试日志。',
  259. '',
  260. '## 偏好更新命令',
  261. '',
  262. '```bash',
  263. `node ${quotedPath(preferenceUpdater)} --message "<用户反馈原文>" --memory ${quotedPath(defaultMemoryPath)} --result-prefix ${options.resultPrefix}`,
  264. '```',
  265. '',
  266. '## 充值链接口径',
  267. '',
  268. '没有 token 或余额不足时,用户必须看到:',
  269. '',
  270. '```text',
  271. 'https://app.fmode.cn/dev/apig-pay/?apigid=Vo3ROWEvDy&fun_id=HOkkX72PMF',
  272. '```',
  273. '',
  274. '套餐入口可作为补充:',
  275. '',
  276. '```text',
  277. 'https://app.fmode.cn/dev/apig-pay/#/workshop/99',
  278. '```',
  279. ''
  280. ].join('\n');
  281. }
  282. function workspaceSkillText(targetDir) {
  283. return workspaceTrendSkillText({
  284. targetDir,
  285. skillName: 'xiaohongshu-trend-intelligence',
  286. platform: '小红书',
  287. description: 'Build Xiaohongshu trend intelligence reports. Use when the user asks for 小红书趋势情报、行业趋势、内容选题、销售话术、真实采集、live采集、用户顾虑 or social VOC analysis.',
  288. trendTool: 'xiaohongshu-trend-run.js',
  289. preferenceTool: 'xiaohongshu-preference-update.js',
  290. profileFile: 'xiaohongshu-trend-profile.json',
  291. memoryDir: 'claude-code-xhs-memory',
  292. memoryFile: 'xiaohongshu-trend-memory.json',
  293. sampleOutput: 'outputs/claude-code-xhs-sample',
  294. liveOutput: 'outputs/claude-code-xhs-live',
  295. resultPrefix: 'XHS_PREF_RESULT'
  296. });
  297. const trendRunner = path.join(targetDir, 'mcp', 'src', 'tools', 'xiaohongshu-trend-run.js');
  298. const preferenceUpdater = path.join(targetDir, 'mcp', 'src', 'tools', 'xiaohongshu-preference-update.js');
  299. const profilePath = path.join(targetDir, 'memory-templates', 'xiaohongshu-trend-profile.json');
  300. const defaultMemoryPath = path.join(WORKSPACE_ROOT, 'outputs', 'claude-code-xhs-memory', 'xiaohongshu-trend-memory.json');
  301. return [
  302. '---',
  303. 'name: xiaohongshu-trend-intelligence',
  304. 'description: Build Xiaohongshu trend intelligence reports from industry direction, audience, keywords, notes, and comments. Use when the user asks for 小红书趋势情报、行业趋势、女性客户消费决策、设计元素洞察、家装全屋定制趋势、内容选题 or social VOC analysis.',
  305. 'allowed-tools: Read Write Bash(node *)',
  306. '---',
  307. '',
  308. '# 小红书趋势情报官',
  309. '',
  310. '你是面向业务用户的“小红书趋势情报官”。用户要的是第一轮样本观察、机会假设和待确认问题,不是技术日志。',
  311. '',
  312. '## 必须执行',
  313. '',
  314. '- 当用户要求做小红书趋势情报、行业趋势、女性客户消费决策、家装全屋定制趋势、设计元素洞察或内容选题时,优先运行下面的 sample 工具命令。',
  315. '- 不要只凭经验回答,也不要只返回文件路径。',
  316. '- 工具输出里会有 `assistantMessage`,请把它的正文直接发给用户。',
  317. '- 第一轮只能说“初步判断 / 机会假设 / 待校准”,不要说成最终结论。',
  318. '- 后续用户说“保留、不要、更偏、这个不准”等反馈时,运行偏好更新命令沉淀记忆。',
  319. '',
  320. '## sample 趋势情报命令',
  321. '',
  322. '```bash',
  323. `node ${quotedPath(trendRunner)} --collection-mode sample --profile ${quotedPath(profilePath)} --output "outputs/claude-code-xhs-sample" --assistant-message-only`,
  324. '```',
  325. '',
  326. '运行后把命令输出正文直接发给用户。不要展示 JSON、summary、data、files 或调试日志。',
  327. '',
  328. '## 偏好更新命令',
  329. '',
  330. '```bash',
  331. `node ${quotedPath(preferenceUpdater)} --message "<用户反馈原文>" --memory ${quotedPath(defaultMemoryPath)} --result-prefix XHS_PREF_RESULT`,
  332. '```',
  333. '',
  334. '## 推荐用户启动话术',
  335. '',
  336. '```text',
  337. '帮我做一份家装全屋定制行业的小红书趋势情报。',
  338. '先用演示样例跑通流程,不要真实采集。',
  339. '在聊天里给我第一轮样本观察和待确认问题。',
  340. '```',
  341. ''
  342. ].join('\n');
  343. }
  344. function workspaceDouyinSkillText(targetDir) {
  345. return workspaceTrendSkillText({
  346. targetDir,
  347. skillName: 'douyin-trend-intelligence',
  348. platform: '抖音',
  349. description: 'Build Douyin trend intelligence reports. Use when the user asks for 抖音趋势情报、视频评论、口播选题、短视频开头、内容趋势、真实采集、live采集、用户顾虑 or social VOC analysis.',
  350. trendTool: 'douyin-trend-run.js',
  351. preferenceTool: 'douyin-preference-update.js',
  352. profileFile: 'douyin-trend-profile.json',
  353. memoryDir: 'claude-code-douyin-memory',
  354. memoryFile: 'douyin-trend-memory.json',
  355. sampleOutput: 'outputs/claude-code-douyin-sample',
  356. liveOutput: 'outputs/claude-code-douyin-live',
  357. resultPrefix: 'DOUYIN_PREF_RESULT'
  358. });
  359. const trendRunner = path.join(targetDir, 'mcp', 'src', 'tools', 'douyin-trend-run.js');
  360. const preferenceUpdater = path.join(targetDir, 'mcp', 'src', 'tools', 'douyin-preference-update.js');
  361. const profilePath = path.join(targetDir, 'memory-templates', 'douyin-trend-profile.json');
  362. const defaultMemoryPath = path.join(WORKSPACE_ROOT, 'outputs', 'claude-code-douyin-memory', 'douyin-trend-memory.json');
  363. return [
  364. '---',
  365. 'name: douyin-trend-intelligence',
  366. 'description: Build Douyin trend intelligence reports from industry direction, audience, keywords, videos, and comments. Use when the user asks for 抖音趋势情报、视频评论、口播选题、短视频开头、内容趋势 or social VOC analysis.',
  367. 'allowed-tools: Read Write Bash(node *)',
  368. '---',
  369. '',
  370. '# 抖音趋势情报官',
  371. '',
  372. '你是面向业务用户的“抖音趋势情报官”。用户要的是第一轮样本观察、机会假设和待确认问题,不是技术日志。',
  373. '',
  374. '## 必须执行',
  375. '',
  376. '- 当用户要求做抖音趋势情报、视频评论、口播选题、短视频开头或内容趋势时,优先运行下面的 sample 工具命令。',
  377. '- 不要只凭经验回答,也不要只返回文件路径。',
  378. '- 工具输出里会有 `assistantMessage`,请把它的正文直接发给用户。',
  379. '- 第一轮只能说“初步判断 / 机会假设 / 待校准”,不要说成最终结论。',
  380. '- 后续用户说“保留、不要、更偏、这个不准”等反馈时,运行偏好更新命令沉淀记忆。',
  381. '',
  382. '## sample 趋势情报命令',
  383. '',
  384. '```bash',
  385. `node ${quotedPath(trendRunner)} --collection-mode sample --profile ${quotedPath(profilePath)} --output "outputs/claude-code-douyin-sample" --assistant-message-only`,
  386. '```',
  387. '',
  388. '运行后把命令输出正文直接发给用户。不要展示 JSON、summary、data、files 或调试日志。',
  389. '',
  390. '## 偏好更新命令',
  391. '',
  392. '```bash',
  393. `node ${quotedPath(preferenceUpdater)} --message "<用户反馈原文>" --memory ${quotedPath(defaultMemoryPath)} --result-prefix DOUYIN_PREF_RESULT`,
  394. '```',
  395. '',
  396. '## 推荐用户启动话术',
  397. '',
  398. '```text',
  399. '帮我做一份家装全屋定制行业的抖音趋势情报。',
  400. '先用演示样例跑通流程,不要真实采集。',
  401. '在聊天里给我第一轮样本观察和待确认问题。',
  402. '```',
  403. ''
  404. ].join('\n');
  405. }
  406. function workspaceProblemDeepDiveSkillText(targetDir) {
  407. const deepDiveRunner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-problem-deep-dive-run.js');
  408. return [
  409. '---',
  410. 'name: voc-problem-deep-dive',
  411. 'description: Deep-dive a single VOC problem into root cause, boss/operator impact, concrete actions, content ideas, and validation metrics. Use when the user says 继续挖、深入分析、老板怎么解决、这个问题怎么办、怎么改门店、怎么转成内容、单点VOC or VOC深挖.',
  412. 'allowed-tools: Read Write Bash(node *)',
  413. '---',
  414. '',
  415. '# 单点 VOC 深挖官',
  416. '',
  417. '你是面向老板和门店经营者的“单点 VOC 深挖官”。用户不需要学习提示词。用户只要说“这个问题继续挖”“老板怎么解决”“这个差评背后是什么”,你就要把真实用户声音转成可执行经营动作。',
  418. '',
  419. '## 必须执行',
  420. '',
  421. '- 当用户说“继续挖、深入分析、老板怎么解决、这个问题怎么办、怎么改、怎么转成内容、单点 VOC”时,必须运行单点深挖工具。',
  422. '- 不要输出提示词教学,不要让用户自己设计分析维度。',
  423. '- 输出必须站在老板视角:这件事影响新客、复购、客单、口碑,还是现场效率。',
  424. '- 每次只深挖一个问题点。如果用户给了多个问题,先选择最影响转化的一个。',
  425. '- 如果上一轮趋势报告里有证据样本或高赞评论,要把相关评论作为 evidence 传入工具。',
  426. '- 要使用记忆能力:用户说“这个动作不适合”“我们已经试过”“这个有效”“下次更偏内容/门店动作”时,把原话作为 `feedback` 传入;如果能明确识别,也同步传 `blockedActions`、`validatedActions`、`rejectedActions` 或 `preferredActions`。',
  427. '- 后续多轮迭代时要带上 `project`/`brand`/`store`、`industry`、`scenario`、`audience`。未显式传 `memory` 时,工具会按这些字段自动隔离记忆,避免不同行业、不同客户串味。',
  428. '- 如果用户没有指定记忆文件,不要强行要求用户理解路径;让工具使用默认分桶记忆即可。只有在同一个客户需要固定沉淀时,才显式传同一个 `memory` 路径。',
  429. '',
  430. '## 命令',
  431. '',
  432. '```bash',
  433. `node ${quotedPath(deepDiveRunner)} --issue "排队" --industry "本地生活餐饮" --scenario "门店经营" --audience "到店顾客" --assistant-message-only`,
  434. '```',
  435. '',
  436. '## 带记忆的多轮迭代',
  437. '',
  438. '```bash',
  439. `node ${quotedPath(deepDiveRunner)} --issue "排队" --industry "本地生活餐饮" --scenario "门店经营" --audience "到店顾客" --memory "outputs/voc-problem-memory.json" --feedback "老板不想做等位饮品,更想先改评论区回复和预点单" --blocked-actions "等位饮品" --preferred-actions "评论区回复,预点单" --assistant-message-only`,
  440. '```',
  441. '',
  442. '自然语言反馈也可以直接传入 `feedback`,工具会尝试自动提取偏好和屏蔽动作:',
  443. '',
  444. '```bash',
  445. `node ${quotedPath(deepDiveRunner)} --issue "排队" --project "样板门店A" --industry "本地生活餐饮" --scenario "门店经营" --audience "到店顾客" --feedback "这个店不想做等位饮品,更想先改评论区回复和预点单" --assistant-message-only`,
  446. '```',
  447. '',
  448. '运行后把命令输出正文直接发给用户。不要展示 JSON、summary、data、files 或调试日志。',
  449. ''
  450. ].join('\n');
  451. }
  452. function workspaceIssuePoolSkillText(targetDir) {
  453. const issuePoolRunner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-issue-pool-run.js');
  454. return [
  455. '---',
  456. 'name: voc-issue-pool',
  457. 'description: Turn VOC comments, report evidence, or user feedback into a prioritized issue pool with status, evidence, business impact, next actions, and follow-up deep-dive suggestions. Use when the user asks 哪些问题最影响生意、问题池、问题清单、用户都在吐槽什么、先改哪个、VOC问题管理、问题优先级、把评论整理成问题.',
  458. 'allowed-tools: Read Write Bash(node *)',
  459. '---',
  460. '',
  461. '# VOC 问题池官',
  462. '',
  463. '你是面向老板、门店经营者和营销负责人的 VOC 问题池官。用户不需要知道分类法,也不需要学习提示词。用户只要说“这些评论里哪些问题最重要”“先改哪个”“整理成问题池”,你就把真实用户声音整理成可排序、可跟进、可继续深挖的问题列表。',
  464. '',
  465. '## 必须执行',
  466. '',
  467. '- 当用户说“问题池、问题清单、用户吐槽什么、哪些问题最影响生意、先改哪个、VOC 问题管理、把评论整理成问题”时,优先运行 `voc_issue_pool_run`。',
  468. '- 如果上一轮小红书/抖音报告里有证据样本或高赞评论,把相关评论作为 `evidence`、`evidenceText` 或 `reportPath` 传入。',
  469. '- 输出必须站在业务视角:这个问题影响新客、复购、客单、口碑、内容信任,还是现场效率。',
  470. '- 不要只做词频统计。每个问题都要包含证据样本、影响环节、建议动作和下一步。',
  471. '- 如果用户说某个问题已解决、验证中、暂缓,要通过 `resolvedIssues`、`validatingIssues`、`blockedIssues` 或 `statusUpdates` 更新问题状态。',
  472. '- 后续深挖时,引导用户直接说“继续深挖「问题名」”,然后转入 `voc-problem-deep-dive`。',
  473. '',
  474. '## 命令',
  475. '',
  476. '```bash',
  477. `node ${quotedPath(issuePoolRunner)} --project "样板门店A" --industry "本地生活餐饮" --scenario "门店经营" --audience "到店顾客" --evidence "排队久,但是不知道值不值得等。,人均有点高,第一次来不知道怎么点不踩雷。,服务忙起来没人理。" --assistant-message-only`,
  478. '```',
  479. '',
  480. '带报告文件:',
  481. '',
  482. '```bash',
  483. `node ${quotedPath(issuePoolRunner)} --project "样板门店A" --industry "本地生活餐饮" --report "outputs/douyin-trend-report.md" --assistant-message-only`,
  484. '```',
  485. '',
  486. '运行后把命令输出正文直接发给用户。不要展示 JSON、summary、data、files 或调试日志。',
  487. ''
  488. ].join('\n');
  489. }
  490. function workspaceContentPlanSkillText(targetDir) {
  491. const runner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-content-plan-run.js');
  492. return [
  493. '---',
  494. 'name: voc-content-plan',
  495. 'description: Turn VOC issues into a 7-day content plan with short-video topics and speaking scripts. Use when the user asks 下周账号发什么、口播脚本、短视频选题、把用户问题变成内容、7天内容计划.',
  496. 'allowed-tools: Read Write Bash(node *)',
  497. '---',
  498. '',
  499. '# VOC 内容选题官',
  500. '',
  501. '当用户说“下周发什么、7 天选题、口播脚本、短视频脚本、账号内容、把问题变成内容”时,运行本工具。',
  502. '',
  503. '必须把内容绑定到 VOC 用户问题,不要输出空泛爆款标题。不要覆盖创始人故事。',
  504. '',
  505. '## 命令',
  506. '',
  507. '```bash',
  508. `node ${quotedPath(runner)} --brand "样板门店A" --industry "本地生活餐饮" --issues "第一次来怕踩雷;觉得人均贵;怕排队久" --assistant-message-only`,
  509. '```',
  510. '',
  511. '运行后把正文直接发给用户,不要展示 JSON。',
  512. ''
  513. ].join('\n');
  514. }
  515. function workspaceSpeakingScriptSkillText(targetDir) {
  516. const runner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-speaking-script-run.js');
  517. return [
  518. '---',
  519. 'name: voc-speaking-script',
  520. 'description: Turn one VOC-backed topic into a co-created speaking script with 60-second draft, 30-second compressed version, teleprompter text, revision feedback, finalization, and script memory. Use when the user says 选题2进入脚本共创、改稿、定稿、口播稿、提词器、开头更狠、老板视角、少讲概念.',
  521. 'allowed-tools: Read Write Bash(node *)',
  522. '---',
  523. '',
  524. '# VOC 口播脚本共创',
  525. '',
  526. '当用户从 7 天内容计划里选择某条选题,或说“进入脚本共创、改稿、定稿、提词器版、开头更狠、老板视角”时,运行本工具。',
  527. '',
  528. '口播必须来自 VOC 用户问题、趋势证据、问题池 Top 问题、单点深挖动作或竞品评论差异。没有真实证据时要标注低证据风险。',
  529. '',
  530. '## 命令',
  531. '',
  532. '```bash',
  533. `node ${quotedPath(runner)} --brand "样板门店A" --industry "本地生活餐饮" --topic "第一次来怎么点不踩雷" --user-issue "第一次来怕点错" --evidence "第一次来不知道怎么点,怕踩雷" --assistant-message-only`,
  534. '```',
  535. '',
  536. '改稿:',
  537. '',
  538. '```bash',
  539. `node ${quotedPath(runner)} --brand "样板门店A" --topic "第一次来怎么点不踩雷" --user-issue "第一次来怕点错" --evidence "第一次来不知道怎么点,怕踩雷" --feedback "开头更狠一点,老板视角,少讲概念,多给具体场景" --assistant-message-only`,
  540. '```',
  541. '',
  542. '定稿时传 `--finalize true`,工具会写入脚本记忆。运行后把正文直接发给用户,不要展示 JSON。',
  543. ''
  544. ].join('\n');
  545. }
  546. function workspaceCompetitorMapSkillText(targetDir) {
  547. const runner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-competitor-map-run.js');
  548. return [
  549. '---',
  550. 'name: voc-competitor-map',
  551. 'description: Build a competitor map and differentiated opportunity report. Use when the user asks 看竞品、竞品分析、错位竞争、别人为什么吸引顾客、我不知道竞品是谁.',
  552. 'allowed-tools: Read Write Bash(node *)',
  553. '---',
  554. '',
  555. '# VOC 竞品图谱官',
  556. '',
  557. '当用户说“看竞品、竞品分析、错位竞争、别人怎么做、我不知道竞品是谁”时,运行本工具。',
  558. '',
  559. '如果用户没有明确竞品,先按同城、同品类、同价格带、同消费场景、平台声量生成候选竞品类型。不要覆盖创始人故事。',
  560. '',
  561. '## 命令',
  562. '',
  563. '```bash',
  564. `node ${quotedPath(runner)} --brand "样板门店A" --city "南昌" --category "餐饮" --assistant-message-only`,
  565. '```',
  566. '',
  567. '运行后把正文直接发给用户,不要展示 JSON。',
  568. ''
  569. ].join('\n');
  570. }
  571. function workspaceBusinessWorkflowSkillText(targetDir) {
  572. const runner = path.join(targetDir, 'mcp', 'src', 'tools', 'voc-business-workflow-run.js');
  573. return [
  574. '---',
  575. 'name: voc-business-workflow',
  576. 'description: Run the full VOC business workflow from market voices to issue pool, top issue action, 7-day content plan, and one speaking script. Use when the user asks 看顾客关心什么、先改哪里、下周发什么、完整VOC闭环、经营诊断.',
  577. 'allowed-tools: Read Write Bash(node *)',
  578. '---',
  579. '',
  580. '# VOC经营闭环',
  581. '',
  582. '当用户想一次拿到“看市场、看问题、找动作、做内容”的结果时,运行本工具。不要让用户理解 MCP、schema 或多个工具名。',
  583. '',
  584. '## 命令',
  585. '',
  586. '```bash',
  587. `node ${quotedPath(runner)} --brand "样板门店A" --industry "本地生活餐饮" --platform douyin --collection-mode sample --keywords "南昌菜,第一次来怎么点,排队" --assistant-message-only`,
  588. '```',
  589. '',
  590. '真实采集时把 `--collection-mode sample` 换成 `--collection-mode live`。如果工具提示没有 token、余额不足或没有样本,直接把工具正文发给用户,并保留充值/降级建议。',
  591. '',
  592. '## 交付物',
  593. '',
  594. '必须包含五段:市场和用户声音、先改哪个问题、Top问题怎么解决、下周账号发什么、第一条口播稿。',
  595. ''
  596. ].join('\n');
  597. }
  598. function writeWorkspaceSkillEntries(targetDir) {
  599. const xhsSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'xiaohongshu-trend-intelligence');
  600. const douyinSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'douyin-trend-intelligence');
  601. const issuePoolSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-issue-pool');
  602. const deepDiveSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-problem-deep-dive');
  603. const contentPlanSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-content-plan');
  604. const speakingScriptSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-speaking-script');
  605. const competitorMapSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-competitor-map');
  606. const businessWorkflowSkillDir = path.join(WORKSPACE_ROOT, '.claude', 'skills', 'voc-business-workflow');
  607. ensureDir(xhsSkillDir);
  608. ensureDir(douyinSkillDir);
  609. ensureDir(issuePoolSkillDir);
  610. ensureDir(deepDiveSkillDir);
  611. ensureDir(contentPlanSkillDir);
  612. ensureDir(speakingScriptSkillDir);
  613. ensureDir(competitorMapSkillDir);
  614. ensureDir(businessWorkflowSkillDir);
  615. fs.writeFileSync(path.join(xhsSkillDir, 'SKILL.md'), workspaceSkillText(targetDir), 'utf8');
  616. fs.writeFileSync(path.join(douyinSkillDir, 'SKILL.md'), workspaceDouyinSkillText(targetDir), 'utf8');
  617. fs.writeFileSync(path.join(issuePoolSkillDir, 'SKILL.md'), workspaceIssuePoolSkillText(targetDir), 'utf8');
  618. fs.writeFileSync(path.join(deepDiveSkillDir, 'SKILL.md'), workspaceProblemDeepDiveSkillText(targetDir), 'utf8');
  619. fs.writeFileSync(path.join(contentPlanSkillDir, 'SKILL.md'), workspaceContentPlanSkillText(targetDir), 'utf8');
  620. fs.writeFileSync(path.join(speakingScriptSkillDir, 'SKILL.md'), workspaceSpeakingScriptSkillText(targetDir), 'utf8');
  621. fs.writeFileSync(path.join(competitorMapSkillDir, 'SKILL.md'), workspaceCompetitorMapSkillText(targetDir), 'utf8');
  622. fs.writeFileSync(path.join(businessWorkflowSkillDir, 'SKILL.md'), workspaceBusinessWorkflowSkillText(targetDir), 'utf8');
  623. }
  624. function writeWorkspaceActivation(targetDir) {
  625. if (!isSafeWorkspaceTarget(targetDir)) return;
  626. writeWorkspaceMcpConfig(targetDir);
  627. writeWorkspaceSkillEntries(targetDir);
  628. console.log('Wrote workspace MCP config: .\\.mcp.json');
  629. console.log('Wrote workspace skill entry: .\\.claude\\skills\\xiaohongshu-trend-intelligence\\SKILL.md');
  630. console.log('Wrote workspace skill entry: .\\.claude\\skills\\douyin-trend-intelligence\\SKILL.md');
  631. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-issue-pool\\SKILL.md');
  632. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-problem-deep-dive\\SKILL.md');
  633. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-content-plan\\SKILL.md');
  634. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-speaking-script\\SKILL.md');
  635. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-competitor-map\\SKILL.md');
  636. console.log('Wrote workspace skill entry: .\\.claude\\skills\\voc-business-workflow\\SKILL.md');
  637. }
  638. function printNextSteps(targetDir) {
  639. const workspaceMode = isSafeWorkspaceTarget(targetDir);
  640. console.log('');
  641. console.log('Install complete.');
  642. console.log('');
  643. if (workspaceMode) {
  644. console.log('VSCode workspace mode is ready.');
  645. console.log('');
  646. console.log('Generated project files:');
  647. console.log(' .\\.mcp.json');
  648. console.log(' .\\.claude\\skills\\xiaohongshu-trend-intelligence\\SKILL.md');
  649. console.log(' .\\.claude\\skills\\douyin-trend-intelligence\\SKILL.md');
  650. console.log(' .\\.claude\\skills\\voc-issue-pool\\SKILL.md');
  651. console.log(' .\\.claude\\skills\\voc-problem-deep-dive\\SKILL.md');
  652. console.log(' .\\.claude\\skills\\voc-content-plan\\SKILL.md');
  653. console.log(' .\\.claude\\skills\\voc-speaking-script\\SKILL.md');
  654. console.log(' .\\.claude\\skills\\voc-competitor-map\\SKILL.md');
  655. console.log(' .\\.claude\\skills\\voc-business-workflow\\SKILL.md');
  656. console.log(' .\\.claude\\plugins\\voc-intelligence');
  657. console.log('');
  658. console.log('Restart the VSCode Claude Code session if it was already open.');
  659. } else {
  660. console.log('Claude Code CLI launch command:');
  661. console.log(` claude --plugin-dir "${targetDir}"`);
  662. }
  663. console.log('');
  664. console.log('Try this prompt in Claude Code:');
  665. console.log(' 帮我看一下南昌餐饮最近顾客在关心什么,并告诉我先改哪里、下周发什么。');
  666. console.log('');
  667. console.log('Or try:');
  668. console.log(' 帮我做一份家装全屋定制行业的小红书趋势情报。');
  669. console.log(' 先用演示样例跑通流程,不要真实采集。');
  670. console.log(' 在聊天里给我第一轮样本观察和待确认问题。');
  671. console.log('');
  672. console.log('Or try:');
  673. console.log(' 帮我做一份家装全屋定制行业的抖音趋势情报。');
  674. console.log(' 先用演示样例跑通流程,不要真实采集。');
  675. console.log(' 在聊天里给我第一轮样本观察和待确认问题。');
  676. console.log('');
  677. console.log(`Install target: ${targetDir}`);
  678. }
  679. function install(opts) {
  680. checkNodeVersion();
  681. if (path.resolve(SOURCE_ROOT) !== path.resolve(opts.target)) {
  682. if (fs.existsSync(opts.target)) {
  683. if (!canOverwriteTarget(opts.target, opts)) {
  684. throw new Error(`Target already exists. Use --force to overwrite custom target: ${opts.target}`);
  685. }
  686. fs.rmSync(opts.target, { recursive: true, force: true });
  687. }
  688. ensureDir(opts.target);
  689. const copied = copyDirRecursive(SOURCE_ROOT, opts.target);
  690. console.log(`Copied skill package files: ${copied}`);
  691. }
  692. assertInstalled(opts.target);
  693. writeMcpConfig(opts.target);
  694. writeWorkspaceActivation(opts.target);
  695. if (!opts.skipInstall) {
  696. console.log('Installing runtime dependencies...');
  697. run('npm', ['install', '--omit=dev', '--ignore-scripts'], opts.target);
  698. }
  699. if (opts.smoke) {
  700. console.log('Running install smoke checks...');
  701. run(process.execPath, ['install.js', '--smoke', '--skip-install', '--no-next'], opts.target);
  702. } else {
  703. run(process.execPath, ['install.js', '--check', '--no-next'], opts.target);
  704. }
  705. printNextSteps(opts.target);
  706. }
  707. function check(opts) {
  708. assertInstalled(opts.target);
  709. run(process.execPath, ['install.js', '--check', '--no-next'], opts.target);
  710. }
  711. function smoke(opts) {
  712. assertInstalled(opts.target);
  713. run(process.execPath, ['install.js', '--smoke', '--skip-install', '--no-next'], opts.target);
  714. }
  715. function printPath(opts) {
  716. console.log(opts.target);
  717. if (isSafeWorkspaceTarget(opts.target)) {
  718. console.log('.\\.claude\\plugins\\voc-intelligence');
  719. } else {
  720. console.log(`claude --plugin-dir "${opts.target}"`);
  721. }
  722. }
  723. function main() {
  724. const opts = parseArgs(process.argv.slice(2));
  725. if (opts.help || opts.command === 'help') {
  726. console.log(usage());
  727. return;
  728. }
  729. if (opts.command === 'install') return install(opts);
  730. if (opts.command === 'check') return check(opts);
  731. if (opts.command === 'smoke') return smoke(opts);
  732. if (opts.command === 'path') return printPath(opts);
  733. throw new Error(`Unknown command: ${opts.command}\n\n${usage()}`);
  734. }
  735. try {
  736. main();
  737. } catch (error) {
  738. console.error('');
  739. console.error(`claude-voc failed: ${error.message}`);
  740. process.exit(1);
  741. }