| 1 | import { execSync } from "child_process"; |
| 2 | |
| 3 | import chalk from "chalk"; |
| 4 | |
| 5 | import { |
| 6 | isAuthenticated, |
| 7 | isAuthenticatedConfig, |
| 8 | loadAuthConfig, |
| 9 | } from "./auth/workos.js"; |
| 10 | import { services } from "./services/index.js"; |
| 11 | import { getCurrentSession, getSessionFilePath } from "./session.js"; |
| 12 | import { posthogService } from "./telemetry/posthogService.js"; |
| 13 | import { logger } from "./util/logger.js"; |
| 14 | import { getVersion } from "./version.js"; |
| 15 | |
| 16 | export async function handleInfoSlashCommand() { |
| 17 | posthogService.capture("useSlashCommand", { name: "info" }); |
| 18 | |
| 19 | const infoLines = []; |
| 20 | |
| 21 | // Version and working directory info |
| 22 | const version = getVersion(); |
| 23 | const cwd = process.cwd(); |
| 24 | |
| 25 | infoLines.push( |
| 26 | chalk.white("CLI Information:"), |
| 27 | ` Version: ${chalk.green(version)}`, |
| 28 | ` Working Directory: ${chalk.blue(cwd)}`, |
| 29 | ); |
| 30 | |
| 31 | // Auth info |
| 32 | if (isAuthenticated()) { |
| 33 | const config = loadAuthConfig(); |
| 34 | if (config && isAuthenticatedConfig(config)) { |
| 35 | const email = config.userEmail || config.userId; |
| 36 | const orgId = config.organizationId; |
| 37 | infoLines.push( |
| 38 | "", |
| 39 | chalk.white("Authentication:"), |
| 40 | ` Email: ${chalk.green(email)}`, |
| 41 | ` Org ID: ${chalk.cyan(orgId)}`, |
| 42 | ); |
| 43 | } else { |
| 44 | infoLines.push( |
| 45 | "", |
| 46 | chalk.white("Authentication:"), |
| 47 | ` ${chalk.yellow("Authenticated via environment variable")}`, |
| 48 | ); |
| 49 | } |
| 50 | } else { |
| 51 | infoLines.push( |
| 52 | "", |
| 53 | chalk.white("Authentication:"), |
| 54 | ` ${chalk.red("Not logged in")}`, |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | // Config info |
| 59 | try { |
| 60 | const configState = services.config.getState(); |
| 61 | infoLines.push("", chalk.white("Configuration:")); |
| 62 | if (configState.config) { |
| 63 | infoLines.push(` ${chalk.gray(`Using ${configState.config?.name}`)}`); |
| 64 | } else { |
| 65 | infoLines.push(` ${chalk.red(`Config not found`)}`); |
| 66 | } |
| 67 | if (configState.configPath) { |
| 68 | infoLines.push(` Path: ${chalk.blue(configState.configPath)}`); |
| 69 | } |
| 70 | |
| 71 | // Add current model info |
| 72 | try { |
| 73 | const modelInfo = services.model?.getModelInfo(); |
| 74 | if (modelInfo) { |
| 75 | infoLines.push(` Model: ${chalk.cyan(modelInfo.name)}`); |
| 76 | } else { |
| 77 | infoLines.push(` Model: ${chalk.red("Not available")}`); |
| 78 | } |
| 79 | } catch { |
| 80 | infoLines.push(` Model: ${chalk.red("Error retrieving model info")}`); |
| 81 | } |
| 82 | } catch { |
| 83 | infoLines.push( |
| 84 | "", |
| 85 | chalk.white("Configuration:"), |
| 86 | ` ${chalk.red("Configuration service not available")}`, |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | // Session info |
| 91 | infoLines.push("", chalk.white("Session:")); |
| 92 | try { |
| 93 | const currentSession = getCurrentSession(); |
| 94 | const sessionFilePath = getSessionFilePath(); |
| 95 | infoLines.push( |
| 96 | ` Title: ${chalk.green(currentSession.title)}`, |
| 97 | ` ID: ${chalk.gray(currentSession.sessionId)}`, |
| 98 | ` File: ${chalk.blue(sessionFilePath)}`, |
| 99 | ); |
| 100 | } catch { |
| 101 | infoLines.push(` ${chalk.red("Session not available")}`); |
| 102 | } |
| 103 | |
| 104 | // Runtime diagnostic info |
| 105 | const nodePath = process.execPath; |
| 106 | const invokedPath = process.argv[1]; |
| 107 | |
| 108 | // Get npm version |
| 109 | let npmVersion = "unknown"; |
| 110 | try { |
| 111 | npmVersion = execSync("npm --version", { |
| 112 | encoding: "utf8", |
| 113 | timeout: 5000, |
| 114 | stdio: ["pipe", "pipe", "ignore"], |
| 115 | }).trim(); |
| 116 | } catch (error) { |
| 117 | // If npm command fails, fallback to "unknown" |
| 118 | logger.warn("Failed to get npm version:", error); |
| 119 | } |
| 120 | |
| 121 | // Diagnostic info |
| 122 | infoLines.push( |
| 123 | "", |
| 124 | chalk.white("Diagnostic Info"), |
| 125 | ` Currently running: npm-global (${chalk.green(npmVersion)})`, |
| 126 | ` Path: ${chalk.blue(nodePath)}`, |
| 127 | ` Invoked: ${chalk.blue(invokedPath)}`, |
| 128 | ); |
| 129 | |
| 130 | // TODO add global settings like auto update etc. |
| 131 | |
| 132 | return { |
| 133 | exit: false, |
| 134 | output: infoLines.join("\n"), |
| 135 | }; |
| 136 | } |