/**
 * Bug reporting — sends a report to the platform admin channel via IPC.
 */
import path from 'path';
import { getContext } from '../client.js';
import { writeIpcFile } from '../ipc.js';

function groupFolder(): string {
  return process.env.NANOCLAW_GROUP_FOLDER ?? '';
}

export async function sendReport(text: string, ipcDir?: string): Promise<void> {
  const dir = ipcDir ?? getContext().ipcDir;
  writeIpcFile(path.join(dir, 'messages'), {
    type: 'report',
    text,
    groupFolder: groupFolder(),
    timestamp: new Date().toISOString(),
  });
}
