Changesets · Branches · Tags · Compare
| Changeset | 3a92c1d84a026718343241e1e6fcf35b44bc5132b0e5ec70632e5474dad2d522 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-06 19:08 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-06 19:08 -07:00 |
| Parents | f679de86c340 |
2 files changed
added extensions/cli/src/infoScreen.ts +134 −0
| @@ -0,0 +1,134 @@ | ||
| 1 | +import chalk from "chalk"; | |
| 2 | +import { execSync } from "child_process"; | |
| 3 | + | |
| 4 | +import { | |
| 5 | + isAuthenticated, | |
| 6 | + isAuthenticatedConfig, | |
| 7 | + loadAuthConfig, | |
| 8 | +} from "./auth/workos.js"; | |
| 9 | +import { services } from "./services/index.js"; | |
| 10 | +import { getCurrentSession, getSessionFilePath } from "./session.js"; | |
| 11 | +import { posthogService } from "./telemetry/posthogService.js"; | |
| 12 | +import { getVersion } from "./version.js"; | |
| 13 | + | |
| 14 | +export async function handleInfoSlashCommand() { | |
| 15 | + posthogService.capture("useSlashCommand", { name: "info" }); | |
| 16 | + | |
| 17 | + const infoLines = []; | |
| 18 | + | |
| 19 | + // Version and working directory info | |
| 20 | + const version = getVersion(); | |
| 21 | + const cwd = process.cwd(); | |
| 22 | + | |
| 23 | + infoLines.push( | |
| 24 | + chalk.white("CLI Information:"), | |
| 25 | + ` Version: ${chalk.green(version)}`, | |
| 26 | + ` Working Directory: ${chalk.blue(cwd)}`, | |
| 27 | + ); | |
| 28 | + | |
| 29 | + // Auth info | |
| 30 | + if (isAuthenticated()) { | |
| 31 | + const config = loadAuthConfig(); | |
| 32 | + if (config && isAuthenticatedConfig(config)) { | |
| 33 | + const email = config.userEmail || config.userId; | |
| 34 | + const org = "(no org)"; // Organization info not available in AuthenticatedConfig | |
| 35 | + infoLines.push( | |
| 36 | + "", | |
| 37 | + chalk.white("Authentication:"), | |
| 38 | + ` Email: ${chalk.green(email)}`, | |
| 39 | + ` Organization: ${chalk.cyan(org)}`, | |
| 40 | + ); | |
| 41 | + } else { | |
| 42 | + infoLines.push( | |
| 43 | + "", | |
| 44 | + chalk.white("Authentication:"), | |
| 45 | + ` ${chalk.yellow("Authenticated via environment variable")}`, | |
| 46 | + ); | |
| 47 | + } | |
| 48 | + } else { | |
| 49 | + infoLines.push( | |
| 50 | + "", | |
| 51 | + chalk.white("Authentication:"), | |
| 52 | + ` ${chalk.red("Not logged in")}`, | |
| 53 | + ); | |
| 54 | + } | |
| 55 | + | |
| 56 | + // Config info | |
| 57 | + try { | |
| 58 | + const configState = services.config.getState(); | |
| 59 | + infoLines.push("", chalk.white("Configuration:")); | |
| 60 | + if (configState.config) { | |
| 61 | + infoLines.push(` ${chalk.gray(`Using ${configState.config?.name}`)}`); | |
| 62 | + } else { | |
| 63 | + infoLines.push(` ${chalk.red(`Config not found`)}`); | |
| 64 | + } | |
| 65 | + if (configState.configPath) { | |
| 66 | + infoLines.push(` Path: ${chalk.blue(configState.configPath)}`); | |
| 67 | + } | |
| 68 | + | |
| 69 | + // Add current model info | |
| 70 | + try { | |
| 71 | + const modelInfo = services.model?.getModelInfo(); | |
| 72 | + if (modelInfo) { | |
| 73 | + infoLines.push(` Model: ${chalk.cyan(modelInfo.name)}`); | |
| 74 | + } else { | |
| 75 | + infoLines.push(` Model: ${chalk.red("Not available")}`); | |
| 76 | + } | |
| 77 | + } catch { | |
| 78 | + infoLines.push(` Model: ${chalk.red("Error retrieving model info")}`); | |
| 79 | + } | |
| 80 | + } catch { | |
| 81 | + infoLines.push( | |
| 82 | + "", | |
| 83 | + chalk.white("Configuration:"), | |
| 84 | + ` ${chalk.red("Configuration service not available")}`, | |
| 85 | + ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + // Session info | |
| 89 | + infoLines.push("", chalk.white("Session:")); | |
| 90 | + try { | |
| 91 | + const currentSession = getCurrentSession(); | |
| 92 | + const sessionFilePath = getSessionFilePath(); | |
| 93 | + infoLines.push( | |
| 94 | + ` Title: ${chalk.green(currentSession.title)}`, | |
| 95 | + ` ID: ${chalk.gray(currentSession.sessionId)}`, | |
| 96 | + ` File: ${chalk.blue(sessionFilePath)}`, | |
| 97 | + ); | |
| 98 | + } catch { | |
| 99 | + infoLines.push(` ${chalk.red("Session not available")}`); | |
| 100 | + } | |
| 101 | + | |
| 102 | + // Runtime diagnostic info | |
| 103 | + const nodePath = process.execPath; | |
| 104 | + const invokedPath = process.argv[1]; | |
| 105 | + | |
| 106 | + // Get npm version | |
| 107 | + let npmVersion = "unknown"; | |
| 108 | + try { | |
| 109 | + npmVersion = execSync("npm --version", { | |
| 110 | + encoding: "utf8", | |
| 111 | + timeout: 5000, | |
| 112 | + stdio: ["pipe", "pipe", "ignore"], | |
| 113 | + }).trim(); | |
| 114 | + } catch (error) { | |
| 115 | + // If npm command fails, fallback to "unknown" | |
| 116 | + console.warn("Failed to get npm version:", error); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // Diagnostic info | |
| 120 | + infoLines.push( | |
| 121 | + "", | |
| 122 | + chalk.white("Diagnostic Info"), | |
| 123 | + ` Currently running: npm-global (${chalk.green(npmVersion)})`, | |
| 124 | + ` Path: ${chalk.blue(nodePath)}`, | |
| 125 | + ` Invoked: ${chalk.blue(invokedPath)}`, | |
| 126 | + ); | |
| 127 | + | |
| 128 | + // TODO add global settings like auto update etc. | |
| 129 | + | |
| 130 | + return { | |
| 131 | + exit: false, | |
| 132 | + output: infoLines.join("\n"), | |
| 133 | + }; | |
| 134 | +} |
modified extensions/cli/src/slashCommands.ts +3 −90
| @@ -7,11 +7,11 @@ | ||
| 7 | 7 | loadAuthConfig, |
| 8 | 8 | } from "./auth/workos.js"; |
| 9 | 9 | import { getAllSlashCommands } from "./commands/commands.js"; |
| 10 | +import { handleInfoSlashCommand } from "./infoScreen.js"; | |
| 10 | 11 | import { reloadService, SERVICE_NAMES, services } from "./services/index.js"; |
| 11 | -import { getCurrentSession, getSessionFilePath } from "./session.js"; | |
| 12 | +import { getCurrentSession } from "./session.js"; | |
| 12 | 13 | import { posthogService } from "./telemetry/posthogService.js"; |
| 13 | 14 | import { SlashCommandResult } from "./ui/hooks/useChat.types.js"; |
| 14 | -import { getVersion } from "./version.js"; | |
| 15 | 15 | |
| 16 | 16 | type CommandHandler = ( |
| 17 | 17 | args: string[], |
| @@ -115,93 +115,6 @@ | ||
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | -async function handleInfo() { | |
| 119 | - posthogService.capture("useSlashCommand", { name: "info" }); | |
| 120 | - | |
| 121 | - const infoLines = []; | |
| 122 | - | |
| 123 | - // Version and working directory info | |
| 124 | - const version = getVersion(); | |
| 125 | - const cwd = process.cwd(); | |
| 126 | - | |
| 127 | - infoLines.push(chalk.white("CLI Information:")); | |
| 128 | - infoLines.push(` Version: ${chalk.green(version)}`); | |
| 129 | - infoLines.push(` Working Directory: ${chalk.blue(cwd)}`); | |
| 130 | - | |
| 131 | - // Auth info | |
| 132 | - if (isAuthenticated()) { | |
| 133 | - const config = loadAuthConfig(); | |
| 134 | - if (config && isAuthenticatedConfig(config)) { | |
| 135 | - const email = config.userEmail || config.userId; | |
| 136 | - const org = "(no org)"; // Organization info not available in AuthenticatedConfig | |
| 137 | - infoLines.push(""); | |
| 138 | - infoLines.push(chalk.white("Authentication:")); | |
| 139 | - infoLines.push(` Email: ${chalk.green(email)}`); | |
| 140 | - infoLines.push(` Organization: ${chalk.cyan(org)}`); | |
| 141 | - } else { | |
| 142 | - infoLines.push(""); | |
| 143 | - infoLines.push(chalk.white("Authentication:")); | |
| 144 | - infoLines.push( | |
| 145 | - ` ${chalk.yellow("Authenticated via environment variable")}`, | |
| 146 | - ); | |
| 147 | - } | |
| 148 | - } else { | |
| 149 | - infoLines.push(""); | |
| 150 | - infoLines.push(chalk.white("Authentication:")); | |
| 151 | - infoLines.push(` ${chalk.red("Not logged in")}`); | |
| 152 | - } | |
| 153 | - | |
| 154 | - // Config info | |
| 155 | - try { | |
| 156 | - const configState = services.config.getState(); | |
| 157 | - infoLines.push(""); | |
| 158 | - infoLines.push(chalk.white("Configuration:")); | |
| 159 | - if (configState.config) { | |
| 160 | - infoLines.push(` ${chalk.gray(`Using ${configState.config?.name}`)}`); | |
| 161 | - } else { | |
| 162 | - infoLines.push(` ${chalk.red(`Config not found`)}`); | |
| 163 | - } | |
| 164 | - if (configState.configPath) { | |
| 165 | - infoLines.push(` Path: ${chalk.blue(configState.configPath)}`); | |
| 166 | - } | |
| 167 | - | |
| 168 | - // Add current model info | |
| 169 | - try { | |
| 170 | - const modelInfo = services.model?.getModelInfo(); | |
| 171 | - if (modelInfo) { | |
| 172 | - infoLines.push(` Model: ${chalk.cyan(modelInfo.name)}`); | |
| 173 | - } else { | |
| 174 | - infoLines.push(` Model: ${chalk.red("Not available")}`); | |
| 175 | - } | |
| 176 | - } catch { | |
| 177 | - infoLines.push(` Model: ${chalk.red("Error retrieving model info")}`); | |
| 178 | - } | |
| 179 | - } catch { | |
| 180 | - infoLines.push(""); | |
| 181 | - infoLines.push(chalk.white("Configuration:")); | |
| 182 | - infoLines.push(` ${chalk.red("Configuration service not available")}`); | |
| 183 | - } | |
| 184 | - | |
| 185 | - // Session info | |
| 186 | - infoLines.push(""); | |
| 187 | - infoLines.push(chalk.white("Session:")); | |
| 188 | - try { | |
| 189 | - const currentSession = getCurrentSession(); | |
| 190 | - infoLines.push(` Title: ${chalk.green(currentSession.title)}`); | |
| 191 | - infoLines.push(` ID: ${chalk.gray(currentSession.sessionId)}`); | |
| 192 | - | |
| 193 | - const sessionFilePath = getSessionFilePath(); | |
| 194 | - infoLines.push(` File: ${chalk.blue(sessionFilePath)}`); | |
| 195 | - } catch { | |
| 196 | - infoLines.push(` ${chalk.red("Session not available")}`); | |
| 197 | - } | |
| 198 | - | |
| 199 | - return { | |
| 200 | - exit: false, | |
| 201 | - output: infoLines.join("\n"), | |
| 202 | - }; | |
| 203 | -} | |
| 204 | - | |
| 205 | 118 | async function handleFork() { |
| 206 | 119 | posthogService.capture("useSlashCommand", { name: "fork" }); |
| 207 | 120 | |
| @@ -247,7 +160,7 @@ | ||
| 247 | 160 | login: handleLogin, |
| 248 | 161 | logout: handleLogout, |
| 249 | 162 | whoami: handleWhoami, |
| 250 | - info: handleInfo, | |
| 163 | + info: handleInfoSlashCommand, | |
| 251 | 164 | model: () => ({ openModelSelector: true }), |
| 252 | 165 | compact: () => { |
| 253 | 166 | posthogService.capture("useSlashCommand", { name: "compact" }); |