Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ reviews:
instructions: >-
Act as an adversarial second-opinion reviewer. Verify PR claims against implementation and
contracts. Trace changed inputs through normal, boundary, error, cancellation, retry, and
default paths and their consumers. Seek plausible counterexamples and regressions from removed
safeguards. Identify assumptions in changed code that depend on facts outside the diff. First
verify repository conventions, tests, and related implementations. When a potential finding
depends on external behavior, use web search and prefer official documentation, specifications,
or upstream repositories. Report only concrete, actionable conflicts or failure modes, citing
the relevant repository location or external source. Prioritize correctness, security, data loss,
lifecycle, and test gaps. Do not report generic best practices, unsupported concerns, speculative
style comments, or unrelated refactors. When changed code introduces a local implementation of a
cross-cutting concern, check whether it bypasses or duplicates an established repository abstraction
or nearby convention. Report only a concrete inconsistency with behavioral or maintenance impact,
and allow intentional deviations.
default paths and their direct test counterparts. Do not flag defects in files not changed by
this PR unless the defect is directly triggered by changed code and cannot be detected in the
changed file alone. Seek plausible counterexamples and regressions from removed safeguards.
Identify assumptions in changed code that depend on facts outside the diff. First verify
repository conventions, tests, and related implementations. When a potential finding depends on
external behavior, use web search and prefer official documentation, specifications, or upstream
repositories. Report only concrete, actionable conflicts or failure modes, citing the relevant
repository location or external source. Prioritize correctness, security, data loss, lifecycle,
and test gaps. Do not report generic best practices, unsupported concerns, speculative style
comments, or unrelated refactors. When changed code introduces a local implementation of a
cross-cutting concern, check whether it bypasses or duplicates an established repository
abstraction or nearby convention. Report only a concrete inconsistency with behavioral or
maintenance impact, and allow intentional deviations.

- path: "**/*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}"
instructions: >-
Expand Down
12 changes: 8 additions & 4 deletions src/__tests__/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ vi.mock("../services/mcp/McpServerManager", () => ({
},
}))

