Skip to content

Commit c520b87

Browse files
committed
working
1 parent fa4c794 commit c520b87

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Package } from "./shared/package"
2222
import { formatLanguage } from "./shared/language"
2323
import { ContextProxy } from "./core/config/ContextProxy"
2424
import { ClineProvider } from "./core/webview/ClineProvider"
25+
import { getAllModesInfo } from "./shared/modes"
2526
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
2627
import { TerminalRegistry } from "./integrations/terminal/TerminalRegistry"
2728
import { McpServerManager } from "./services/mcp/McpServerManager"
@@ -147,6 +148,16 @@ export async function activate(context: vscode.ExtensionContext) {
147148
{ ...bridgeConfig, provider, sessionId: vscode.env.sessionId },
148149
(message: string) => outputChannel.appendLine(message),
149150
)
151+
152+
// Send available modes to the bridge
153+
const bridgeInstance = ExtensionBridgeService.getInstance()
154+
if (bridgeInstance && provider) {
155+
const customModes = await provider.customModesManager.getCustomModes()
156+
const modesInfo = getAllModesInfo(customModes)
157+
158+
await bridgeInstance.setAvailableModes(modesInfo)
159+
outputChannel.appendLine(`[CloudService] Sent ${modesInfo.length} modes to bridge`)
160+
}
150161
})
151162

152163
// Add to subscriptions for proper cleanup on deactivate.

src/shared/__tests__/modes.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, it, expect } from "vitest"
2+
import { getAllModesInfo } from "../modes"
3+
import { ModeConfig } from "@roo-code/types"
4+
5+
describe("getAllModesInfo", () => {
6+
it("should return slug and name for all built-in modes", () => {
7+
const modesInfo = getAllModesInfo()
8+
9+
// Should have multiple modes
10+
expect(modesInfo.length).toBeGreaterThan(0)
11+
12+
// Each mode should have slug and name
13+
modesInfo.forEach((mode) => {
14+
expect(mode).toHaveProperty("slug")
15+
expect(mode).toHaveProperty("name")
16+
expect(typeof mode.slug).toBe("string")
17+
expect(typeof mode.name).toBe("string")
18+
expect(mode.slug).toBeTruthy()
19+
expect(mode.name).toBeTruthy()
20+
})
21+
22+
// Check that we have some expected built-in modes
23+
const slugs = modesInfo.map((m) => m.slug)
24+
expect(slugs).toContain("code")
25+
expect(slugs).toContain("architect")
26+
expect(slugs).toContain("ask")
27+
})
28+
29+
it("should include custom modes when provided", () => {
30+
const customModes: ModeConfig[] = [
31+
{
32+
slug: "custom-test",
33+
name: "Custom Test Mode",
34+
roleDefinition: "Test role",
35+
groups: ["read"],
36+
},
37+
]
38+
39+
const modesInfo = getAllModesInfo(customModes)
40+
41+
// Should include the custom mode
42+
const customMode = modesInfo.find((m) => m.slug === "custom-test")
43+
expect(customMode).toBeDefined()
44+
expect(customMode?.name).toBe("Custom Test Mode")
45+
})
46+
47+
it("should override built-in modes with custom modes of the same slug", () => {
48+
const customModes: ModeConfig[] = [
49+
{
50+
slug: "code",
51+
name: "Custom Code Mode",
52+
roleDefinition: "Custom role",
53+
groups: ["read"],
54+
},
55+
]
56+
57+
const modesInfo = getAllModesInfo(customModes)
58+
59+
// Should have the custom mode name for the code slug
60+
const codeMode = modesInfo.find((m) => m.slug === "code")
61+
expect(codeMode).toBeDefined()
62+
expect(codeMode?.name).toBe("Custom Code Mode")
63+
64+
// Should not have duplicate entries
65+
const codeModes = modesInfo.filter((m) => m.slug === "code")
66+
expect(codeModes.length).toBe(1)
67+
})
68+
})

src/shared/modes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ export function getAllModes(customModes?: ModeConfig[]): ModeConfig[] {
109109
return allModes
110110
}
111111

112+
// Get all mode slugs and display names (in the same precedence order as getAllModes).
113+
// Custom modes override built-in modes when slugs collide.
114+
export function getAllModesInfo(customModes?: ModeConfig[]): Array<{ slug: string; name: string }> {
115+
return getAllModes(customModes).map((m) => ({ slug: m.slug, name: m.name }))
116+
}
117+
112118
// Check if a mode is custom or an override
113119
export function isCustomMode(slug: string, customModes?: ModeConfig[]): boolean {
114120
return !!customModes?.some((mode) => mode.slug === slug)

0 commit comments

Comments
 (0)