Elffuss BraidHub

kikocis/continue public

feat: info slash command
Changeset5b5fa6eb4e4aa74696be1f85a06dfe712e34c0b3f4bd319241bf113bd718ff56
AuthorNate <sestinj@gmail.com> · 2025-08-23 10:32 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-23 10:32 -07:00
Parents231e99760742

Browse the files at this changeset

4 files changed

modified extensions/cli/src/commands/commands.ts +6 −1
@@ -4,9 +4,9 @@
44 export { chat } from "./chat.js";
55 export { login } from "./login.js";
66 export { logout } from "./logout.js";
7+export { listSessionsCommand } from "./ls.js";
78 export { remote } from "./remote.js";
89 export { serve } from "./serve.js";
9-export { listSessionsCommand } from "./ls.js";
1010
1111 export interface SlashCommand {
1212 name: string;
@@ -45,6 +45,11 @@
4545 description: "Check who you're currently logged in as",
4646 category: "system",
4747 },
48+ {
49+ name: "info",
50+ description: "Show session information",
51+ category: "system",
52+ },
4853 {
4954 name: "model",
5055 description: "Switch between available chat models",
modified extensions/cli/src/session.ts +1 −1
@@ -180,7 +180,7 @@
180180 /**
181181 * Get the session file path for the current session
182182 */
183-function getSessionFilePath(): string {
183+export function getSessionFilePath(): string {
184184 const sessionId = getSessionId();
185185 const sessionDir = getSessionDir();
186186 return path.join(sessionDir, `${sessionId}.json`);
modified extensions/cli/src/slashCommands.test.ts +160 −125
@@ -1,147 +1,182 @@
1-// Import after mocking
2-import { AssistantUnrolled } from "@continuedev/config-yaml";
3-import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
4-
5-import * as workos from "./auth/workos.js";
6-import * as commands from "./commands/commands.js";
7-import { reloadService, SERVICE_NAMES, services } from "./services/index.js";
8-import type { AuthServiceState } from "./services/types.js";
1+import type { AssistantUnrolled } from "@continuedev/config-yaml";
2+import { describe, it, expect, vi, beforeEach, type MockedFunction } from "vitest";
3+
4+import type { AuthConfig, AuthenticatedConfig } from "./auth/workos.js";
5+import type { ConfigServiceState } from "./services/types.js";
96 import { handleSlashCommands } from "./slashCommands.js";
107
11-// The imports are already mocked via vitest.setup.ts, so we can use them directly
12-
13-// Mock console to avoid output during tests
14-const originalConsole = console;
15-const mockConsole = {
16- info: vi.fn(),
17- error: vi.fn(),
18- log: vi.fn(),
19-};
20-
21-describe("handleSlashCommands", () => {
8+// Mock the services
9+vi.mock("./services/index.js", () => ({
10+ services: {
11+ config: {
12+ getState: vi.fn()
13+ }
14+ },
15+ reloadService: vi.fn(),
16+ SERVICE_NAMES: {
17+ AUTH: 'AUTH'
18+ }
19+}));
20+
21+// Mock auth functions
22+vi.mock("./auth/workos.js", () => ({
23+ isAuthenticated: vi.fn(),
24+ isAuthenticatedConfig: vi.fn(),
25+ loadAuthConfig: vi.fn()
26+}));
27+
28+// Mock telemetry
29+vi.mock("./telemetry/posthogService.js", () => ({
30+ posthogService: {
31+ capture: vi.fn()
32+ }
33+}));
34+
35+// Mock commands
36+vi.mock("./commands/commands.js", () => ({
37+ getAllSlashCommands: vi.fn(() => [])
38+}));
39+
40+// Mock os and path
41+vi.mock("os", () => ({
42+ default: {
43+ homedir: vi.fn(() => "/home/test")
44+ }
45+}));
46+
47+vi.mock("path", () => ({
48+ default: {
49+ join: vi.fn((...parts) => parts.join("/"))
50+ },
51+ join: vi.fn((...parts) => parts.join("/"))
52+}));
53+
54+// Mock session functions
55+vi.mock("./session.js", () => ({
56+ getSessionFilePath: vi.fn(() => "/home/test/.continue/cli-sessions/continue-cli-pid-12345.json"),
57+ hasSession: vi.fn(() => false)
58+}));
59+
60+describe("slashCommands", () => {
2261 const mockAssistant: AssistantUnrolled = {
2362 name: "test-assistant",
24- version: "1.0.0",
25- prompts: [{ name: "test", prompt: "Test prompt: " }],
63+ version: "1.0.0"
2664 };
2765
2866 beforeEach(() => {
29- Object.assign(console, mockConsole);
3067 vi.clearAllMocks();
31-
32- // Since the mock already returns the required value, we don't need to set it
33- // Just verify it returns what we expect
34- expect(commands.getAllSlashCommands(mockAssistant)).toEqual(
35- expect.arrayContaining([
36- expect.objectContaining({ name: "help" }),
37- expect.objectContaining({ name: "login" }),
38- ]),
39- );
4068 });
4169
42- afterEach(() => {
43- Object.assign(console, originalConsole);
44- });
45-
46- describe("Automatic Service Cascade Reloading", () => {
47- test.skip("login command should trigger automatic cascade reload via auth service", async () => {
48- const newAuthState: AuthServiceState = {
49- authConfig: { userEmail: "test@example.com" } as any,
50- isAuthenticated: true,
51- };
52-
53- (services.auth.login as any).mockResolvedValue(newAuthState);
54- (workos.isAuthenticatedConfig as any).mockReturnValue(true);
55- (reloadService as any).mockResolvedValue(undefined);
56-
57- const result = await handleSlashCommands("/login", mockAssistant);
58-
59- expect(result).not.toBeNull();
60- expect(result?.output).toContain(
61- "Login successful! All services updated automatically.",
62- );
63-
64- // Verify auth service login was called
65- expect(services.auth.login).toHaveBeenCalledTimes(1);
66-
67- // Verify automatic cascade reload was triggered - only auth service reload needed
68- expect(reloadService).toHaveBeenCalledTimes(1);
69- expect(reloadService).toHaveBeenCalledWith(SERVICE_NAMES.AUTH);
70-
71- // Verify manual service reloads are NOT called
72- expect(reloadService).not.toHaveBeenCalledWith(SERVICE_NAMES.API_CLIENT);
73- expect(reloadService).not.toHaveBeenCalledWith(SERVICE_NAMES.CONFIG);
74- });
75-
76- test.skip("login failure should not trigger any reloads", async () => {
77- const loginError = new Error("Login failed");
78- (services.auth.login as any).mockRejectedValue(loginError);
79-
80- const result = await handleSlashCommands("/login", mockAssistant);
81-
82- expect(result).not.toBeNull();
83- expect(result?.output).toContain("Login failed: Login failed");
84-
85- // Verify NO reload was triggered on failure
86- expect(reloadService).not.toHaveBeenCalled();
70+ describe("handleSlashCommands", () => {
71+ it("should handle /info command when not authenticated", async () => {
72+ const { isAuthenticated } = await import("./auth/workos.js");
73+ const { services } = await import("./services/index.js");
74+
75+ (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false);
76+ (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({
77+ config: null,
78+ configPath: "/test/config.yaml"
79+ } as ConfigServiceState);
80+
81+ const result = await handleSlashCommands("/info", mockAssistant);
82+
83+ expect(result).toBeDefined();
84+ expect(result?.output).toContain("Authentication:");
85+ expect(result?.output).toContain("Not logged in");
86+ expect(result?.output).toContain("Configuration:");
87+ expect(result?.output).toContain("/test/config.yaml");
88+ expect(result?.output).toContain("Session History:");
89+ expect(result?.output).toContain(".json");
90+ expect(result?.exit).toBe(false);
8791 });
88- });
8992
90- describe("Other Commands (unchanged behavior)", () => {
91- test("help command should work normally", async () => {
92- const result = await handleSlashCommands("/help", mockAssistant);
93-
94- expect(result).not.toBeNull();
95- expect(result?.output).toContain("Slash commands:");
96- expect(result?.output).toContain("/help: Show help");
97- expect(result?.output).toContain("/login: Authenticate");
93+ it("should handle /info command when authenticated via environment", async () => {
94+ const { isAuthenticated, loadAuthConfig, isAuthenticatedConfig } = await import("./auth/workos.js");
95+ const { services } = await import("./services/index.js");
96+
97+ (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(true);
98+ (loadAuthConfig as MockedFunction<typeof loadAuthConfig>).mockReturnValue({} as AuthConfig);
99+ (isAuthenticatedConfig as any).mockReturnValue(false);
100+ (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({
101+ config: null,
102+ configPath: undefined
103+ } as ConfigServiceState);
104+
105+ const result = await handleSlashCommands("/info", mockAssistant);
106+
107+ expect(result).toBeDefined();
108+ expect(result?.output).toContain("Authentication:");
109+ expect(result?.output).toContain("Authenticated via environment variable");
110+ expect(result?.output).toContain("Configuration:");
111+ expect(result?.output).toContain("Using default configuration");
112+ expect(result?.exit).toBe(false);
98113 });
99114
100- test.skip("logout command should exit", async () => {
101- const logoutState: AuthServiceState = {
102- authConfig: null,
103- isAuthenticated: false,
115+ it("should handle /info command when authenticated with user config", async () => {
116+ const { isAuthenticated, loadAuthConfig, isAuthenticatedConfig } = await import("./auth/workos.js");
117+ const { services } = await import("./services/index.js");
118+
119+ const mockAuthConfig: AuthenticatedConfig = {
120+ userId: "test-user-id",
121+ userEmail: "test@example.com",
122+ accessToken: "test-token",
123+ refreshToken: "test-refresh-token",
124+ expiresAt: Date.now() + 3600000,
125+ organizationId: "test-org-id"
104126 };
105- (services.auth.logout as any).mockResolvedValue(logoutState);
106-
107- const result = await handleSlashCommands("/logout", mockAssistant);
108-
109- expect(result).not.toBeNull();
110- expect(result?.exit).toBe(true);
111- expect(result?.output).toContain("Logged out successfully");
112- });
113127
114- test("clear command should work normally", async () => {
115- const result = await handleSlashCommands("/clear", mockAssistant);
116-
117- expect(result).not.toBeNull();
118- expect(result?.clear).toBe(true);
119- expect(result?.output).toBe("Chat history cleared");
120- });
121-
122- test("compact command should work normally", async () => {
123- const result = await handleSlashCommands("/compact", mockAssistant);
124-
125- expect(result).not.toBeNull();
126- expect(result?.compact).toBe(true);
128+ (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(true);
129+ (loadAuthConfig as MockedFunction<typeof loadAuthConfig>).mockReturnValue(mockAuthConfig);
130+ (isAuthenticatedConfig as any).mockReturnValue(true);
131+ (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({
132+ config: null,
133+ configPath: "/custom/config.yaml"
134+ } as ConfigServiceState);
135+
136+ const result = await handleSlashCommands("/info", mockAssistant);
137+
138+ expect(result).toBeDefined();
139+ expect(result?.output).toContain("Authentication:");
140+ expect(result?.output).toContain("test@example.com");
141+ expect(result?.output).toContain("(no org)");
142+ expect(result?.output).toContain("Configuration:");
143+ expect(result?.output).toContain("/custom/config.yaml");
144+ expect(result?.exit).toBe(false);
127145 });
128146
129- test("resume command should open session selector", async () => {
130- const result = await handleSlashCommands("/resume", mockAssistant);
131-
132- expect(result).not.toBeNull();
133- expect(result?.openSessionSelector).toBe(true);
134- });
135-
136- test("non-slash input should return null", async () => {
137- const result = await handleSlashCommands("regular input", mockAssistant);
138- expect(result).toBeNull();
147+ it("should handle config service errors gracefully", async () => {
148+ const { isAuthenticated } = await import("./auth/workos.js");
149+ const { services } = await import("./services/index.js");
150+
151+ (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false);
152+ (services.config.getState as MockedFunction<typeof services.config.getState>).mockImplementation(() => {
153+ throw new Error("Service not ready");
154+ });
155+
156+ const result = await handleSlashCommands("/info", mockAssistant);
157+
158+ expect(result).toBeDefined();
159+ expect(result?.output).toContain("Configuration service not available");
139160 });
140161
141- test("unknown slash command should return null", async () => {
142- const result = await handleSlashCommands("/unknown", mockAssistant);
143-
144- expect(result).toBeNull();
162+ it("should use test session directory when in test mode", async () => {
163+ const { isAuthenticated } = await import("./auth/workos.js");
164+ const { services } = await import("./services/index.js");
165+ const { getSessionFilePath } = await import("./session.js");
166+
167+ // Mock the session path for this specific test
168+ (getSessionFilePath as any).mockReturnValue("/test-home/.continue/cli-sessions/continue-cli-test-123.json");
169+
170+ (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false);
171+ (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({
172+ config: null,
173+ configPath: undefined
174+ } as ConfigServiceState);
175+
176+ const result = await handleSlashCommands("/info", mockAssistant);
177+
178+ expect(result?.output).toContain("/test-home/.continue/cli-sessions/");
179+ expect(result?.output).toContain(".json");
145180 });
146181 });
147-});
182+});
No newline at the end of the file
modified extensions/cli/src/slashCommands.ts +59 −0
@@ -8,6 +8,7 @@
88 } from "./auth/workos.js";
99 import { getAllSlashCommands } from "./commands/commands.js";
1010 import { reloadService, SERVICE_NAMES, services } from "./services/index.js";
11+import { getSessionFilePath } from "./session.js";
1112 import { posthogService } from "./telemetry/posthogService.js";
1213 import { SlashCommandResult } from "./ui/hooks/useChat.types.js";
1314
@@ -96,6 +97,63 @@
9697 }
9798 }
9899
100+async function handleInfo() {
101+ posthogService.capture("useSlashCommand", { name: "info" });
102+
103+ const infoLines = [];
104+
105+ // Auth info
106+ if (isAuthenticated()) {
107+ const config = loadAuthConfig();
108+ if (config && isAuthenticatedConfig(config)) {
109+ const email = config.userEmail || config.userId;
110+ const org = "(no org)"; // Organization info not available in AuthenticatedConfig
111+ infoLines.push(chalk.white("Authentication:"));
112+ infoLines.push(` Email: ${chalk.green(email)}`);
113+ infoLines.push(` Organization: ${chalk.cyan(org)}`);
114+ } else {
115+ infoLines.push(chalk.white("Authentication:"));
116+ infoLines.push(
117+ ` ${chalk.yellow("Authenticated via environment variable")}`,
118+ );
119+ }
120+ } else {
121+ infoLines.push(chalk.white("Authentication:"));
122+ infoLines.push(` ${chalk.red("Not logged in")}`);
123+ }
124+
125+ // Config info
126+ try {
127+ const configState = services.config.getState();
128+ infoLines.push("");
129+ infoLines.push(chalk.white("Configuration:"));
130+ if (configState.config) {
131+ infoLines.push(` ${chalk.gray(`Using ${configState.config?.name}`)}`);
132+ } else {
133+ infoLines.push(` ${chalk.red(`Config not found`)}`);
134+ }
135+ if (configState.configPath) {
136+ infoLines.push(` Path: ${chalk.blue(configState.configPath)}`);
137+ }
138+ } catch {
139+ infoLines.push("");
140+ infoLines.push(chalk.white("Configuration:"));
141+ infoLines.push(` ${chalk.red("Configuration service not available")}`);
142+ }
143+
144+ // Session history path
145+ infoLines.push("");
146+ infoLines.push(chalk.white("Session History:"));
147+ const sessionFilePath = getSessionFilePath();
148+
149+ infoLines.push(` File: ${chalk.blue(sessionFilePath)}`);
150+
151+ return {
152+ exit: false,
153+ output: infoLines.join("\n"),
154+ };
155+}
156+
99157 const commandHandlers: Record<string, CommandHandler> = {
100158 help: handleHelp,
101159 clear: () => {
@@ -113,6 +171,7 @@
113171 login: handleLogin,
114172 logout: handleLogout,
115173 whoami: handleWhoami,
174+ info: handleInfo,
116175 model: () => ({ openModelSelector: true }),
117176 compact: () => {
118177 posthogService.capture("useSlashCommand", { name: "compact" });