vi.mock("../services/code-index/manager", () => ({
CodeIndexManager: {
getInstance: vi.fn().mockReturnValue(null),
vi.mock("../services/code-index/code-index-manager-registry", () => ({
CodeIndexManagerRegistry: {
getOrCreate: vi.fn().mockReturnValue(null),
disposeAll: vi.fn(),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
}))

Expand Down Expand Up @@ -463,6 +464,7 @@ describe("extension.ts", () => {
const { TelemetryService } = await import("@roo-code/telemetry")
const { Terminal } = await import("../integrations/terminal/Terminal")
const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry")
const { CodeIndexManagerRegistry } = await import("../services/code-index/code-index-manager-registry")

vi.mocked(TelemetryService.instance.shutdown).mockRejectedValue(new Error("shutdown failed"))
const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile")
Expand All @@ -474,6 +476,7 @@ describe("extension.ts", () => {

expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined)
expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1)
expect(CodeIndexManagerRegistry.disposeAll).toHaveBeenCalledTimes(1)

setTerminalProfileSpy.mockRestore()
})
Expand All @@ -486,6 +489,7 @@ describe("extension.ts", () => {
const { TelemetryService } = await import("@roo-code/telemetry")
const { Terminal } = await import("../integrations/terminal/Terminal")
const { TerminalRegistry } = await import("../integrations/terminal/TerminalRegistry")
const { CodeIndexManagerRegistry } = await import("../services/code-index/code-index-manager-registry")

const setTerminalProfileSpy = vi.spyOn(Terminal, "setTerminalProfile")

Expand All @@ -509,9 +513,9 @@ describe("extension.ts", () => {
expect(mockTelemetryServiceInstance.shutdown).not.toHaveBeenCalled()
expect(setTerminalProfileSpy).toHaveBeenCalledWith(undefined)
expect(TerminalRegistry.cleanup).toHaveBeenCalledTimes(1)
expect(CodeIndexManagerRegistry.disposeAll).toHaveBeenCalledTimes(1)

instanceGetterSpy.mockRestore()

setTerminalProfileSpy.mockRestore()
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/activate/__tests__/registerCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ vi.mock("../../core/config/importExport", () => ({
importSettingsWithFeedback: vi.fn(),
}))

vi.mock("../../services/code-index/manager", () => ({
CodeIndexManager: {
getInstance: vi.fn(),
vi.mock("../../services/code-index/code-index-manager-registry", () => ({
CodeIndexManagerRegistry: {
getOrCreate: vi.fn(),
},
}))

Expand Down
2 changes: 0 additions & 2 deletions src/activate/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ClineProvider } from "../core/webview/ClineProvider"
import { ContextProxy } from "../core/config/ContextProxy"
import { focusPanel } from "../utils/focusPanel"
import { handleNewTask } from "./handleTask"
import { CodeIndexManager } from "../services/code-index/manager"
import { importSettingsWithFeedback } from "../core/config/importExport"
import { MdmService } from "../services/mdm/MdmService"
import { registerRipgrepDiagnosticCommand } from "../services/ripgrep/diagnostic"
Expand Down Expand Up @@ -227,7 +226,6 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit<Registe
// don't need to use that event).
// https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
const contextProxy = await ContextProxy.getInstance(context)
const codeIndexManager = CodeIndexManager.getInstance(context)

// Get the existing MDM service instance to ensure consistent policy enforcement
let mdmService: MdmService | undefined
Expand Down
4 changes: 2 additions & 2 deletions src/core/prompts/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatLanguage } from "../../shared/language"
import { isEmpty } from "../../utils/object"

import { McpHub } from "../../services/mcp/McpHub"
import { CodeIndexManager } from "../../services/code-index/manager"
import { CodeIndexManagerRegistry } from "../../services/code-index/code-index-manager-registry"
import { SkillsManager } from "../../services/skills/SkillsManager"

import type { SystemPromptSettings } from "./types"
Expand Down Expand Up @@ -79,7 +79,7 @@ async function generatePrompt(
}
const shouldIncludeMcp = hasMcpGroup && hasMcpServers

const codeIndexManager = CodeIndexManager.getInstance(context, cwd)
const codeIndexManager = CodeIndexManagerRegistry.getOrCreate(context, cwd)

// Tool calling is native-only.
const effectiveProtocol = "native"
Expand Down
9 changes: 9 additions & 0 deletions src/core/task/__tests__/Task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ vi.mock("p-wait-for", () => ({
default: vi.fn().mockImplementation(async () => Promise.resolve()),
}))

// Task tests do not exercise indexing; keep workspace resolution and its cache out of this suite.
vi.mock("../../../services/code-index/code-index-manager-registry", () => ({
CodeIndexManagerRegistry: {
getOrCreate: vi.fn().mockReturnValue(undefined),
getAllInstances: vi.fn().mockReturnValue([]),
disposeAll: vi.fn(),
},
}))

vi.mock("vscode", () => {
const mockDisposable = { dispose: vi.fn() }
const mockEventEmitter = { event: vi.fn(), fire: vi.fn() }
Expand Down
4 changes: 2 additions & 2 deletions src/core/task/build-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export async function buildNativeToolsArrayWithRestrictions(options: BuildToolsO
const mcpHub = provider.getMcpHub()

// Get CodeIndexManager for feature checking.
const { CodeIndexManager } = await import("../../services/code-index/manager")
const codeIndexManager = CodeIndexManager.getInstance(provider.context, cwd)
const { CodeIndexManagerRegistry } = await import("../../services/code-index/code-index-manager-registry")
const codeIndexManager = CodeIndexManagerRegistry.getOrCreate(provider.context, cwd)

// Build settings object for tool filtering.
const filterSettings = {
Expand Down
4 changes: 2 additions & 2 deletions src/core/tools/CodebaseSearchTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode"
import path from "path"

import { Task } from "../task/Task"
import { CodeIndexManager } from "../../services/code-index/manager"
import { CodeIndexManagerRegistry } from "../../services/code-index/code-index-manager-registry"
import { getWorkspacePath } from "../../utils/path"
import { formatResponse } from "../prompts/responses"
import { VectorStoreSearchResult } from "../../services/code-index/interfaces"
Expand Down Expand Up @@ -57,7 +57,7 @@ export class CodebaseSearchTool extends BaseTool<"codebase_search"> {
throw new Error("Extension context is not available.")
}

const manager = CodeIndexManager.getInstance(context)
const manager = CodeIndexManagerRegistry.getOrCreate(context)

if (!manager) {
throw new Error("CodeIndexManager is not available.")
Expand Down
5 changes: 3 additions & 2 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ import { McpHub } from "../../services/mcp/McpHub"
import { McpServerManager } from "../../services/mcp/McpServerManager"
import { MarketplaceManager } from "../../services/marketplace"
import { ShadowCheckpointService } from "../../services/checkpoints/ShadowCheckpointService"
import { CodeIndexManager } from "../../services/code-index/manager"
import type { CodeIndexManager } from "../../services/code-index/manager"
import { CodeIndexManagerRegistry } from "../../services/code-index/code-index-manager-registry"
import type { IndexProgressUpdate } from "../../services/code-index/interfaces/manager"
import { MdmService } from "../../services/mdm/MdmService"
import { SkillsManager } from "../../services/skills/SkillsManager"
Expand Down Expand Up @@ -3307,7 +3308,7 @@ export class ClineProvider
* @returns CodeIndexManager instance for the current workspace or the default one
*/
public getCurrentWorkspaceCodeIndexManager(): CodeIndexManager | undefined {
return CodeIndexManager.getInstance(this.context)
return CodeIndexManagerRegistry.getOrCreate(this.context)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/webview/__tests__/ClineProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ describe("webviewMessageHandler no-floating-promises coverage", () => {
})

it("catches auto-enabled indexing failures and posts the resulting status", async () => {
const { CodeIndexManager } = await import("../../../services/code-index/manager")
const { CodeIndexManagerRegistry } = await import("../../../services/code-index/code-index-manager-registry")
let workspaceEnabled = false
const manager = createIndexManager({
setAutoEnableDefault: vi.fn().mockImplementation(async () => {
Expand All @@ -3235,8 +3235,8 @@ describe("webviewMessageHandler no-floating-promises coverage", () => {
})
Object.defineProperty(manager, "isWorkspaceEnabled", { get: () => workspaceEnabled })
const getAllInstances = vi
.spyOn(CodeIndexManager, "getAllInstances")
.mockReturnValue([manager] as unknown as ReturnType<typeof CodeIndexManager.getAllInstances>)
.spyOn(CodeIndexManagerRegistry, "getAllInstances")
.mockReturnValue([manager] as unknown as ReturnType<typeof CodeIndexManagerRegistry.getAllInstances>)
const provider = createProvider({
getCurrentWorkspaceCodeIndexManager: vi.fn().mockReturnValue(manager),
})
Expand Down
4 changes: 2 additions & 2 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { Package } from "../../shared/package"
import { type RouterName, toRouterName } from "../../shared/api"
import { MessageEnhancer } from "./messageEnhancer"

import { CodeIndexManager } from "../../services/code-index/manager"
import { CodeIndexManagerRegistry } from "../../services/code-index/code-index-manager-registry"
import { checkExistKey } from "../../shared/checkExistApiConfig"
import { getRouterRemovalMessage, getRouterUnavailableSignInMessage } from "../config/routerRemoval"
import { experimentDefault } from "../../shared/experiments"
Expand Down Expand Up @@ -3311,7 +3311,7 @@ export const webviewMessageHandler = async (
return
}
// Capture prior state for every manager before persisting the global change
const allManagers = CodeIndexManager.getAllInstances()
const allManagers = CodeIndexManagerRegistry.getAllInstances()
const priorStates = new Map(allManagers.map((m) => [m, m.isWorkspaceEnabled]))
await manager.setAutoEnableDefault(message.bool ?? true)
// Apply stop/start to every affected manager
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@
},
"services/code-index/__tests__/manager.spec.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 89
"count": 87
}
},
"services/code-index/__tests__/orchestrator.spec.ts": {
Expand Down
9 changes: 3 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { TerminalRegistry } from "./integrations/terminal/TerminalRegistry"
import { openAiCodexOAuthManager } from "./integrations/openai-codex/oauth"
import { kimiCodeOAuthManager } from "./integrations/kimi-code/oauth"
import { McpServerManager } from "./services/mcp/McpServerManager"
import { CodeIndexManager } from "./services/code-index/manager"
import { CodeIndexManagerRegistry } from "./services/code-index/code-index-manager-registry"
import { MdmService } from "./services/mdm/MdmService"
import { migrateSettings } from "./utils/migrateSettings"
import { autoImportSettings } from "./utils/autoImportSettings"
Expand Down Expand Up @@ -196,15 +196,11 @@ export async function activate(context: vscode.ExtensionContext) {
)

// Initialize code index managers for all workspace folders.
const codeIndexManagers: CodeIndexManager[] = []

if (vscode.workspace.workspaceFolders) {
for (const folder of vscode.workspace.workspaceFolders) {
const manager = CodeIndexManager.getInstance(context, folder.uri.fsPath)
const manager = CodeIndexManagerRegistry.getOrCreate(context, folder.uri.fsPath)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (manager) {
codeIndexManagers.push(manager)

// Initialize in background; do not block extension activation
void manager.initialize(contextProxy).catch((error) => {
const message = error instanceof Error ? error.message : String(error)
Expand Down Expand Up @@ -412,4 +408,5 @@ export async function deactivate() {

Terminal.setTerminalProfile(undefined)
TerminalRegistry.cleanup()
CodeIndexManagerRegistry.disposeAll()
}
Loading
Loading