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