claude-voc.js 34 KB

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