Skip to content

Commit 8a3effd

Browse files
format the codebase
1 parent 37c21ca commit 8a3effd

12 files changed

+408
-127
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ webviewUi/dist
1212
samples
1313
patterns
1414
.codebuddy
15+
scripts

src/services/code-indexing.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export class CodeIndexingService {
5858
if (!mappedCode) {
5959
throw new Error("Failed to build codebase map");
6060
}
61-
const ats = Object.values(mappedCode).flatMap((repo) => Object.values(repo.modules));
61+
const ats = Object.values(mappedCode).flatMap((repo) =>
62+
Object.values(repo.modules),
63+
);
6264
const mapper = new CodeStructureMapper(ats);
6365
return mapper.normalizeData();
6466
} catch (error) {
@@ -73,7 +75,8 @@ export class CodeIndexingService {
7375
*/
7476
async generateFunctionDescription(): Promise<IFunctionData[]> {
7577
try {
76-
const functions = (await this.buildFunctionStructureMap()) as IFunctionData[];
78+
const functions =
79+
(await this.buildFunctionStructureMap()) as IFunctionData[];
7780
if (!functions?.length) {
7881
throw new Error("failed to generate ATS");
7982
}
@@ -95,7 +98,10 @@ export class CodeIndexingService {
9598
item.compositeText = `Description: ${item.description} Function: ${item.name} ${item.returnType} Dependencies: ${(item.dependencies ?? []).join(", ")}`;
9699
}
97100
});
98-
const functionWithEmbeddings = await this.embeddingService.processFunctions(functionsWithDescription, true);
101+
const functionWithEmbeddings = await this.embeddingService.processFunctions(
102+
functionsWithDescription,
103+
true,
104+
);
99105
return functionWithEmbeddings;
100106
}
101107

src/services/context-retriever.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as vscode from "vscode";
22
import { Orchestrator } from "../agents/orchestrator";
3-
import { IFileToolConfig, IFileToolResponse } from "../application/interfaces/agent.interface";
3+
import {
4+
IFileToolConfig,
5+
IFileToolResponse,
6+
} from "../application/interfaces/agent.interface";
47
import { Logger } from "../infrastructure/logger/logger";
58
import { getAPIKeyAndModel, getGenerativeAiModel } from "./../utils/utils";
69
import { EmbeddingService } from "./embedding";
@@ -51,7 +54,9 @@ export class ContextRetriever {
5154
// }
5255
// }
5356

54-
async readFiles(fileConfigs: IFileToolConfig[]): Promise<IFileToolResponse[]> {
57+
async readFiles(
58+
fileConfigs: IFileToolConfig[],
59+
): Promise<IFileToolResponse[]> {
5560
const files = fileConfigs.flatMap((file) => file);
5661
const promises = files.map(async (file) => {
5762
try {
@@ -65,7 +70,9 @@ export class ContextRetriever {
6570
}
6671
});
6772
const results = await Promise.all(promises);
68-
return results.filter((result): result is IFileToolResponse => result !== undefined);
73+
return results.filter(
74+
(result): result is IFileToolResponse => result !== undefined,
75+
);
6976
}
7077

7178
async readFileContent(filePath: string): Promise<string> {

src/services/embedding.ts

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { EmbedContentResponse, GenerativeModel, GoogleGenerativeAI } from "@google/generative-ai";
1+
import {
2+
EmbedContentResponse,
3+
GenerativeModel,
4+
GoogleGenerativeAI,
5+
} from "@google/generative-ai";
26
import { EmbeddingsConfig } from "../application/constant";
37
import { IFunctionData } from "../application/interfaces";
48
import { Logger, LogLevel } from "../infrastructure/logger/logger";
@@ -24,7 +28,8 @@ interface BatchProcessResult {
2428
* @class EmbeddingService
2529
*/
2630
export class EmbeddingService {
27-
private static readonly DEFAULT_OPTIONS: Required<EmbeddingServiceOptions> = EmbeddingsConfig;
31+
private static readonly DEFAULT_OPTIONS: Required<EmbeddingServiceOptions> =
32+
EmbeddingsConfig;
2833

2934
private readonly options: Required<EmbeddingServiceOptions>;
3035
private readonly requestInterval: number;
@@ -56,7 +61,10 @@ export class EmbeddingService {
5661
try {
5762
const vscode = require("vscode");
5863
const config = vscode.workspace?.getConfiguration?.();
59-
return (config?.get("codebuddy.embeddingModel") as string) || "gemini-2.0-flash";
64+
return (
65+
(config?.get("codebuddy.embeddingModel") as string) ||
66+
"gemini-2.0-flash"
67+
);
6068
} catch {
6169
// Fallback if vscode module is not available (e.g., in tests)
6270
return "gemini-2.0-flash";
@@ -171,7 +179,9 @@ export class EmbeddingService {
171179
* @returns {Promise<IFunctionData>} The function data with the generated embeddings.
172180
* @memberof EmbeddingService
173181
*/
174-
private async generateFunctionEmbeddings(item: IFunctionData): Promise<IFunctionData> {
182+
private async generateFunctionEmbeddings(
183+
item: IFunctionData,
184+
): Promise<IFunctionData> {
175185
try {
176186
const embedding = await this.generateEmbedding(item.compositeText);
177187
return {
@@ -202,7 +212,7 @@ export class EmbeddingService {
202212
private async processBatchWithRetry(
203213
batch: IFunctionData[],
204214
lastRequestTime: number,
205-
forEmbedding: boolean
215+
forEmbedding: boolean,
206216
): Promise<BatchProcessResult> {
207217
let retries = 0;
208218
const generateComments: IFunctionData[] = [];
@@ -216,17 +226,23 @@ export class EmbeddingService {
216226
}
217227

218228
if (forEmbedding) {
219-
const embeddings = await Promise.all(batch.map((item) => this.generateFunctionEmbeddings(item)));
229+
const embeddings = await Promise.all(
230+
batch.map((item) => this.generateFunctionEmbeddings(item)),
231+
);
220232
generateEmbeddings.push(...embeddings.filter(Boolean));
221233
} else {
222234
const comments = await Promise.all(
223235
batch.map((item) => {
224236
if (!item.description) {
225237
return item.content ? this.generateText(item) : null;
226238
}
227-
})
239+
}),
240+
);
241+
generateComments.push(
242+
...comments.filter(
243+
(comment): comment is IFunctionData => comment !== null,
244+
),
228245
);
229-
generateComments.push(...comments.filter((comment): comment is IFunctionData => comment !== null));
230246
}
231247

232248
return {
@@ -262,7 +278,10 @@ export class EmbeddingService {
262278
* @returns {Promise<IFunctionData[]>} The processed function data, including any generated embeddings or text.
263279
* @memberof EmbeddingService
264280
*/
265-
public async processFunctions(data: IFunctionData[], forEmbedding = false): Promise<IFunctionData[]> {
281+
public async processFunctions(
282+
data: IFunctionData[],
283+
forEmbedding = false,
284+
): Promise<IFunctionData[]> {
266285
try {
267286
const result = await this.processWithRateLimit(data, forEmbedding);
268287

@@ -290,7 +309,7 @@ export class EmbeddingService {
290309
*/
291310
private async processWithRateLimit(
292311
data: IFunctionData[],
293-
forEmbedding: boolean
312+
forEmbedding: boolean,
294313
): Promise<{
295314
successful: IFunctionData[];
296315
failed: IFunctionData[];
@@ -304,9 +323,17 @@ export class EmbeddingService {
304323

305324
try {
306325
await this.delay(60000);
307-
const result = await this.processBatchWithRetry(batch, lastRequestTime, forEmbedding);
326+
const result = await this.processBatchWithRetry(
327+
batch,
328+
lastRequestTime,
329+
forEmbedding,
330+
);
308331

309-
successful.push(...(forEmbedding ? result.generateEmbeddings : result.generateComments));
332+
successful.push(
333+
...(forEmbedding
334+
? result.generateEmbeddings
335+
: result.generateComments),
336+
);
310337
lastRequestTime = Date.now();
311338

312339
this.logger.info(`Batch processed`, { startIndex: i });
@@ -315,7 +342,9 @@ export class EmbeddingService {
315342
startIndex: i,
316343
error,
317344
});
318-
failed.push(...batch.map((item) => ({ ...item, error: error as Error })));
345+
failed.push(
346+
...batch.map((item) => ({ ...item, error: error as Error })),
347+
);
319348
}
320349
}
321350

src/services/url-reranker.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ interface IRerankingConfig {
2323
export class UrlReranker {
2424
private static readonly CONFIG: IRerankingConfig = URL_RERANKING_CONFIG;
2525
private static readonly KEYWORDS: string[] = RELEVANT_CODING_KEY_WORDS;
26-
private static readonly WEBSITE_REPUTATIONS: Record<string, number> = REPUTATION_RANK_MAP;
27-
private static readonly CATEGORIES: Record<string, { type: string; score: number }> = URL_CATEGORIES;
26+
private static readonly WEBSITE_REPUTATIONS: Record<string, number> =
27+
REPUTATION_RANK_MAP;
28+
private static readonly CATEGORIES: Record<
29+
string,
30+
{ type: string; score: number }
31+
> = URL_CATEGORIES;
2832
private readonly groqLLM: GroqLLM;
2933
private static instance: UrlReranker;
3034
query: string;
@@ -36,7 +40,8 @@ export class UrlReranker {
3640
const { apiKey, model } = getAPIKeyAndModel(currentModel);
3741

3842
// For URL reranking, prefer Groq if available, otherwise fallback to current selection
39-
const rerankerModel = currentModel.toLowerCase() === "groq" ? currentModel : "Groq";
43+
const rerankerModel =
44+
currentModel.toLowerCase() === "groq" ? currentModel : "Groq";
4045
const { apiKey: rerankerApiKey } = getAPIKeyAndModel(rerankerModel);
4146

4247
this.groqLLM = GroqLLM.getInstance({
@@ -69,7 +74,9 @@ export class UrlReranker {
6974
private calculateTitleRelevanceScore(title: string): number {
7075
if (!title) return 0;
7176

72-
const matches = UrlReranker.KEYWORDS.filter((keyword) => title.toLowerCase().includes(keyword.toLowerCase()));
77+
const matches = UrlReranker.KEYWORDS.filter((keyword) =>
78+
title.toLowerCase().includes(keyword.toLowerCase()),
79+
);
7380

7481
return matches.length / UrlReranker.KEYWORDS.length;
7582
}
@@ -83,7 +90,10 @@ export class UrlReranker {
8390
const hostname = this.extractHostname(metadata);
8491
const domain = hostname.split(".").slice(-2).join(".");
8592

86-
return UrlReranker.WEBSITE_REPUTATIONS[domain] || UrlReranker.WEBSITE_REPUTATIONS.default;
93+
return (
94+
UrlReranker.WEBSITE_REPUTATIONS[domain] ||
95+
UrlReranker.WEBSITE_REPUTATIONS.default
96+
);
8797
}
8898

8999
/**
@@ -95,7 +105,9 @@ export class UrlReranker {
95105
if (!metadata.content) return 0;
96106

97107
const codeBlockCount = this.countCodeBlocks(metadata.content);
98-
const hasAdequateExplanation = this.hasAdequateExplanation(metadata.content);
108+
const hasAdequateExplanation = this.hasAdequateExplanation(
109+
metadata.content,
110+
);
99111

100112
return codeBlockCount + (hasAdequateExplanation ? 1 : 0);
101113
}
@@ -126,7 +138,9 @@ export class UrlReranker {
126138
* @returns Final score for reranking
127139
*/
128140
calculateFinalScore(metadata: IPageMetada): number {
129-
const titleRelevanceScore = this.calculateTitleRelevanceScore(metadata.title ?? "");
141+
const titleRelevanceScore = this.calculateTitleRelevanceScore(
142+
metadata.title ?? "",
143+
);
130144
const reputationScore = this.calculateSourceReputationScore(metadata);
131145
const contentQualityScore = this.calculateContentQualityScore(metadata);
132146
const diversityScore = this.calculateDiversityScore(metadata);

0 commit comments

Comments
 (0)