Elffuss BraidHub

kikocis/continue public

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