@gitsense/gscb-git-tools 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/common/logger.js +97 -0
  2. package/dist/cjs/common/logger.js.map +1 -0
  3. package/dist/cjs/common/metadata-manager.js +196 -0
  4. package/dist/cjs/common/metadata-manager.js.map +1 -0
  5. package/dist/cjs/importer/chat-manager/chat-creator.js +90 -0
  6. package/dist/cjs/importer/chat-manager/chat-creator.js.map +1 -0
  7. package/dist/cjs/importer/chat-manager/chat-manager.js +179 -0
  8. package/dist/cjs/importer/chat-manager/chat-manager.js.map +1 -0
  9. package/dist/cjs/importer/chat-manager/constants.js +66 -0
  10. package/dist/cjs/importer/chat-manager/constants.js.map +1 -0
  11. package/dist/cjs/importer/chat-manager/group-manager.js +56 -0
  12. package/dist/cjs/importer/chat-manager/group-manager.js.map +1 -0
  13. package/dist/cjs/importer/chat-manager/hierarchy-manager.js +115 -0
  14. package/dist/cjs/importer/chat-manager/hierarchy-manager.js.map +1 -0
  15. package/dist/cjs/importer/chat-manager/message-manager.js +126 -0
  16. package/dist/cjs/importer/chat-manager/message-manager.js.map +1 -0
  17. package/dist/cjs/importer/constants.js +30 -0
  18. package/dist/cjs/importer/constants.js.map +1 -0
  19. package/dist/cjs/importer/core/directory-processor.js +343 -0
  20. package/dist/cjs/importer/core/directory-processor.js.map +1 -0
  21. package/dist/cjs/importer/core/error-handler.js +64 -0
  22. package/dist/cjs/importer/core/error-handler.js.map +1 -0
  23. package/dist/cjs/importer/core/import-processor.js +167 -0
  24. package/dist/cjs/importer/core/import-processor.js.map +1 -0
  25. package/dist/cjs/importer/core/importer.js +135 -0
  26. package/dist/cjs/importer/core/importer.js.map +1 -0
  27. package/dist/cjs/importer/core/utils.js +66 -0
  28. package/dist/cjs/importer/core/utils.js.map +1 -0
  29. package/dist/cjs/importer/file-processor.js +199 -0
  30. package/dist/cjs/importer/file-processor.js.map +1 -0
  31. package/dist/cjs/importer/language-utils.js +286 -0
  32. package/dist/cjs/importer/language-utils.js.map +1 -0
  33. package/dist/cjs/importer/tree-processor.js +119 -0
  34. package/dist/cjs/importer/tree-processor.js.map +1 -0
  35. package/dist/cjs/index.js +12 -0
  36. package/dist/cjs/index.js.map +1 -0
  37. package/dist/cjs/package.json +3 -0
  38. package/dist/esm/common/logger.js +95 -0
  39. package/dist/esm/common/logger.js.map +1 -0
  40. package/dist/esm/common/metadata-manager.js +194 -0
  41. package/dist/esm/common/metadata-manager.js.map +1 -0
  42. package/dist/esm/importer/chat-manager/chat-creator.js +88 -0
  43. package/dist/esm/importer/chat-manager/chat-creator.js.map +1 -0
  44. package/dist/esm/importer/chat-manager/chat-manager.js +177 -0
  45. package/dist/esm/importer/chat-manager/chat-manager.js.map +1 -0
  46. package/dist/esm/importer/chat-manager/constants.js +48 -0
  47. package/dist/esm/importer/chat-manager/constants.js.map +1 -0
  48. package/dist/esm/importer/chat-manager/group-manager.js +54 -0
  49. package/dist/esm/importer/chat-manager/group-manager.js.map +1 -0
  50. package/dist/esm/importer/chat-manager/hierarchy-manager.js +113 -0
  51. package/dist/esm/importer/chat-manager/hierarchy-manager.js.map +1 -0
  52. package/dist/esm/importer/chat-manager/message-manager.js +124 -0
  53. package/dist/esm/importer/chat-manager/message-manager.js.map +1 -0
  54. package/dist/esm/importer/constants.js +28 -0
  55. package/dist/esm/importer/constants.js.map +1 -0
  56. package/dist/esm/importer/core/directory-processor.js +337 -0
  57. package/dist/esm/importer/core/directory-processor.js.map +1 -0
  58. package/dist/esm/importer/core/error-handler.js +62 -0
  59. package/dist/esm/importer/core/error-handler.js.map +1 -0
  60. package/dist/esm/importer/core/import-processor.js +165 -0
  61. package/dist/esm/importer/core/import-processor.js.map +1 -0
  62. package/dist/esm/importer/core/importer.js +133 -0
  63. package/dist/esm/importer/core/importer.js.map +1 -0
  64. package/dist/esm/importer/core/utils.js +64 -0
  65. package/dist/esm/importer/core/utils.js.map +1 -0
  66. package/dist/esm/importer/file-processor.js +193 -0
  67. package/dist/esm/importer/file-processor.js.map +1 -0
  68. package/dist/esm/importer/language-utils.js +279 -0
  69. package/dist/esm/importer/language-utils.js.map +1 -0
  70. package/dist/esm/importer/tree-processor.js +113 -0
  71. package/dist/esm/importer/tree-processor.js.map +1 -0
  72. package/dist/esm/index.js +4 -0
  73. package/dist/esm/index.js.map +1 -0
  74. package/dist/index.d.ts +215 -0
  75. package/package.json +1 -1
