claude-voc.js 35 KB

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