@gitsense/gscb-git-tools 0.1.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 +189 -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 +187 -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 +40 -0
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+
3
+ var gscbDb = require('gscb-db');
4
+ var gscbGit = require('gscb-git');
5
+ var logger = require('../../common/logger.js');
6
+ var constants = require('../constants.js');
7
+ var importProcessor = require('./import-processor.js');
8
+ var errorHandler = require('./error-handler.js');
9
+
10
+ /**
11
+ * Component: Git Repository Importer (Core)
12
+ * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
13
+ * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
14
+ * Version: 6.6.0
15
+ * Purpose: Core implementation of GitImporter class
16
+ * Language: TypeScript
17
+ * Created-at: 2025-03-15T05:57:33.811Z
18
+ * 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)
19
+ */
20
+ class GitImporter {
21
+ repoPath;
22
+ repoOwner;
23
+ repoName;
24
+ ref;
25
+ refType;
26
+ dbPath;
27
+ options;
28
+ gitRepo;
29
+ dbClient;
30
+ logger;
31
+ initialized = false;
32
+ importProcessor;
33
+ errorHandler;
34
+ constructor(repoPath, repoOwner, repoName, ref, refType, dbPath, options = {}) {
35
+ this.repoPath = repoPath;
36
+ this.repoOwner = repoOwner;
37
+ this.repoName = repoName;
38
+ this.ref = ref;
39
+ this.refType = refType;
40
+ this.dbPath = dbPath;
41
+ this.options = options;
42
+ // Validate input parameters
43
+ if (!repoPath)
44
+ throw new Error('Repository path is required');
45
+ if (!repoOwner)
46
+ throw new Error('Repository owner is required');
47
+ if (!repoName)
48
+ throw new Error('Repository name is required');
49
+ if (!ref)
50
+ throw new Error('Reference is required');
51
+ if (!['branch', 'commit', 'tag'].includes(refType)) {
52
+ throw new Error('Reference type must be one of: branch, commit, tag');
53
+ }
54
+ if (!dbPath)
55
+ throw new Error('Database path is required');
56
+ // Merge default options
57
+ this.options = {
58
+ ...constants.DEFAULT_OPTIONS,
59
+ ...options
60
+ };
61
+ const gitConfig = {
62
+ repoPath,
63
+ ref,
64
+ };
65
+ this.gitRepo = new gscbGit.Repository(gitConfig);
66
+ const dbConfig = {
67
+ path: dbPath,
68
+ poolSize: 5,
69
+ timeout: 5000,
70
+ };
71
+ this.dbClient = new gscbDb.DatabaseClient(dbConfig);
72
+ this.logger = new logger.Logger(this.options.verbose || false);
73
+ // Initialize modules
74
+ this.importProcessor = new importProcessor.ImportProcessor(this.dbClient, this.gitRepo, this.repoOwner, this.repoName, this.ref, this.refType, this.options, this.logger);
75
+ this.errorHandler = new errorHandler.ErrorHandler(this.logger);
76
+ }
77
+ /**
78
+ * Initializes the Git repository, ref commit, and database connection.
79
+ */
80
+ async initialize() {
81
+ if (this.initialized) {
82
+ return;
83
+ }
84
+ this.logger.log('Initializing...');
85
+ try {
86
+ await this.gitRepo.initialize();
87
+ this.logger.log('Git repository initialized');
88
+ await this.dbClient.initialize();
89
+ this.logger.log('Database initialized');
90
+ this.initialized = true;
91
+ }
92
+ catch (error) {
93
+ throw new Error(`Initialization failed: ${error instanceof Error ? error.message : String(error)}`);
94
+ }
95
+ }
96
+ /**
97
+ * Imports the repository by setting up the chat hierarchy.
98
+ *
99
+ * @returns An object containing the ID of the git-ref chat
100
+ * @throws {Error} If initialization fails or chat hierarchy setup fails
101
+ */
102
+ async import() {
103
+ try {
104
+ await this.initialize();
105
+ return await this.importProcessor.setupImport();
106
+ }
107
+ catch (error) {
108
+ await this.errorHandler.handleError(error);
109
+ // This line is needed to satisfy TypeScript, though it will never be reached
110
+ // because handleError always throws
111
+ return { refChatId: -1 };
112
+ }
113
+ finally {
114
+ await this.cleanup();
115
+ }
116
+ }
117
+ /**
118
+ * Cleans up resources by closing the database connection.
119
+ */
120
+ async cleanup() {
121
+ if (this.dbClient.isInitialized()) {
122
+ try {
123
+ await this.dbClient.close();
124
+ this.logger.log('Database connection closed');
125
+ }
126
+ catch (error) {
127
+ this.logger.log('Error during database cleanup:', error, true);
128
+ }
129
+ }
130
+ this.initialized = false;
131
+ }
132
+ }
133
+
134
+ exports.GitImporter = GitImporter;
135
+ //# sourceMappingURL=importer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importer.js","sources":["../../../../src/importer/core/importer.ts"],"sourcesContent":[null],"names":["DEFAULT_OPTIONS","Repository","DatabaseClient","Logger","ImportProcessor","ErrorHandler"],"mappings":";;;;;;;;;AAAA;;;;;;;;;AASG;MAWU,WAAW,CAAA;AASC,IAAA,QAAA;AACA,IAAA,SAAA;AACA,IAAA,QAAA;AACA,IAAA,GAAA;AACA,IAAA,OAAA;AACA,IAAA,MAAA;AACA,IAAA,OAAA;AAdJ,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,MAAM;IACf,WAAW,GAAY,KAAK;AAC5B,IAAA,eAAe;AACf,IAAA,YAAY;AAEpB,IAAA,WAAA,CACqB,QAAgB,EAChB,SAAiB,EACjB,QAAgB,EAChB,GAAW,EACX,OAAgB,EAChB,MAAc,EACd,UAAyB,EAAE,EAAA;QAN3B,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAS,CAAA,SAAA,GAAT,SAAS;QACT,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAG,CAAA,GAAA,GAAH,GAAG;QACH,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAM,CAAA,MAAA,GAAN,MAAM;QACN,IAAO,CAAA,OAAA,GAAP,OAAO;;AAGxB,Q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C/B,YAAA,IAAI;AACA,gBAAA,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;AAC3B,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;;YAC/C,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,KAAK,EAAE,IAAI,CAAC;;;AAGtE,QAAA,IAAI,CAAC,WAAW,GAAG,KAAK;;AAE/B;;;;"}
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Component: Utilities
5
+ * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
6
+ * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
7
+ * Version: 6.6.0
8
+ * Purpose: Utility functions for GitImporter
9
+ * Language: TypeScript
10
+ * Created-at: 2025-03-15T06:02:35.714Z
11
+ * 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)
12
+ */
13
+ class Utils {
14
+ gitRepo;
15
+ logger;
16
+ constructor(gitRepo, logger) {
17
+ this.gitRepo = gitRepo;
18
+ this.logger = logger;
19
+ }
20
+ /**
21
+ * Normalizes a file path.
22
+ */
23
+ normalizePath(path) {
24
+ return path.replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
25
+ }
26
+ /**
27
+ * Validates that the repository exists and the reference is valid.
28
+ * @throws {Error} If the repository doesn't exist or the reference is invalid
29
+ */
30
+ async validateRepository(repoPath, ref, refType) {
31
+ if (!this.logger)
32
+ throw new Error('Logger not defined. Unable to call validateRepository');
33
+ if (!this.gitRepo)
34
+ throw new Error('Logger not defined. Unable to call validateRepository');
35
+ try {
36
+ this.logger.log("Validating repository...");
37
+ const repoInfo = await this.gitRepo.getInfo();
38
+ if (!repoInfo) {
39
+ throw new Error(`Repository not found at path: ${repoPath}`);
40
+ }
41
+ // Validate that the reference exists
42
+ const refExists = await this.gitRepo.hasRef(ref);
43
+ if (!refExists) {
44
+ throw new Error(`Reference ${ref} of type ${refType} not found in repository`);
45
+ }
46
+ this.logger.log("Repository validation successful");
47
+ }
48
+ catch (error) {
49
+ throw new Error(`Repository validation failed: ${error instanceof Error ? error.message : String(error)}`);
50
+ }
51
+ }
52
+ /**
53
+ * Determines the latest commit from an array of GitCommitInfo objects.
54
+ */
55
+ static getLatestCommit(commits) {
56
+ if (commits.length === 0) {
57
+ // If no commits, return an empty GitCommitInfo
58
+ return null;
59
+ }
60
+ // Find the commit with the latest timestamp
61
+ return commits.reduce((latest, commit) => commit.timestamp > latest.timestamp ? commit : latest);
62
+ }
63
+ }
64
+
65
+ exports.Utils = Utils;
66
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/importer/core/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;;;;;AASG;MAKU,KAAK,CAAA;AAEO,IAAA,OAAA;AACA,IAAA,MAAA;IAFrB,WACqB,CAAA,OAAoB,EACpB,MAAe,EAAA;QADf,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAM,CAAA,MAAA,GAAN,MAAM;;AAG3B;;AAEG;AACH,IAAA,aAAa,CAAC,IAAY,EAAA;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;;AAG3E;;;AAGG;AACH,IAAA,MAAM,kBAAkB,CAAC,QAAgB,EAAE,GAAW,EAAE,OAAoC,EAAA;QACxF,IAAI,CAAC,IAAI,CAAC,MAAM;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;QAC1F,IAAI,CAAC,IAAI,CAAC,OAAO;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AAE3F,QAAA,IAAI;AACA,YAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC;YAE3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YAC7C,IAAI,CAAC,QAAQ,EAAE;AACX,gBAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAA,CAAE,CAAC;;;YAIhE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;YAChD,IAAI,CAAC,SAAS,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,CAAA,UAAA,EAAa,GAAG,CAAY,SAAA,EAAA,OAAO,CAA0B,wBAAA,CAAA,CAAC;;AAGlF,YAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC;;QACrD,OAAO,KAAK,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,CAAA,8BAAA,EAAiC,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAE,CAAA,CAAC;;;AAIlH;;AAEG;IACH,OAAO,eAAe,CAAC,OAAwB,EAAA;AAC3C,QAAA,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;;AAEtB,YAAA,OAAO,IAAI;;;QAIf,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,KACjC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,CACxD;;AAER;;;;"}
@@ -0,0 +1,199 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var gscbUtils = require('gscb-utils');
5
+ var languageUtils = require('./language-utils.js');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var path__default = /*#__PURE__*/_interopDefault(path);
10
+
11
+ /**
12
+ * Component: File Processor
13
+ * Block-UUID: 27a7202c-94f0-4b35-8a34-c580a5f346a5
14
+ * Parent-UUID: 73378071-3284-4b9d-9354-436e49ed2f75
15
+ * Version: 5.1.0
16
+ * Description: Processes Git repository files for import, handling file creation, updates, and filtering
17
+ * Language: TypeScript
18
+ * Created-at: 2025-02-28T14:45:00.000Z
19
+ * Updated-at: 2025-03-24T00:45:00.000Z
20
+ * Authors: Claude 3.5 Sonnet (v3.0.0), Bard, together.ai - DeepSeek v3 (v3.3.0), together.ai - DeepSeek v3 (v4.0.0), together.ai - DeepSeek v3 (v5.0.0), Claude 3.7 Sonnet (v5.1.0)
21
+ */
22
+ class FileProcessor {
23
+ dbClient;
24
+ gitRepo;
25
+ chatManager;
26
+ options;
27
+ repoGroupId;
28
+ logger;
29
+ constructor(dbClient, gitRepo, chatManager, options, repoGroupId, logger) {
30
+ this.dbClient = dbClient;
31
+ this.gitRepo = gitRepo;
32
+ this.chatManager = chatManager;
33
+ this.options = options;
34
+ this.repoGroupId = repoGroupId;
35
+ this.logger = logger;
36
+ }
37
+ /**
38
+ * Estimates tokens using 1.33 tokens per word.
39
+ */
40
+ estimateTokens(text) {
41
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
42
+ return Math.ceil(wordCount * 1.33);
43
+ }
44
+ /**
45
+ * Processes a file and returns its GitCommitInfo.
46
+ * If the file already exists in the database, it will update the existing chat.
47
+ */
48
+ async processFile(filePath, parentChatId, orderWeight) {
49
+ try {
50
+ // Check if a chat for this file already exists
51
+ const fileName = path__default.default.basename(filePath);
52
+ const childChats = await this.dbClient.getChatsByParentId(parentChatId);
53
+ const existingFileChat = childChats.find(chat => chat.type === 'git-blob' &&
54
+ chat.name === fileName &&
55
+ chat.meta?.path === filePath);
56
+ if (existingFileChat) {
57
+ // Update existing file chat
58
+ return await this.updateExistingFile(existingFileChat.id, filePath);
59
+ }
60
+ else {
61
+ // Create new file chat
62
+ return await this.createNewFile(filePath, parentChatId, orderWeight);
63
+ }
64
+ }
65
+ catch (error) {
66
+ throw new Error(`Failed to process file '${filePath}': ${error instanceof Error ? error.message : String(error)}`);
67
+ }
68
+ }
69
+ /**
70
+ * Creates a new file chat.
71
+ */
72
+ async createNewFile(filePath, parentChatId, orderWeight) {
73
+ const fileInfo = await this.gitRepo.getFileInfo(filePath);
74
+ const fileCommitHash = await this.gitRepo.getFileCommitHash(filePath);
75
+ const commitInfo = await this.gitRepo.getCommitInfo(fileCommitHash);
76
+ const content = await this.gitRepo.readFile(filePath);
77
+ const now = new Date().toISOString();
78
+ const type = 'git-blob';
79
+ // Estimate tokens for content and metadata
80
+ const contentTokens = this.estimateTokens(content.toString());
81
+ const metaTokens = this.estimateTokens(JSON.stringify({
82
+ path: filePath,
83
+ name: path__default.default.basename(filePath),
84
+ commit: commitInfo,
85
+ blob: fileInfo.hash,
86
+ size: fileInfo.size,
87
+ language: await languageUtils.detectLanguage(filePath),
88
+ highlight: await languageUtils.getHighlightSyntax(filePath)
89
+ }));
90
+ const meta = {
91
+ type,
92
+ path: filePath,
93
+ name: path__default.default.basename(filePath),
94
+ commit: commitInfo,
95
+ blob: fileInfo.hash,
96
+ size: fileInfo.size,
97
+ language: await languageUtils.detectLanguage(filePath),
98
+ highlight: await languageUtils.getHighlightSyntax(filePath),
99
+ tokens: {
100
+ content: { estimate: contentTokens, estimatedAt: now },
101
+ metadata: { estimate: metaTokens, estimatedAt: now }
102
+ },
103
+ importStartedAt: now,
104
+ importFinishedAt: now,
105
+ status: 'imported'
106
+ };
107
+ await this.chatManager.createChat(type, path__default.default.basename(filePath), parentChatId, this.repoGroupId, meta, content.toString(), orderWeight);
108
+ return commitInfo;
109
+ }
110
+ /**
111
+ * Updates an existing file chat.
112
+ */
113
+ async updateExistingFile(chatId, filePath) {
114
+ // Get the current file information
115
+ const fileInfo = await this.gitRepo.getFileInfo(filePath);
116
+ const fileCommitHash = await this.gitRepo.getFileCommitHash(filePath);
117
+ const commitInfo = await this.gitRepo.getCommitInfo(fileCommitHash);
118
+ const content = await this.gitRepo.readFile(filePath);
119
+ const now = new Date().toISOString();
120
+ // Get the existing chat and meta
121
+ const chat = await this.chatManager.getChatById(chatId);
122
+ const oldMeta = chat.meta;
123
+ // Skip update if the commit hash hasn't changed
124
+ if (oldMeta.commit?.hash === commitInfo.hash) {
125
+ this.logger.log(`Skipping update for file '${filePath}' (commit hash unchanged)`);
126
+ return commitInfo;
127
+ }
128
+ // Estimate tokens for content and metadata
129
+ const contentTokens = this.estimateTokens(content.toString());
130
+ const metaTokens = this.estimateTokens(JSON.stringify({
131
+ path: filePath,
132
+ name: path__default.default.basename(filePath),
133
+ commit: commitInfo,
134
+ blob: fileInfo.hash,
135
+ size: fileInfo.size,
136
+ language: await languageUtils.detectLanguage(filePath),
137
+ highlight: await languageUtils.getHighlightSyntax(filePath)
138
+ }));
139
+ // Create updated metadata
140
+ const updatedMeta = {
141
+ ...oldMeta,
142
+ commit: commitInfo,
143
+ blob: fileInfo.hash,
144
+ size: fileInfo.size,
145
+ importFinishedAt: now,
146
+ status: 'imported'
147
+ };
148
+ // We don't want to override tokens.analysis with a shallow copy
149
+ updatedMeta.tokens.content = { estimate: contentTokens, estimatedAt: now },
150
+ updatedMeta.tokens.metadata = { estimate: metaTokens, estimatedAt: now };
151
+ // Update the chat metadata
152
+ await this.chatManager.updateFileMetadata(chatId, filePath, commitInfo);
153
+ // Update the meta message
154
+ const metaMessage = await this.chatManager.getMessageByChatIdAndType(chatId, 'chat-meta');
155
+ await this.chatManager.updateMessage(metaMessage.id, {
156
+ message: JSON.stringify(updatedMeta, null, 2)
157
+ });
158
+ // Update the main message with new content
159
+ const mainMessage = await this.chatManager.getMessageByChatIdAndType(chatId, 'git-blob');
160
+ const gitBlobMessage = content.toString();
161
+ await this.chatManager.updateMessage(mainMessage.id, {
162
+ message: gitBlobMessage
163
+ });
164
+ return commitInfo;
165
+ }
166
+ /**
167
+ * Determines whether a file should be skipped based on the provided patterns.
168
+ */
169
+ async shouldSkipFile(filePath) {
170
+ const { skipPatterns, includePatterns, skipBinaryFiles } = this.options;
171
+ // Check against skip patterns first (fastest check)
172
+ if (skipPatterns?.some(pattern => pattern.test(filePath))) {
173
+ this.logger.log(`Skipping file '${filePath}' (matched skip pattern)`);
174
+ return true;
175
+ }
176
+ // Check if file is binary (if skipBinaryFiles is enabled)
177
+ if (skipBinaryFiles) {
178
+ try {
179
+ const isBinary = await gscbUtils.FSUtils.isBinaryFile(filePath);
180
+ if (isBinary) {
181
+ this.logger.log(`Skipping binary file '${filePath}'`);
182
+ return true;
183
+ }
184
+ }
185
+ catch (error) {
186
+ this.logger.log(`Error checking if file '${filePath}' is binary: ${error instanceof Error ? error.message : String(error)}`);
187
+ }
188
+ }
189
+ // Check against include patterns if specified
190
+ if (includePatterns?.length && !includePatterns.some(pattern => pattern.test(filePath))) {
191
+ this.logger.log(`Skipping file '${filePath}' (did not match include pattern)`);
192
+ return true;
193
+ }
194
+ return false;
195
+ }
196
+ }
197
+
198
+ exports.FileProcessor = FileProcessor;
199
+ //# sourceMappingURL=file-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-processor.js","sources":["../../../src/importer/file-processor.ts"],"sourcesContent":[null],"names":["path","detectLanguage","getHighlightSyntax","FSUtils"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;AAUG;MAaU,aAAa,CAAA;AAED,IAAA,QAAA;AACA,IAAA,OAAA;AACA,IAAA,WAAA;AACA,IAAA,OAAA;AACA,IAAA,WAAA;AACA,IAAA,MAAA;IANrB,WACqB,CAAA,QAAwB,EACxB,OAAmB,EACnB,WAAwB,EACxB,OAAsB,EACtB,WAAmB,EACnB,MAAc,EAAA;QALd,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACR,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAW,CAAA,WAAA,GAAX,WAAW;QACX,IAAO,CAAA,OAAA,GAAP,OAAO;QACP,IAAW,CAAA,WAAA,GAAX,WA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