|
| 1 | +const { execSync } = require("child_process") |
| 2 | +const readline = require("readline") |
| 3 | +const os = require("os") |
| 4 | + |
| 5 | +const rl = readline.createInterface({ |
| 6 | + input: process.stdin, |
| 7 | + output: process.stdout, |
| 8 | +}) |
| 9 | + |
| 10 | +const ask = (question) => new Promise((resolve) => rl.question(`\n${question}`, resolve)) |
| 11 | + |
| 12 | +const getClineVersion = () => { |
| 13 | + try { |
| 14 | + const extensions = execSync("code --list-extensions --show-versions").toString() |
| 15 | + const clineMatch = extensions.match(/claude-dev@(\d+\.\d+\.\d+)/) |
| 16 | + return clineMatch ? clineMatch[1] : "Not installed" |
| 17 | + } catch (err) { |
| 18 | + return "Error getting version" |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +const collectSystemInfo = () => { |
| 23 | + let cpuInfo = "N/A" |
| 24 | + let memoryInfo = "N/A" |
| 25 | + try { |
| 26 | + if (process.platform === "darwin") { |
| 27 | + cpuInfo = execSync("sysctl -n machdep.cpu.brand_string").toString().trim() |
| 28 | + memoryInfo = execSync("sysctl -n hw.memsize").toString().trim() |
| 29 | + memoryInfo = `${Math.round(parseInt(memoryInfo) / 1e9)} GB RAM` |
| 30 | + } else { |
| 31 | + // Linux specific commands |
| 32 | + cpuInfo = execSync("lscpu").toString().split("\n").slice(0, 5).join("\n") |
| 33 | + memoryInfo = execSync("free -h").toString() |
| 34 | + } |
| 35 | + } catch (err) { |
| 36 | + // Fallback for unsupported systems |
| 37 | + cpuInfo = Array.from(new Set(os.cpus().map((c) => c.model))).join("\n") |
| 38 | + memoryInfo = `${Math.round(os.totalmem() / 1e9)} GB RAM` |
| 39 | + } |
| 40 | + |
| 41 | + return { |
| 42 | + cpuInfo, |
| 43 | + memoryInfo, |
| 44 | + os: `${os.arch()}; ${os.version()}`, |
| 45 | + nodeVersion: execSync("node -v").toString().trim(), |
| 46 | + npmVersion: execSync("npm -v").toString().trim(), |
| 47 | + clineVersion: getClineVersion(), |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +const checkGitHubAuth = async () => { |
| 52 | + try { |
| 53 | + execSync("gh auth status", { stdio: "ignore" }) |
| 54 | + return true |
| 55 | + } catch (err) { |
| 56 | + console.log("\nGitHub authentication required.") |
| 57 | + console.log("\nPlease run the following command in your terminal to authenticate:") |
| 58 | + console.log("\n gh auth login\n") |
| 59 | + console.log("After authenticating, run this script again.") |
| 60 | + return false |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +const createIssueUrl = (systemInfo, issueTitle) => { |
| 65 | + return ( |
| 66 | + `https://github.com/cline/cline/issues/new?template=bug_report.yml` + |
| 67 | + `&title=${issueTitle}` + |
| 68 | + `&operating-system=${systemInfo.os}` + |
| 69 | + `&cline-version=${systemInfo.clineVersion}` + |
| 70 | + `&system-info=${ |
| 71 | + `Node: ${systemInfo.nodeVersion}\n` + |
| 72 | + `npm: ${systemInfo.npmVersion}\n` + |
| 73 | + `CPU Info: ${systemInfo.cpuInfo}\n` + |
| 74 | + `Free RAM: ${systemInfo.memoryInfo}` |
| 75 | + }` |
| 76 | + ) |
| 77 | +} |
| 78 | + |
| 79 | +const openUrl = (url) => { |
| 80 | + try { |
| 81 | + switch (process.platform) { |
| 82 | + case "darwin": |
| 83 | + execSync(`open "${url}"`) |
| 84 | + break |
| 85 | + case "win32": |
| 86 | + execSync(`start "" "${url}"`) |
| 87 | + break |
| 88 | + case "linux": |
| 89 | + execSync(`xdg-open "${url}"`) |
| 90 | + break |
| 91 | + default: |
| 92 | + console.log("\nPlease open this URL in your browser:") |
| 93 | + console.log(url) |
| 94 | + } |
| 95 | + } catch (err) { |
| 96 | + console.log("\nFailed to open URL automatically. Please open this URL in your browser:") |
| 97 | + console.log(url) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +const submitIssue = async (issueTitle, systemInfo) => { |
| 102 | + try { |
| 103 | + const issueUrl = createIssueUrl(systemInfo, issueTitle) |
| 104 | + console.log("\nOpening GitHub issue creation page in your browser...") |
| 105 | + openUrl(issueUrl) |
| 106 | + } catch (err) { |
| 107 | + console.error("\nFailed to create issue URL:", err.message) |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +async function main() { |
| 112 | + const consent = await ask("Do you consent to collect system data and submit a GitHub issue? (y/n): ") |
| 113 | + if (consent.trim().toLowerCase() !== "y") { |
| 114 | + console.log("\nAborted.") |
| 115 | + rl.close() |
| 116 | + return |
| 117 | + } |
| 118 | + |
| 119 | + console.log("Collecting system data...") |
| 120 | + const systemInfo = collectSystemInfo() |
| 121 | + |
| 122 | + const isAuthenticated = await checkGitHubAuth() |
| 123 | + if (!isAuthenticated) { |
| 124 | + rl.close() |
| 125 | + return |
| 126 | + } |
| 127 | + |
| 128 | + const issueTitle = await ask("Enter the title for your issue: ") |
| 129 | + |
| 130 | + await submitIssue(issueTitle, systemInfo) |
| 131 | + rl.close() |
| 132 | +} |
| 133 | + |
| 134 | +main().catch((err) => { |
| 135 | + console.error("\nAn error occurred:", err) |
| 136 | + rl.close() |
| 137 | +}) |
0 commit comments