@@ -0,0 +1,343 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var utils = require('./utils.js');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var path__default = /*#__PURE__*/_interopDefault(path);
9
+
10
+ /**
11
+ * Component: Directory Processor
12
+ * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
13
+ * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
14
+ * Version: 8.0.0
15
+ * Purpose: Add hash comparison and token estimation for directories
16
+ * Language: TypeScript
17
+ * Created-at: 2025-03-15T05:58:33.811Z
18
+ * Updated-at: 2025-03-24T00:50:00.000Z
19
+ * Authors: Claude 3.5 Sonnet (v5.0.1), Bard, Claude 3.5 Sonnet (v6.0.0), Claude 3.7 Sonnet (v6.3.0),
20
+ * OpenRouter - Gemini Flash 2.0 (v6.4.0), OpenRouter - Gemini Flash 2.0 (v6.5.0),
21
+ * together.ai - DeepSeek v3 (v6.6.0), Claude 3.7 Sonnet (v6.7.0), together.ai - DeepSeek v3 (v6.8.0),
22
+ * together.ai - DeepSeek v3 (v7.0.0), together.ai - DeepSeek v3 (v8.0.0)
23
+ */
24
+ class DirectoryProcessor {
25
+ dbClient;
26
+ gitRepo;
27
+ fileProcessor;
28
+ treeProcessor;
29
+ metadataManager;
30
+ chatManager;
31
+ logger;
32
+ constructor(dbClient, gitRepo, fileProcessor, treeProcessor, metadataManager, chatManager, logger) {
33
+ this.dbClient = dbClient;
34
+ this.gitRepo = gitRepo;
35
+ this.fileProcessor = fileProcessor;
36
+ this.treeProcessor = treeProcessor;
37
+ this.metadataManager = metadataManager;
38
+ this.chatManager = chatManager;
39
+ this.logger = logger;
40
+ }
41
+ /**
42
+ * Estimates tokens using 1.33 tokens per word.
43
+ */
44
+ estimateTokens(text) {
45
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
46
+ return Math.ceil(wordCount * 1.33);
47
+ }
48
+ /**
49
+ * Processes all files and directories in the repository, ensuring a proper parent-child relationship.
50
+ */
51
+ async processFiles(rootChatId) {
52
+ try {
53
+ // Start processing from the root directory. Empty string is root.
54
+ return await this.processDirectory('', rootChatId);
55
+ }
56
+ catch (error) {
57
+ throw new Error(`Failed to process files: ${error instanceof Error ? error.message : String(error)}`);
58
+ }
59
+ }
60
+ /**
61
+ * Processes entries (files and directories) that have changed between commits.
62
+ */
63
+ async processChangedEntries(changedEntries, refChatId, repoGroupId) {
64
+ // Group entries by change type
65
+ const addedOrModifiedFiles = [];
66
+ const deletedFiles = [];
67
+ const deletedDirs = [];
68
+ for (const entry of changedEntries) {
69
+ // Normalize the path
70
+ const normalizedPath = this.normalizePath(entry.path);
71
+ // Skip files that match skip patterns if they're being added or modified
72
+ if (entry.entryType === 'file' && entry.changeType !== 'delete' &&
73
+ await this.fileProcessor.shouldSkipFile(normalizedPath)) {
74
+ this.logger.log(`Skipping file: ${normalizedPath}`);
75
+ continue;
76
+ }
77
+ // Categorize the entry
78
+ if (entry.entryType === 'file') {
79
+ if (entry.changeType === 'delete') {
80
+ deletedFiles.push(normalizedPath);
81
+ }
82
+ else {
83
+ addedOrModifiedFiles.push(normalizedPath);
84
+ }
85
+ }
86
+ else {
87
+ if (entry.changeType === 'delete') {
88
+ deletedDirs.push(normalizedPath);
89
+ }
90
+ }
91
+ }
92
+ // Process deleted files first
93
+ if (deletedFiles.length > 0) {
94
+ this.logger.log(`Processing ${deletedFiles.length} deleted files`);
95
+ await this.processDeletedFiles(deletedFiles, refChatId);
96
+ }
97
+ // Process deleted directories
98
+ if (deletedDirs.length > 0) {
99
+ this.logger.log(`Processing ${deletedDirs.length} deleted directories`);
100
+ await this.processDeletedDirectories(deletedDirs, refChatId);
101
+ }
102
+ // Group added/modified files by directory
103
+ const filesByDirectory = {};
104
+ for (const filePath of addedOrModifiedFiles) {
105
+ const dirPath = this.normalizePath(path__default.default.dirname(filePath));
106
+ if (!filesByDirectory[dirPath]) {
107
+ filesByDirectory[dirPath] = [];
108
+ }
109
+ filesByDirectory[dirPath].push(filePath);
110
+ }
111
+ // Process each directory's added/modified files
112
+ for (const [dirPath, files] of Object.entries(filesByDirectory)) {
113
+ this.logger.log(`Processing ${files.length} files in directory: ${dirPath}`);
114
+ // Find or create the directory chat
115
+ const dirChatId = await this.findOrCreateDirectoryChat(dirPath, refChatId, repoGroupId);
116
+ // Process each file in the directory
117
+ let orderWeight = 10;
118
+ for (const filePath of files) {
119
+ this.logger.log(`Processing file: ${filePath}`);
120
+ // FileProcessor will handle both new files and updates
121
+ await this.fileProcessor.processFile(filePath, dirChatId, orderWeight);
122
+ orderWeight += 10;
123
+ }
124
+ await this.metadataManager.updateDirectoryMetadata(dirChatId, dirPath, null);
125
+ }
126
+ }
127
+ /**
128
+ * Recursively processes a directory and its contents.
129
+ */
130
+ async processDirectory(dirPath, parentChatId, treeSha = '') {
131
+ try {
132
+ // Used to define chat order
133
+ let orderWeight = 0;
134
+ // Create a chat for the current directory
135
+ const dirChatId = dirPath === ''
136
+ ? parentChatId
137
+ : await this.treeProcessor.createDirectoryChat(dirPath, parentChatId, treeSha, orderWeight);
138
+ // List the contents of the directory
139
+ const entries = await this.gitRepo.listDirectory(dirPath);
140
+ // Separate directories and files, then sort alphabetically
141
+ const directories = entries
142
+ .filter(entry => entry.type === 'tree')
143
+ .sort((a, b) => b.path.localeCompare(a.path));
144
+ const files = entries
145
+ .filter(entry => entry.type === 'blob')
146
+ .sort((a, b) => a.path.localeCompare(b.path));
147
+ // Process directories and files
148
+ const childCommits = [];
149
+ for (const dir of directories) {
150
+ orderWeight += 10;
151
+ const childCommit = await this.processDirectory(dirPath + (dirPath === '' ? '' : '/') + dir.path, dirChatId, dir.oid);
152
+ if (childCommit)
153
+ childCommits.push(childCommit);
154
+ }
155
+ for (const file of files) {
156
+ const { path } = file;
157
+ if (await this.fileProcessor.shouldSkipFile(path))
158
+ continue;
159
+ orderWeight += 10;
160
+ const fileCommit = await this.fileProcessor.processFile(dirPath + (dirPath === '' ? '' : '/') + path, dirChatId, orderWeight);
161
+ if (fileCommit)
162
+ childCommits.push(fileCommit);
163
+ }
164
+ // Determine the latest commit for the directory
165
+ const latestCommit = utils.Utils.getLatestCommit(childCommits);
166
+ // Skip update if the commit hash hasn't changed
167
+ const existingMeta = (await this.chatManager.getChatById(dirChatId))?.meta || {};
168
+ if (existingMeta.commit?.hash === latestCommit?.hash) {
169
+ this.logger.log(`Skipping update for directory '${dirPath}' (commit hash unchanged)`);
170
+ return latestCommit;
171
+ }
172
+ // Estimate tokens for directory metadata
173
+ const now = new Date().toISOString();
174
+ const metaTokens = this.estimateTokens(JSON.stringify({
175
+ type: 'git-tree',
176
+ tree: treeSha,
177
+ path: dirPath,
178
+ name: path__default.default.basename(dirPath),
179
+ commit: latestCommit,
180
+ status: 'imported'
181
+ }));
182
+ // Update the directory metadata
183
+ const update = {
184
+ status: 'imported',
185
+ importFinishedAt: now,
186
+ tokens: {
187
+ metadata: { estimate: metaTokens, estimatedAt: now }
188
+ }
189
+ };
190
+ if (dirPath !== '' && dirPath !== '.') {
191
+ update.commit = latestCommit;
192
+ }
193
+ await this.metadataManager.updateChatMetadata(dirChatId, { ...existingMeta, ...update });
194
+ return latestCommit;
195
+ }
196
+ catch (error) {
197
+ console.trace();
198
+ throw new Error(`Failed to process directory '${dirPath}': ${error instanceof Error ? error.message : String(error)}`);
199
+ }
200
+ }
201
+ /**
202
+ * Processes deleted files.
203
+ */
204
+ async processDeletedFiles(deletedFiles, refChatId) {
205
+ for (const filePath of deletedFiles) {
206
+ this.logger.log(`Processing deleted file: ${filePath}`);
207
+ // Find the directory chat for this file
208
+ const dirPath = this.normalizePath(path__default.default.dirname(filePath));
209
+ const dirChatId = await this.findDirectoryChat(dirPath, refChatId);
210
+ if (!dirChatId) {
211
+ this.logger.log(`Could not find directory chat for ${dirPath}, skipping deletion of ${filePath}`);
212
+ continue;
213
+ }
214
+ // Find the file chat
215
+ const fileName = path__default.default.basename(filePath);
216
+ const childChats = await this.dbClient.getChatsByParentId(dirChatId);
217
+ const fileChat = childChats.find(chat => chat.type === 'git-blob' &&
218
+ chat.name === fileName && chat.meta?.path === filePath);
219
+ if (!fileChat) {
220
+ this.logger.log(`Could not find chat for file ${filePath}, it may have been deleted already`);
221
+ continue;
222
+ }
223
+ // Mark the file as deleted
224
+ await this.metadataManager.markFileAsDeleted(fileChat.id, filePath);
225
+ await this.metadataManager.updateDirectoryMetadata(dirChatId, dirPath, null);
226
+ }
227
+ }
228
+ /**
229
+ * Processes deleted directories.
230
+ */
231
+ async processDeletedDirectories(deletedDirs, refChatId) {
232
+ // Sort directories by depth (deepest first) to handle nested directories correctly
233
+ const sortedDirs = [...deletedDirs].sort((a, b) => b.split('/').length - a.split('/').length);
234
+ for (const dirPath of sortedDirs) {
235
+ this.logger.log(`Processing deleted directory: ${dirPath}`);
236
+ // Find the parent directory chat
237
+ const parentDirPath = this.normalizePath(path__default.default.dirname(dirPath));
238
+ const parentDirChatId = await this.findDirectoryChat(parentDirPath, refChatId);
239
+ if (!parentDirChatId) {
240
+ this.logger.log(`Could not find parent directory chat for ${parentDirPath}, skipping deletion of ${dirPath}`);
241
+ continue;
242
+ }
243
+ // Find the directory chat
244
+ const dirName = path__default.default.basename(dirPath);
245
+ const childChats = await this.dbClient.getChatsByParentId(parentDirChatId);
246
+ const dirChat = childChats.find(chat => chat.type === 'git-tree' &&
247
+ chat.name === dirName &&
248
+ chat.meta?.path === dirPath);
249
+ if (!dirChat) {
250
+ this.logger.log(`Could not find chat for directory ${dirPath}, it may have been deleted already`);
251
+ continue;
252
+ }
253
+ // Delete the directory
254
+ await this.dbClient.deleteChat(dirChat.id);
255
+ // Mark the directory and all its contents as deleted
256
+ await this.metadataManager.markDirectoryAsDeleted(dirChat.id, dirPath);
257
+ }
258
+ }
259
+ /**
260
+ * Finds or creates a directory chat.
261
+ */
262
+ async findOrCreateDirectoryChat(dirPath, refChatId, repoGroupId) {
263
+ // Normalize the input path
264
+ const normalizedDirPath = this.normalizePath(dirPath);
265
+ if (normalizedDirPath === '.' || normalizedDirPath === '') {
266
+ return refChatId;
267
+ }
268
+ // Split the path into components
269
+ const pathComponents = normalizedDirPath.split('/');
270
+ // Start from the root chat
271
+ let currentChatId = refChatId;
272
+ let currentPath = '';
273
+ // Traverse the path, creating directory chats as needed
274
+ for (const component of pathComponents) {
275
+ currentPath = currentPath ? `${currentPath}/${component}` : component;
276
+ const normalizedCurrentPath = this.normalizePath(currentPath);
277
+ // Try to find an existing chat for this directory
278
+ const childChats = await this.dbClient.getChatsByParentId(currentChatId);
279
+ const dirChat = childChats.find(chat => {
280
+ // Normalize the path from meta for comparison
281
+ const chatPath = this.normalizePath(chat.meta?.path || '');
282
+ return chat.type === 'git-tree' && chatPath === normalizedCurrentPath;
283
+ });
284
+ if (dirChat) {
285
+ currentChatId = dirChat.id;
286
+ this.logger.log(`Found existing directory chat for ${normalizedCurrentPath}: ${currentChatId}`);
287
+ }
288
+ else {
289
+ // Create a new directory chat
290
+ this.logger.log(`Creating new directory chat for ${normalizedCurrentPath}`);
291
+ const treeSha = await this.gitRepo.getTreeSha(normalizedCurrentPath);
292
+ currentChatId = await this.treeProcessor.createDirectoryChat(normalizedCurrentPath, currentChatId, treeSha, 10) || 0;
293
+ }
294
+ }
295
+ return currentChatId;
296
+ }
297
+ /**
298
+ * Finds a directory chat by path.
299
+ */
300
+ async findDirectoryChat(dirPath, rootChatId) {
301
+ // Normalize the input path
302
+ const normalizedDirPath = this.normalizePath(dirPath);
303
+ if (normalizedDirPath === '.' || normalizedDirPath === '') {
304
+ return rootChatId;
305
+ }
306
+ // Split the path into components
307
+ const pathComponents = normalizedDirPath.split('/');
308
+ // Start from the root chat
309
+ let currentChatId = rootChatId;
310
+ let currentPath = '';
311
+ // Traverse the path, looking for existing directory chats
312
+ for (const component of pathComponents) {
313
+ currentPath = currentPath ? `${currentPath}/${component}` : component;
314
+ const normalizedCurrentPath = this.normalizePath(currentPath);
315
+ // Try to find an existing chat for this directory
316
+ const childChats = await this.dbClient.getChatsByParentId(currentChatId);
317
+ const dirChat = childChats.find(chat => {
318
+ // Normalize the path from meta for comparison
319
+ const chatPath = this.normalizePath(chat.meta?.path || '');
320
+ return chat.type === 'git-tree' && chatPath === normalizedCurrentPath;
321
+ });
322
+ if (dirChat) {
323
+ currentChatId = dirChat.id;
324
+ this.logger.log(`Found existing directory chat for ${normalizedCurrentPath}: ${currentChatId}`);
325
+ }
326
+ else {
327
+ // If we can't find a directory at any level, return undefined
328
+ this.logger.log(`Could not find directory chat for ${normalizedCurrentPath}`);
329
+ return undefined;
330
+ }
331
+ }
332
+ return currentChatId;
333
+ }
334
+ /**
335
+ * Normalizes a file path.
336
+ */
337
+ normalizePath(path) {
338
+ return path.replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
339
+ }
340
+ }
341
+
342
+ exports.DirectoryProcessor = DirectoryProcessor;
343
+ //# sourceMappingURL=directory-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory-processor.js","sources":["../../../../src/importer/core/directory-processor.ts"],"sourcesContent":[null],"names":["path","Utils"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;AAaG;MAaU,kBAAkB,CAAA;AAEN,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,WAAA;AACA,IAAA,MAAA;AAPrB,IAAA,WAAA,CACqB,QAAwB,EACxB,OAAmB,EACnB,aAA4B,EAC5B,aAA4B,EAC5B,eAAgC,EAChC,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AG,IAAI,CAAC,aAAa,CAAE,IAAI,CAAC,IAAY,EAAE,IAAI,IAAI,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,QAAQ,KAAK,qBAAqB;AACzE,aAAC,CAAC;YAEF,IAAI,OAAO,EAAE;AACT,gBAAA,aAAa,GAAG,OAAO,CAAC,EAAG;gBAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAqC,kCAAA,EAAA,qBAAqB,CAAK,EAAA,EAAA,aAAa,CAAE,CAAA,CAAC;;iBAC5F;;gBAEH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAqC,kCAAA,EAAA,qBAAqB,CAAE,CAAA,CAAC;AAC7E,gBAAA,OAAO,SAAS;;;AAIxB,QAAA,OAAO,aAAa;;AAGxB;;AAEG;AACK,IAAA,aAAa,CAAC,IAAY,EAAA;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;;AAE9E;;;;"}
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ var gscbDb = require('@gitsense/gscb-db');
4
+
5
+ /**
6
+ * Component: Error Handler
7
+ * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
8
+ * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
9
+ * Version: 6.6.0
10
+ * Purpose: Centralized error handling for GitImporter
11
+ * Language: TypeScript
12
+ * Created-at: 2025-03-15T05:59:20.178Z
13
+ * Authors: Claude 3.5 Sonnet (v5.0.1), Bard, Claude 3.5 Sonnet (v6.0.0), Claude 3.7 Sonnet (v6.3.0), OpenRouter - Gemini Flash 2.0 (v6.4.0), OpenRouter - Gemini Flash 2.0 (v6.5.0), together.ai - DeepSeek v3 (v6.6.0)
14
+ */
15
+ class ErrorHandler {
16
+ logger;
17
+ constructor(logger) {
18
+ this.logger = logger;
19
+ }
20
+ /**
21
+ * Handles errors during the import process.
22
+ * @param error The error to handle.
23
+ * @throws {Error} Always throws an error after handling.
24
+ */
25
+ async handleError(error) {
26
+ let message;
27
+ let isExpected = false;
28
+ if (error instanceof gscbDb.DatabaseError) {
29
+ message = `Database error: ${error.message}`;
30
+ isExpected = true;
31
+ }
32
+ else if (error instanceof gscbDb.ValidationError) {
33
+ message = `Validation error: ${error.message}`;
34
+ isExpected = true;
35
+ }
36
+ else if (error instanceof gscbDb.NotFoundError) {
37
+ message = `Not found: ${error.message}`;
38
+ isExpected = true;
39
+ }
40
+ else if (this.isGitError(error)) {
41
+ message = `Git error: ${error.message}`;
42
+ isExpected = true;
43
+ }
44
+ else if (error instanceof Error) {
45
+ message = `Unexpected error: ${error.message}`;
46
+ }
47
+ else {
48
+ message = `Unknown error: ${String(error)}`;
49
+ }
50
+ this.logger.log(message, error, !isExpected);
51
+ throw error;
52
+ }
53
+ /**
54
+ * Checks if an error is a Git error.
55
+ */
56
+ isGitError(error) {
57
+ return (error instanceof Error &&
58
+ 'code' in error &&
59
+ typeof error.code === 'string');
60
+ }
61
+ }
62
+
63
+ exports.ErrorHandler = ErrorHandler;
64
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sources":["../../../../src/importer/core/error-handler.ts"],"sourcesContent":[null],"names":["DatabaseError","ValidationError","NotFoundError"],"mappings":";;;;AAAA;;;;;;;;;AASG;MAOU,YAAY,CAAA;AACQ,IAAA,MAAA;AAA7B,IAAA,WAAA,CAA6B,MAAc,EAAA;QAAd,IAAM,CAAA,MAAA,GAAN,MAAM;;AAEnC;;;;AAIG;IACH,MAAM,WAAW,CAAC,KAAc,EAAA;AAC5B,QAAA,IAAI,OAAe;QACnB,IAAI,UAAU,GAAG,KAAK;AAEtB,QAAA,IAAI,KAAK,YAAYA,oBAAa,EAAE;AAChC,YAAA,OAAO,GAAG,CAAmB,gBAAA,EAAA,KAAK,CAAC,OAAO,EAAE;YAC5C,UAAU,GAAG,IAAI;;AACd,aAAA,IAAI,KAAK,YAAYC,sBAAe,EAAE;AACzC,YAAA,OAAO,GAAG,CAAqB,kBAAA,EAAA,KAAK,CAAC,OAAO,EAAE;YAC9C,UAAU,GAAG,IAAI;;AACd,aAAA,IAAI,KAAK,YAAYC,oBAAa,EAAE;AACvC,YAAA,OAAO,GAAG,CAAc,WAAA,EAAA,KAAK,CAAC,OAAO,EAAE;YACvC,UAAU,GAAG,IAAI;;AACd,aAAA,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC/B,YAAA,OAAO,GAAG,CAAe,WAAA,EAAA,KAA6B,CAAC,OAAO,EAAE;YAChE,UAAU,GAAG,IAAI;;AACd,aAAA,IAAI,KAAK,YAAY,KAAK,EAAE;AAC/B,YAAA,OAAO,GAAG,CAAqB,kBAAA,EAAA,KAAK,CAAC,OAAO,EAAE;;aAC3C;AACH,YAAA,OAAO,GAAG,CAAkB,eAAA,EAAA,MAAM,CAAC,KAAK,CAAC,EAAE;;AAG/C,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC;AAC5C,QAAA,MAAM,KAAK;;AAGf;;AAEG;AACK,IAAA,UAAU,CAAC,KAAc,EAAA;QAC7B,QACI,KAAK,YAAY,KAAK;AACtB,YAAA,MAAM,IAAI,KAAK;AACf,YAAA,OAAQ,KAAkB,CAAC,IAAI,KAAK,QAAQ;;AAGvD;;;;"}
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ var chatManager = require('../chat-manager/chat-manager.js');
4
+ var messageManager = require('../chat-manager/message-manager.js');
5
+ var fileProcessor = require('../file-processor.js');
6
+ var treeProcessor = require('../tree-processor.js');
7
+ var directoryProcessor = require('./directory-processor.js');
8
+ var metadataManager = require('../../common/metadata-manager.js');
9
+
10
+ /**
11
+ * Component: Import Processor
12
+ * Block-UUID: 5cc5dcf8-63d7-415a-aa21-ffa85e3b8dd9
13
+ * Parent-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
14
+ * Version: 6.8.0
15
+ * Purpose: Handles the import process logic for GitImporter with optimized metadata updates
16
+ * Language: TypeScript
17
+ * Created-at: 2025-03-17T04:14:43.902Z
18
+ * Authors: Claude 3.5 Sonnet (v5.0.1), Bard, Claude 3.5 Sonnet (v6.0.0), Claude 3.7 Sonnet (v6.3.0),
19
+ * OpenRouter - Gemini Flash 2.0 (v6.4.0), OpenRouter - Gemini Flash 2.0 (v6.5.0),
20
+ * together.ai - DeepSeek v3 (v6.6.0), Claude 3.7 Sonnet (v6.7.0), together.ai - DeepSeek v3 (v6.8.0)
21
+ */
22
+ class ImportProcessor {
23
+ dbClient;
24
+ gitRepo;
25
+ repoOwner;
26
+ repoName;
27
+ ref;
28
+ refType;
29
+ options;
30
+ logger;
31
+ chatManager;
32
+ messageManager;
33
+ _metadataManager = null;
34
+ _fileProcessor = null;
35
+ _treeProcessor = null;
36
+ constructor(dbClient, gitRepo, repoOwner, repoName, ref, refType, options, logger) {
37
+ this.dbClient = dbClient;
38
+ this.gitRepo = gitRepo;
39
+ this.repoOwner = repoOwner;
40
+ this.repoName = repoName;
41
+ this.ref = ref;
42
+ this.refType = refType;
43
+ this.options = options;
44
+ this.logger = logger;
45
+ this.chatManager = new chatManager.ChatManager(dbClient, gitRepo, repoOwner, repoName, ref, refType, options, logger);
46
+ this.messageManager = new messageManager.MessageManager(dbClient, logger);
47
+ }
48
+ /**
49
+ * Sets up the import process with optimized metadata updates
50
+ */
51
+ async setupImport() {
52
+ try {
53
+ // Setup chat hierarchy
54
+ const { refChatId, repoGroupId } = await this.chatManager.setupChatHierarchy();
55
+ // Process import
56
+ const currentCommit = await this.gitRepo.resolveRef(this.ref);
57
+ const refChat = await this.chatManager.getChatById(refChatId);
58
+ const meta = refChat?.meta || {};
59
+ if (meta && meta.status === 'imported' && meta.commit) {
60
+ await this.processExistingImport(meta, currentCommit, refChatId, repoGroupId);
61
+ }
62
+ else {
63
+ await this.processNewImport(refChatId, repoGroupId);
64
+ }
65
+ return { refChatId, repoGroupId };
66
+ }
67
+ catch (error) {
68
+ throw error;
69
+ }
70
+ }
71
+ /**
72
+ * Processes an existing import by checking for changes and performing an incremental import if necessary.
73
+ */
74
+ async processExistingImport(meta, currentCommit, refChatId, repoGroupId) {
75
+ if (!meta.commit)
76
+ throw new Error("No ref commit meta or hash found");
77
+ const metadataManager = this.getMetadataManager();
78
+ if (meta.commit.hash === currentCommit) {
79
+ this.logger.log('Repository already imported with the same commit hash, skipping import');
80
+ return;
81
+ }
82
+ try {
83
+ this.logger.log(`Found previous import with commit hash: ${meta.commit.hash}`);
84
+ // Mark the start of the import
85
+ await metadataManager.markImportStarted(refChatId, this.ref);
86
+ // Get the list of changed entries with their change types
87
+ const changedEntries = await this.gitRepo.getChangedEntriesBetweenCommits(meta.commit?.hash || '', currentCommit, { includeFiles: true, includeDirectories: true });
88
+ if (changedEntries.length > 0) {
89
+ this.logger.log(`Found ${changedEntries.length} changed entries to process`);
90
+ // Process the changed entries
91
+ const directoryProcessor$1 = new directoryProcessor.DirectoryProcessor(this.dbClient, this.gitRepo, this.getFileProcessor(repoGroupId), this.getTreeProcessor(repoGroupId), this.getMetadataManager(), this.chatManager, this.logger);
92
+ await directoryProcessor$1.processChangedEntries(changedEntries, refChatId, repoGroupId);
93
+ this.logger.log('Incremental import completed successfully');
94
+ }
95
+ else {
96
+ this.logger.log('No files changed, updating commit hash only');
97
+ }
98
+ await metadataManager.markImportFinished(refChatId);
99
+ }
100
+ catch (error) {
101
+ console.trace();
102
+ this.logger.log('Incremental import failed: ', error instanceof Error ? error.message : String(error));
103
+ await metadataManager.markImportFailed(refChatId, error);
104
+ }
105
+ }
106
+ /**
107
+ * Processes a new import by performing a full import of the repository.
108
+ */
109
+ async processNewImport(refChatId, repoGroupId) {
110
+ const metadataManager = this.getMetadataManager();
111
+ this.logger.log('Performing full import');
112
+ await metadataManager.markImportStarted(refChatId, this.ref);
113
+ // Process all files
114
+ const directoryProcessor$1 = new directoryProcessor.DirectoryProcessor(this.dbClient, this.gitRepo, this.getFileProcessor(repoGroupId), this.getTreeProcessor(repoGroupId), this.getMetadataManager(), this.chatManager, this.logger);
115
+ await directoryProcessor$1.processFiles(refChatId);
116
+ await metadataManager.markImportFinished(refChatId);
117
+ this.logger.log('Full import completed successfully');
118
+ }
119
+ /**
120
+ * Gets the chat hierarchy from git-repos down to git-ref
121
+ */
122
+ async getChatHierarchy(refChatId) {
123
+ const hierarchy = [];
124
+ let currentChatId = refChatId;
125
+ while (currentChatId) {
126
+ const chat = await this.chatManager.getChatById(currentChatId);
127
+ if (!chat || !chat.id)
128
+ break;
129
+ hierarchy.unshift({
130
+ id: chat.id,
131
+ type: chat.type
132
+ });
133
+ currentChatId = chat.parentId || 0;
134
+ }
135
+ return hierarchy;
136
+ }
137
+ /**
138
+ * Lazily initializes and returns the MetadataManager instance.
139
+ */
140
+ getMetadataManager() {
141
+ if (!this._metadataManager) {
142
+ this._metadataManager = new metadataManager.MetadataManager(this.dbClient, this.logger, this.gitRepo, this.chatManager);
143
+ }
144
+ return this._metadataManager;
145
+ }
146
+ /**
147
+ * Lazily initializes and returns the FileProcessor instance.
148
+ */
149
+ getFileProcessor(repoGroupId) {
150
+ if (!this._fileProcessor) {
151
+ this._fileProcessor = new fileProcessor.FileProcessor(this.dbClient, this.gitRepo, this.chatManager, this.options, repoGroupId, this.logger);
152
+ }
153
+ return this._fileProcessor;
154
+ }
155
+ /**
156
+ * Lazily initializes and returns the TreeProcessor instance.
157
+ */
158
+ getTreeProcessor(repoGroupId) {
159
+ if (!this._treeProcessor) {
160
+ this._treeProcessor = new treeProcessor.TreeProcessor(this.gitRepo, this.chatManager, this.getFileProcessor(repoGroupId), repoGroupId, this.logger);
161
+ }
162
+ return this._treeProcessor;
163
+ }
164
+ }
165
+
166
+ exports.ImportProcessor = ImportProcessor;
167
+ //# sourceMappingURL=import-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-processor.js","sources":["../../../../src/importer/core/import-processor.ts"],"sourcesContent":[null],"names":["ChatManager","MessageManager","directoryProcessor","DirectoryProcessor","MetadataManager","FileProcessor","TreeProcessor"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;AAWG;MAeU,eAAe,CAAA;AAQH,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,SAAA;AACA,IAAA,QAAA;AACA,IAAA,GAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA,MAAA;AAdJ,IAAA,WAAW;AACX,IAAA,cAAc;IACvB,gBAAgB,GAA2B,IAAI;IAC/C,cAAc,GAAyB,IAAI;IAC3C,cAAc,GAAyB,IAAI;AAEnD,IAAA,WAAA,CACqB,QAAwB,EACxB,OAAmB,EACnB,SAAiB,EACjB,QAAgB,EAChB,GAAW,EACX,OAAgB,EAChB,OAAsB,EACtB,MAAc,EAAA;QAPd,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAS,CAAA,SAAA,GAAT,SAAS;QACT,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAG,CAAA,GAAA,GAAH,GAAG;QACH,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAM,CAAA,MAAA,GAAN,MAAM;QAEvB,IAAI,CAAC,WAAW,GAAG,IAAIA,uBAAW,CAC9B,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,GAAG,EACH,OAAO,EACP,OAAO,EACP,MAAM,CACT;QAED,IAAI,CAAC,cAAc,GAAG,IAAIC,6BAAc,CAAC,QAAQ,EAAE,MAAM,CAAC;;AAG9D;;AAEG;AACH,IAAA,MAAM,WAAW,GAAA;AACb,QAAA,IAAI;;AAEA,YAAA,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,C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