{"version":3,"file":"report-command.mjs","names":[],"sources":["../../../src/commands/report-command.ts"],"sourcesContent":["/**\n * /report, /report_opt_in, /report_opt_out commands.\n *\n * /report <description>  — File a GitHub issue (requires opt-in)\n * /report_opt_in         — Enable issue reporting for this user\n * /report_opt_out        — Disable issue reporting\n *\n * The agent is instructed to proactively suggest /report when it detects\n * bugs, errors, or UX problems. The user must opt in first.\n */\n\nimport {\n  isReportingEnabled,\n  enableReporting,\n  disableReporting,\n  fileIssue,\n  getReporterConfig,\n} from '../services/issue-reporter.js';\n\nexport const reportCommand = {\n  name: 'report',\n  description: 'File a bug report or feature request as a GitHub issue. Usage: /report <title> | <description>',\n  acceptsArgs: true,\n  requireAuth: true,\n\n  handler: async (ctx?: any) => {\n    const userId = ctx?.senderId ?? ctx?.from ?? ctx?.metadata?.senderId ?? 'owner';\n    const rawArgs = (ctx?.args ?? '').trim();\n\n    if (!rawArgs) {\n      const enabled = isReportingEnabled(userId);\n      const config = getReporterConfig(userId);\n      return {\n        text: [\n          '**Issue Reporter**',\n          '',\n          `Status: ${enabled ? 'Enabled' : 'Disabled'}`,\n          ...(config.issueCount > 0 ? [`Issues filed: ${config.issueCount}`] : []),\n          '',\n          'Usage:',\n          '  `/report <title> | <description>` — File a bug or issue',\n          '  `/report_opt_in` — Enable issue reporting',\n          '  `/report_opt_out` — Disable issue reporting',\n          '',\n          enabled\n            ? 'The agent will proactively suggest filing issues when it detects problems.'\n            : 'Run `/report_opt_in` to enable. The agent will then suggest filing issues when it notices bugs or UX problems.',\n        ].join('\\n'),\n      };\n    }\n\n    if (!isReportingEnabled(userId)) {\n      return {\n        text: 'Issue reporting is not enabled.\\n\\nRun `/report_opt_in` to enable. This is a one-time opt-in — the agent will then be able to file GitHub issues on your behalf when it detects problems.',\n      };\n    }\n\n    // Parse: \"title | description\" or just \"title\"\n    const pipeIdx = rawArgs.indexOf('|');\n    let title: string;\n    let body: string;\n    let category: 'bug' | 'feature' | 'ux' | 'question' = 'bug';\n\n    if (pipeIdx >= 0) {\n      title = rawArgs.slice(0, pipeIdx).trim();\n      body = rawArgs.slice(pipeIdx + 1).trim();\n    } else {\n      title = rawArgs;\n      body = '';\n    }\n\n    if (!title) {\n      return { text: 'Please provide a title. Usage: `/report <title> | <description>`' };\n    }\n\n    // Detect category from keywords\n    const lower = (title + ' ' + body).toLowerCase();\n    if (/\\b(feature|request|add|support|wish|want|would be nice)\\b/.test(lower)) {\n      category = 'feature';\n    } else if (/\\b(confus|unclear|ux|ui|usability|hard to|difficult)\\b/.test(lower)) {\n      category = 'ux';\n    } else if (/\\b(question|how|why|what|when)\\b/.test(lower)) {\n      category = 'question';\n    }\n\n    const result = fileIssue({ title, body, category, userId });\n\n    if ('error' in result) {\n      return { text: `Failed to file issue: ${result.error}` };\n    }\n\n    return {\n      text: `Issue filed: ${result.url}`,\n    };\n  },\n};\n\nexport const reportOptInCommand = {\n  name: 'report_opt_in',\n  description: 'Enable GitHub issue reporting. The agent can then suggest filing issues when it detects problems.',\n  acceptsArgs: false,\n  requireAuth: true,\n\n  handler: async (ctx?: any) => {\n    const userId = ctx?.senderId ?? ctx?.from ?? ctx?.metadata?.senderId ?? 'owner';\n\n    if (isReportingEnabled(userId)) {\n      return { text: 'Issue reporting is already enabled. Use `/report <title> | <description>` to file an issue.' };\n    }\n\n    enableReporting(userId);\n    return {\n      text: [\n        'Issue reporting enabled.',\n        '',\n        'From now on, the agent will proactively suggest filing GitHub issues when it detects:',\n        '  - Unexpected errors or tool failures',\n        '  - Confusing UX or missing functionality',\n        '  - Potential bugs in OpenClawnch',\n        '',\n        'You can file issues manually with `/report <title> | <description>`.',\n        'To disable, use `/report_opt_out`.',\n      ].join('\\n'),\n    };\n  },\n};\n\nexport const reportOptOutCommand = {\n  name: 'report_opt_out',\n  description: 'Disable GitHub issue reporting.',\n  acceptsArgs: false,\n  requireAuth: true,\n\n  handler: async (ctx?: any) => {\n    const userId = ctx?.senderId ?? ctx?.from ?? ctx?.metadata?.senderId ?? 'owner';\n\n    if (!isReportingEnabled(userId)) {\n      return { text: 'Issue reporting is already disabled.' };\n    }\n\n    disableReporting(userId);\n    return { text: 'Issue reporting disabled. The agent will no longer suggest filing issues.' };\n  },\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,gBAAgB;CAC3B,MAAM;CACN,aAAa;CACb,aAAa;CACb,aAAa;CAEb,SAAS,OAAO,QAAc;EAC5B,MAAM,SAAS,KAAK,YAAY,KAAK,QAAQ,KAAK,UAAU,YAAY;EACxE,MAAM,WAAW,KAAK,QAAQ,IAAI,MAAM;AAExC,MAAI,CAAC,SAAS;GACZ,MAAM,UAAU,mBAAmB,OAAO;GAC1C,MAAM,SAAS,kBAAkB,OAAO;AACxC,UAAO,EACL,MAAM;IACJ;IACA;IACA,WAAW,UAAU,YAAY;IACjC,GAAI,OAAO,aAAa,IAAI,CAAC,iBAAiB,OAAO,aAAa,GAAG,EAAE;IACvE;IACA;IACA;IACA;IACA;IACA;IACA,UACI,+EACA;IACL,CAAC,KAAK,KAAK,EACb;;AAGH,MAAI,CAAC,mBAAmB,OAAO,CAC7B,QAAO,EACL,MAAM,6LACP;EAIH,MAAM,UAAU,QAAQ,QAAQ,IAAI;EACpC,IAAI;EACJ,IAAI;EACJ,IAAI,WAAkD;AAEtD,MAAI,WAAW,GAAG;AAChB,WAAQ,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;AACxC,UAAO,QAAQ,MAAM,UAAU,EAAE,CAAC,MAAM;SACnC;AACL,WAAQ;AACR,UAAO;;AAGT,MAAI,CAAC,MACH,QAAO,EAAE,MAAM,oEAAoE;EAIrF,MAAM,SAAS,QAAQ,MAAM,MAAM,aAAa;AAChD,MAAI,4DAA4D,KAAK,MAAM,CACzE,YAAW;WACF,yDAAyD,KAAK,MAAM,CAC7E,YAAW;WACF,mCAAmC,KAAK,MAAM,CACvD,YAAW;EAGb,MAAM,SAAS,UAAU;GAAE;GAAO;GAAM;GAAU;GAAQ,CAAC;AAE3D,MAAI,WAAW,OAC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