Skip to content

Commit 0ed421a

Browse files
committed
feat: clear index
1 parent 4576006 commit 0ed421a

8 files changed

Lines changed: 73 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "h-codex",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "A semantic code search tool for intelligent, cross-repo context retrieval.",
55
"author": "Htoo Pyae Lwin",
66
"license": "MIT",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hpbyte/h-codex-core",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Core indexing and search functionality for h-codex",
55
"author": "Htoo Pyae Lwin",
66
"license": "MIT",

packages/core/src/ingestion/indexer/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ export class Indexer {
5656
throw new Error(`Failed to index file ${filePath}: ${error}`)
5757
}
5858
}
59+
60+
async clear(projectName: string) {
61+
try {
62+
const project = await projectsRepository.get(projectName)
63+
64+
if (!project) throw new Error(`Project ${projectName} not found`)
65+
66+
return await chunkEmbeddingsRepository.clearChunkEmbeddings(project.id)
67+
} catch (error) {
68+
throw new Error(`Failed to clear index for project ${projectName}: ${error}`)
69+
}
70+
}
5971
}
6072

6173
export const indexer = new Indexer()

packages/core/src/storage/chunk-embeddings.repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export class ChunkEmbeddingsRepository {
125125
return contextualResults
126126
}
127127

128+
async clearChunkEmbeddings(projectId: string) {
129+
return db.delete(codeChunksTable).where(eq(codeChunksTable.projectId, projectId))
130+
}
131+
128132
private diversifyResults<T extends { chunk: CodeChunk; similarity: number }>(
129133
results: T[],
130134
diversityFactor: number

packages/mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hpbyte/h-codex-mcp",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Model Context Protocol for h-codexx",
55
"author": "Htoo Pyae Lwin",
66
"license": "MIT",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2+
import { indexer } from '@hpbyte/h-codex-core'
3+
4+
import { CodeClearInputSchema } from './schemas'
5+
6+
import type { Tool } from '../types'
7+
8+
class CodeClearTool implements Tool {
9+
register(server: McpServer) {
10+
server.registerTool(
11+
'code-clear',
12+
{
13+
title: 'Clear codebase indices',
14+
description: 'Clear the indexed information about the codebase in a project',
15+
inputSchema: CodeClearInputSchema,
16+
},
17+
async ({ project }) => {
18+
try {
19+
await indexer.clear(project)
20+
21+
return {
22+
content: [
23+
{
24+
type: 'text',
25+
text: 'Codebase indices cleared',
26+
},
27+
],
28+
}
29+
} catch (error) {
30+
return {
31+
content: [
32+
{
33+
type: 'text',
34+
text: `Error clearing codebase: ${error instanceof Error ? error.message : String(error)}`,
35+
},
36+
],
37+
}
38+
}
39+
}
40+
)
41+
}
42+
}
43+
44+
const tool = new CodeClearTool()
45+
46+
export default tool
47+

packages/mcp/src/tools/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
import CodeClearTool from './code-clear'
12
import CodeIndexTool from './code-index'
23
import CodeSearchTool from './code-search'
34

4-
export default [CodeIndexTool, CodeSearchTool]
5+
export default [CodeClearTool, CodeIndexTool, CodeSearchTool]

packages/mcp/src/tools/schemas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { z } from 'zod'
22

3+
export const CodeClearInputSchema = {
4+
project: z.string().describe('Project name to clear indices from'),
5+
}
6+
37
export const CodeIndexInputSchema = {
48
path: z.string().describe('Path to the directory to explore and index'),
59
project: z.string().optional().describe('Project name (defaults to directory name)'),
@@ -9,3 +13,4 @@ export const CodeSearchInputSchema = {
913
query: z.string().describe('Search query to find similar code chunks'),
1014
projects: z.array(z.string()).optional().describe('List of project names to search within'),
1115
}
16+

0 commit comments

Comments
 (0)