Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/types/src/codebase-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const CODEBASE_INDEX_DEFAULTS = {

export const codebaseIndexConfigSchema = z.object({
codebaseIndexEnabled: z.boolean().optional(),
codebaseIndexBranchIsolation: z.boolean().optional(),
codebaseIndexQdrantUrl: z.string().optional(),
codebaseIndexEmbedderProvider: z
.enum(["openai", "ollama", "openai-compatible", "gemini", "mistral", "vercel-ai-gateway"])
Expand Down
5 changes: 5 additions & 0 deletions src/services/code-index/__tests__/config-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ describe("CodeIndexConfigManager", () => {
ollamaBaseUrl: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: undefined,
branchIsolation: false,
}

const requiresRestart = configManager.doesConfigChangeRequireRestart(mockPrevConfig)
Expand Down Expand Up @@ -1437,6 +1438,7 @@ describe("CodeIndexConfigManager", () => {
embedderProvider: "openai",
openAiKey: "test-key",
qdrantUrl: "http://localhost:6333",
branchIsolation: false,
}

// Update to disabled
Expand Down Expand Up @@ -1490,6 +1492,7 @@ describe("CodeIndexConfigManager", () => {
enabled: false,
configured: false,
embedderProvider: "openai",
branchIsolation: false,
}

// Same config, still disabled
Expand All @@ -1514,6 +1517,7 @@ describe("CodeIndexConfigManager", () => {
embedderProvider: "openai",
openAiKey: "test-key",
qdrantUrl: "http://localhost:6333",
branchIsolation: false,
}

const result = configManager.doesConfigChangeRequireRestart(previousSnapshot)
Expand All @@ -1533,6 +1537,7 @@ describe("CodeIndexConfigManager", () => {
enabled: false,
configured: false,
embedderProvider: "openai",
branchIsolation: false,
}

// Provider changed but feature is disabled
Expand Down
19 changes: 19 additions & 0 deletions src/services/code-index/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getDefaultModelId, getModelDimension, getModelScoreThreshold } from "..
*/
export class CodeIndexConfigManager {
private codebaseIndexEnabled: boolean = true
private codebaseIndexBranchIsolation: boolean = false
private embedderProvider: EmbedderProvider = "openai"
private modelId?: string
private modelDimension?: number
Expand Down Expand Up @@ -45,6 +46,7 @@ export class CodeIndexConfigManager {
// Load configuration from storage
const codebaseIndexConfig = this.contextProxy?.getGlobalState("codebaseIndexConfig") ?? {
codebaseIndexEnabled: true,
codebaseIndexBranchIsolation: false,
codebaseIndexQdrantUrl: "http://localhost:6333",
codebaseIndexEmbedderProvider: "openai",
codebaseIndexEmbedderBaseUrl: "",
Expand All @@ -55,6 +57,7 @@ export class CodeIndexConfigManager {

const {
codebaseIndexEnabled,
codebaseIndexBranchIsolation,
codebaseIndexQdrantUrl,
codebaseIndexEmbedderProvider,
codebaseIndexEmbedderBaseUrl,
Expand All @@ -74,6 +77,7 @@ export class CodeIndexConfigManager {

// Update instance variables with configuration
this.codebaseIndexEnabled = codebaseIndexEnabled ?? true
this.codebaseIndexBranchIsolation = codebaseIndexBranchIsolation ?? false
this.qdrantUrl = codebaseIndexQdrantUrl
this.qdrantApiKey = qdrantApiKey ?? ""
this.searchMinScore = codebaseIndexSearchMinScore
Expand Down Expand Up @@ -156,6 +160,7 @@ export class CodeIndexConfigManager {
// Capture the ACTUAL previous state before loading new configuration
const previousConfigSnapshot: PreviousConfigSnapshot = {
enabled: this.codebaseIndexEnabled,
branchIsolation: this.codebaseIndexBranchIsolation,
configured: this.isConfigured(),
embedderProvider: this.embedderProvider,
modelId: this.modelId,
Expand Down Expand Up @@ -259,6 +264,7 @@ export class CodeIndexConfigManager {

// Handle null/undefined values safely
const prevEnabled = prev?.enabled ?? false
const prevBranchIsolation = prev?.branchIsolation ?? false
const prevConfigured = prev?.configured ?? false
const prevProvider = prev?.embedderProvider ?? "openai"
const prevOpenAiKey = prev?.openAiKey ?? ""
Expand All @@ -282,6 +288,11 @@ export class CodeIndexConfigManager {
return true
}

// 2.5. Branch isolation setting changed
if (prevBranchIsolation !== this.codebaseIndexBranchIsolation) {
return true
}

// 3. If wasn't ready before and isn't ready now, no restart needed
if ((!prevEnabled || !prevConfigured) && (!this.codebaseIndexEnabled || !nowConfigured)) {
return false
Expand Down Expand Up @@ -480,4 +491,12 @@ export class CodeIndexConfigManager {
public get currentSearchMaxResults(): number {
return this.searchMaxResults ?? DEFAULT_MAX_SEARCH_RESULTS
}

/**
* Gets whether branch isolation is enabled for codebase indexing.
* When enabled, each Git branch will have its own separate index.
*/
public get isBranchIsolationEnabled(): boolean {
return this.codebaseIndexBranchIsolation
}
}
1 change: 1 addition & 0 deletions src/services/code-index/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface CodeIndexConfig {
*/
export type PreviousConfigSnapshot = {
enabled: boolean
branchIsolation: boolean
configured: boolean
embedderProvider: EmbedderProvider
modelId?: string
Expand Down
11 changes: 9 additions & 2 deletions src/services/code-index/service-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,15 @@ export class CodeIndexServiceFactory {
throw new Error(t("embeddings:serviceFactory.qdrantUrlMissing"))
}

// Assuming constructor is updated: new QdrantVectorStore(workspacePath, url, vectorSize, apiKey?)
return new QdrantVectorStore(this.workspacePath, config.qdrantUrl, vectorSize, config.qdrantApiKey)
// Pass branch isolation setting to QdrantVectorStore
const branchIsolationEnabled = this.configManager.isBranchIsolationEnabled
return new QdrantVectorStore(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Constructor signature change: QdrantVectorStore now takes a 5th arg (branchIsolationEnabled). The unit tests in src/services/code-index/tests/service-factory.spec.ts still assert 4 args via toHaveBeenCalledWith(...). Those expectations should include the final boolean (likely false/undefined in tests unless you stub isBranchIsolationEnabled). Otherwise tests will fail.

this.workspacePath,
config.qdrantUrl,
vectorSize,
config.qdrantApiKey,
branchIsolationEnabled,
)
}

/**
Expand Down
Loading
Loading