-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-processor.ts
More file actions
145 lines (132 loc) · 3.63 KB
/
Copy pathfile-processor.ts
File metadata and controls
145 lines (132 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import type { Event, EmitterDisposable } from "@shofer/types"
import { PointStruct } from "./vector-store.js"
/**
* Interface for code file parser
*/
export interface ICodeParser {
/**
* Parses a code file into code blocks
* @param filePath Path to the file to parse
* @param options Optional parsing options
* @returns Promise resolving to array of code blocks
*/
parseFile(
filePath: string,
options?: {
minBlockLines?: number
maxBlockLines?: number
content?: string
fileHash?: string
},
): Promise<CodeBlock[]>
}
/**
* Interface for directory scanner
*/
export interface IDirectoryScanner {
/**
* Scans a directory for code blocks
* @param directoryPath Path to the directory to scan
* @param options Optional scanning options
* @returns Promise resolving to scan results
*/
scanDirectory(
directory: string,
onError?: (error: Error) => void,
onBlocksIndexed?: (indexedCount: number) => void,
onFileParsed?: (fileBlockCount: number) => void,
signal?: AbortSignal,
): Promise<{
stats: {
processed: number
skipped: number
}
totalBlockCount: number
}>
/**
* Scans specific files (Phase 2 — git-aware narrowing).
* Reuses the same per-file pipeline but operates on an explicit list.
*/
scanSpecificFiles(
workspacePath: string,
paths: string[],
onError?: (error: Error) => void,
onBlocksIndexed?: (indexedCount: number) => void,
onFileParsed?: (fileBlockCount: number) => void,
signal?: AbortSignal,
): Promise<{
stats: { processed: number; skipped: number }
totalBlockCount: number
}>
/**
* Deletes points and cache entries for specific deleted files
* (Phase 2 — git-aware narrowing).
*/
deleteSpecificFiles(paths: string[]): Promise<void>
}
/**
* Interface for file watcher
*/
export interface IFileWatcher extends EmitterDisposable {
/**
* Initializes the file watcher
*/
initialize(): Promise<void>
/**
* Event emitted when a batch of files begins processing.
* The event payload is an array of file paths included in the batch.
*/
readonly onDidStartBatchProcessing: Event<string[]>
/**
* Event emitted to report progress during batch processing.
*/
readonly onBatchProgressUpdate: Event<{
processedInBatch: number
totalInBatch: number
currentFile?: string
}>
/**
* Event emitted when a batch of files has finished processing.
* The event payload contains a summary of the batch operation.
*/
readonly onDidFinishBatchProcessing: Event<BatchProcessingSummary>
/**
* Processes a file
* @param filePath Path to the file to process
* @returns Promise resolving to processing result
*/
processFile(filePath: string): Promise<FileProcessingResult>
}
export interface BatchProcessingSummary {
/** All files attempted in the batch, including their final status. */
processedFiles: FileProcessingResult[]
/** Optional error if the entire batch operation failed (e.g., database connection issue). */
batchError?: Error
}
export interface FileProcessingResult {
path: string
status: "success" | "skipped" | "error" | "processed_for_batching" | "local_error"
error?: Error
reason?: string
newHash?: string
newMtimeMs?: number
newSize?: number
/** New segment hashes after parsing (used for per-segment dedup cache). */
newSegmentHashes?: string[]
/** Qdrant point IDs of stale segments to delete (previous hashes not in new set). */
staleSegmentIds?: string[]
pointsToUpsert?: PointStruct[]
}
/**
* Common types used across the code-index service
*/
export interface CodeBlock {
file_path: string
identifier: string | null
type: string
start_line: number
end_line: number
content: string
fileHash: string
segmentHash: string
}