@gitsense/gscb-git-tools 0.1.0 → 0.2.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/package.json +1 -1
  2. package/dist/cjs/common/logger.js +0 -97
  3. package/dist/cjs/common/logger.js.map +0 -1
  4. package/dist/cjs/common/metadata-manager.js +0 -196
  5. package/dist/cjs/common/metadata-manager.js.map +0 -1
  6. package/dist/cjs/importer/chat-manager/chat-creator.js +0 -90
  7. package/dist/cjs/importer/chat-manager/chat-creator.js.map +0 -1
  8. package/dist/cjs/importer/chat-manager/chat-manager.js +0 -179
  9. package/dist/cjs/importer/chat-manager/chat-manager.js.map +0 -1
  10. package/dist/cjs/importer/chat-manager/constants.js +0 -66
  11. package/dist/cjs/importer/chat-manager/constants.js.map +0 -1
  12. package/dist/cjs/importer/chat-manager/group-manager.js +0 -56
  13. package/dist/cjs/importer/chat-manager/group-manager.js.map +0 -1
  14. package/dist/cjs/importer/chat-manager/hierarchy-manager.js +0 -115
  15. package/dist/cjs/importer/chat-manager/hierarchy-manager.js.map +0 -1
  16. package/dist/cjs/importer/chat-manager/message-manager.js +0 -189
  17. package/dist/cjs/importer/chat-manager/message-manager.js.map +0 -1
  18. package/dist/cjs/importer/constants.js +0 -30
  19. package/dist/cjs/importer/constants.js.map +0 -1
  20. package/dist/cjs/importer/core/directory-processor.js +0 -343
  21. package/dist/cjs/importer/core/directory-processor.js.map +0 -1
  22. package/dist/cjs/importer/core/error-handler.js +0 -64
  23. package/dist/cjs/importer/core/error-handler.js.map +0 -1
  24. package/dist/cjs/importer/core/import-processor.js +0 -167
  25. package/dist/cjs/importer/core/import-processor.js.map +0 -1
  26. package/dist/cjs/importer/core/importer.js +0 -135
  27. package/dist/cjs/importer/core/importer.js.map +0 -1
  28. package/dist/cjs/importer/core/utils.js +0 -66
  29. package/dist/cjs/importer/core/utils.js.map +0 -1
  30. package/dist/cjs/importer/file-processor.js +0 -199
  31. package/dist/cjs/importer/file-processor.js.map +0 -1
  32. package/dist/cjs/importer/language-utils.js +0 -286
  33. package/dist/cjs/importer/language-utils.js.map +0 -1
  34. package/dist/cjs/importer/tree-processor.js +0 -119
  35. package/dist/cjs/importer/tree-processor.js.map +0 -1
  36. package/dist/cjs/index.js +0 -12
  37. package/dist/cjs/index.js.map +0 -1
  38. package/dist/cjs/package.json +0 -3
  39. package/dist/esm/common/logger.js +0 -95
  40. package/dist/esm/common/logger.js.map +0 -1
  41. package/dist/esm/common/metadata-manager.js +0 -194
  42. package/dist/esm/common/metadata-manager.js.map +0 -1
  43. package/dist/esm/importer/chat-manager/chat-creator.js +0 -88
  44. package/dist/esm/importer/chat-manager/chat-creator.js.map +0 -1
  45. package/dist/esm/importer/chat-manager/chat-manager.js +0 -177
  46. package/dist/esm/importer/chat-manager/chat-manager.js.map +0 -1
  47. package/dist/esm/importer/chat-manager/constants.js +0 -48
  48. package/dist/esm/importer/chat-manager/constants.js.map +0 -1
  49. package/dist/esm/importer/chat-manager/group-manager.js +0 -54
  50. package/dist/esm/importer/chat-manager/group-manager.js.map +0 -1
  51. package/dist/esm/importer/chat-manager/hierarchy-manager.js +0 -113
  52. package/dist/esm/importer/chat-manager/hierarchy-manager.js.map +0 -1
  53. package/dist/esm/importer/chat-manager/message-manager.js +0 -187
  54. package/dist/esm/importer/chat-manager/message-manager.js.map +0 -1
  55. package/dist/esm/importer/constants.js +0 -28
  56. package/dist/esm/importer/constants.js.map +0 -1
  57. package/dist/esm/importer/core/directory-processor.js +0 -337
  58. package/dist/esm/importer/core/directory-processor.js.map +0 -1
  59. package/dist/esm/importer/core/error-handler.js +0 -62
  60. package/dist/esm/importer/core/error-handler.js.map +0 -1
  61. package/dist/esm/importer/core/import-processor.js +0 -165
  62. package/dist/esm/importer/core/import-processor.js.map +0 -1
  63. package/dist/esm/importer/core/importer.js +0 -133
  64. package/dist/esm/importer/core/importer.js.map +0 -1
  65. package/dist/esm/importer/core/utils.js +0 -64
  66. package/dist/esm/importer/core/utils.js.map +0 -1
  67. package/dist/esm/importer/file-processor.js +0 -193
  68. package/dist/esm/importer/file-processor.js.map +0 -1
  69. package/dist/esm/importer/language-utils.js +0 -279
  70. package/dist/esm/importer/language-utils.js.map +0 -1
  71. package/dist/esm/importer/tree-processor.js +0 -113
  72. package/dist/esm/importer/tree-processor.js.map +0 -1
  73. package/dist/esm/index.js +0 -4
  74. package/dist/esm/index.js.map +0 -1
  75. package/dist/index.d.ts +0 -215
@@ -1,133 +0,0 @@
1
- import { DatabaseClient } from 'gscb-db';
2
- import { Repository } from 'gscb-git';
3
- import { Logger } from '../../common/logger.js';
4
- import { DEFAULT_OPTIONS } from '../constants.js';
5
- import { ImportProcessor } from './import-processor.js';
6
- import { ErrorHandler } from './error-handler.js';
7
-
8
- /**
9
- * Component: Git Repository Importer (Core)
10
- * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
11
- * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
12
- * Version: 6.6.0
13
- * Purpose: Core implementation of GitImporter class
14
- * Language: TypeScript
15
- * Created-at: 2025-03-15T05:57:33.811Z
16
- * 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)
17
- */
18
- class GitImporter {
19
- repoPath;
20
- repoOwner;
21
- repoName;
22
- ref;
23
- refType;
24
- dbPath;
25
- options;
26
- gitRepo;
27
- dbClient;
28
- logger;
29
- initialized = false;
30
- importProcessor;
31
- errorHandler;
32
- constructor(repoPath, repoOwner, repoName, ref, refType, dbPath, options = {}) {
33
- this.repoPath = repoPath;
34
- this.repoOwner = repoOwner;
35
- this.repoName = repoName;
36
- this.ref = ref;
37
- this.refType = refType;
38
- this.dbPath = dbPath;
39
- this.options = options;
40
- // Validate input parameters
41
- if (!repoPath)
42
- throw new Error('Repository path is required');
43
- if (!repoOwner)
44
- throw new Error('Repository owner is required');
45
- if (!repoName)
46
- throw new Error('Repository name is required');
47
- if (!ref)
48
- throw new Error('Reference is required');
49
- if (!['branch', 'commit', 'tag'].includes(refType)) {
50
- throw new Error('Reference type must be one of: branch, commit, tag');
51
- }
52
- if (!dbPath)
53
- throw new Error('Database path is required');
54
- // Merge default options
55
- this.options = {
56
- ...DEFAULT_OPTIONS,
57
- ...options
58
- };
59
- const gitConfig = {
60
- repoPath,
61
- ref,
62
- };
63
- this.gitRepo = new Repository(gitConfig);
64
- const dbConfig = {
65
- path: dbPath,
66
- poolSize: 5,
67
- timeout: 5000,
68
- };
69
- this.dbClient = new DatabaseClient(dbConfig);
70
- this.logger = new Logger(this.options.verbose || false);
71
- // Initialize modules
72
- this.importProcessor = new ImportProcessor(this.dbClient, this.gitRepo, this.repoOwner, this.repoName, this.ref, this.refType, this.options, this.logger);
73
- this.errorHandler = new ErrorHandler(this.logger);
74
- }
75
- /**
76
- * Initializes the Git repository, ref commit, and database connection.
77
- */
78
- async initialize() {
79
- if (this.initialized) {
80
- return;
81
- }
82
- this.logger.log('Initializing...');
83
- try {
84
- await this.gitRepo.initialize();
85
- this.logger.log('Git repository initialized');
86
- await this.dbClient.initialize();
87
- this.logger.log('Database initialized');
88
- this.initialized = true;
89
- }
90
- catch (error) {
91
- throw new Error(`Initialization failed: ${error instanceof Error ? error.message : String(error)}`);
92
- }
93
- }
94
- /**
95
- * Imports the repository by setting up the chat hierarchy.
96
- *
97
- * @returns An object containing the ID of the git-ref chat
98
- * @throws {Error} If initialization fails or chat hierarchy setup fails
99
- */
100
- async import() {
101
- try {
102
- await this.initialize();
103
- return await this.importProcessor.setupImport();
104
- }
105
- catch (error) {
106
- await this.errorHandler.handleError(error);
107
- // This line is needed to satisfy TypeScript, though it will never be reached
108
- // because handleError always throws
109
- return { refChatId: -1 };
110
- }
111
- finally {
112
- await this.cleanup();
113
- }
114
- }
115
- /**
116
- * Cleans up resources by closing the database connection.
117
- */
118
- async cleanup() {
119
- if (this.dbClient.isInitialized()) {
120
- try {
121
- await this.dbClient.close();
122
- this.logger.log('Database connection closed');
123
- }
124
- catch (error) {
125
- this.logger.log('Error during database cleanup:', error, true);
126
- }
127
- }
128
- this.initialized = false;
129
- }
130
- }
131
-
132
- export { GitImporter };
133
- //# sourceMappingURL=importer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"importer.js","sources":["../../../../src/importer/core/importer.ts"],"sourcesContent":[null],"names":[],"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,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC;AAC7D,QAAA,IAAI,CAAC,SAAS;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;AAC/D,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC;AAC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AAA,IAAI,CAAC,WAAW,GAAG,KAAK;;AAE/B;;;;"}
@@ -1,64 +0,0 @@
1
- /**
2
- * Component: Utilities
3
- * Block-UUID: 237b8cc5-5d1b-4285-82c4-0e1f49459f2c
4
- * Parent-UUID: 31839e44-58af-43ea-baab-96674d745ad0
5
- * Version: 6.6.0
6
- * Purpose: Utility functions for GitImporter
7
- * Language: TypeScript
8
- * Created-at: 2025-03-15T06:02:35.714Z
9
- * 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)
10
- */
11
- class Utils {
12
- gitRepo;
13
- logger;
14
- constructor(gitRepo, logger) {
15
- this.gitRepo = gitRepo;
16
- this.logger = logger;
17
- }
18
- /**
19
- * Normalizes a file path.
20
- */
21
- normalizePath(path) {
22
- return path.replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
23
- }
24
- /**
25
- * Validates that the repository exists and the reference is valid.
26
- * @throws {Error} If the repository doesn't exist or the reference is invalid
27
- */
28
- async validateRepository(repoPath, ref, refType) {
29
- if (!this.logger)
30
- throw new Error('Logger not defined. Unable to call validateRepository');
31
- if (!this.gitRepo)
32
- throw new Error('Logger not defined. Unable to call validateRepository');
33
- try {
34
- this.logger.log("Validating repository...");
35
- const repoInfo = await this.gitRepo.getInfo();
36
- if (!repoInfo) {
37
- throw new Error(`Repository not found at path: ${repoPath}`);
38
- }
39
- // Validate that the reference exists
40
- const refExists = await this.gitRepo.hasRef(ref);
41
- if (!refExists) {
42
- throw new Error(`Reference ${ref} of type ${refType} not found in repository`);
43
- }
44
- this.logger.log("Repository validation successful");
45
- }
46
- catch (error) {
47
- throw new Error(`Repository validation failed: ${error instanceof Error ? error.message : String(error)}`);
48
- }
49
- }
50
- /**
51
- * Determines the latest commit from an array of GitCommitInfo objects.
52
- */
53
- static getLatestCommit(commits) {
54
- if (commits.length === 0) {
55
- // If no commits, return an empty GitCommitInfo
56
- return null;
57
- }
58
- // Find the commit with the latest timestamp
59
- return commits.reduce((latest, commit) => commit.timestamp > latest.timestamp ? commit : latest);
60
- }
61
- }
62
-
63
- export { Utils };
64
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
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;;;;"}
@@ -1,193 +0,0 @@
1
- import path from 'path';
2
- import { FSUtils } from 'gscb-utils';
3
- import { getHighlightSyntax, detectLanguage } from './language-utils.js';
4
-
5
- /**
6
- * Component: File Processor
7
- * Block-UUID: 27a7202c-94f0-4b35-8a34-c580a5f346a5
8
- * Parent-UUID: 73378071-3284-4b9d-9354-436e49ed2f75
9
- * Version: 5.1.0
10
- * Description: Processes Git repository files for import, handling file creation, updates, and filtering
11
- * Language: TypeScript
12
- * Created-at: 2025-02-28T14:45:00.000Z
13
- * Updated-at: 2025-03-24T00:45:00.000Z
14
- * 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)
15
- */
16
- class FileProcessor {
17
- dbClient;
18
- gitRepo;
19
- chatManager;
20
- options;
21
- repoGroupId;
22
- logger;
23
- constructor(dbClient, gitRepo, chatManager, options, repoGroupId, logger) {
24
- this.dbClient = dbClient;
25
- this.gitRepo = gitRepo;
26
- this.chatManager = chatManager;
27
- this.options = options;
28
- this.repoGroupId = repoGroupId;
29
- this.logger = logger;
30
- }
31
- /**
32
- * Estimates tokens using 1.33 tokens per word.
33
- */
34
- estimateTokens(text) {
35
- const wordCount = text.split(/\s+/).filter(Boolean).length;
36
- return Math.ceil(wordCount * 1.33);
37
- }
38
- /**
39
- * Processes a file and returns its GitCommitInfo.
40
- * If the file already exists in the database, it will update the existing chat.
41
- */
42
- async processFile(filePath, parentChatId, orderWeight) {
43
- try {
44
- // Check if a chat for this file already exists
45
- const fileName = path.basename(filePath);
46
- const childChats = await this.dbClient.getChatsByParentId(parentChatId);
47
- const existingFileChat = childChats.find(chat => chat.type === 'git-blob' &&
48
- chat.name === fileName &&
49
- chat.meta?.path === filePath);
50
- if (existingFileChat) {
51
- // Update existing file chat
52
- return await this.updateExistingFile(existingFileChat.id, filePath);
53
- }
54
- else {
55
- // Create new file chat
56
- return await this.createNewFile(filePath, parentChatId, orderWeight);
57
- }
58
- }
59
- catch (error) {
60
- throw new Error(`Failed to process file '${filePath}': ${error instanceof Error ? error.message : String(error)}`);
61
- }
62
- }
63
- /**
64
- * Creates a new file chat.
65
- */
66
- async createNewFile(filePath, parentChatId, orderWeight) {
67
- const fileInfo = await this.gitRepo.getFileInfo(filePath);
68
- const fileCommitHash = await this.gitRepo.getFileCommitHash(filePath);
69
- const commitInfo = await this.gitRepo.getCommitInfo(fileCommitHash);
70
- const content = await this.gitRepo.readFile(filePath);
71
- const now = new Date().toISOString();
72
- const type = 'git-blob';
73
- // Estimate tokens for content and metadata
74
- const contentTokens = this.estimateTokens(content.toString());
75
- const metaTokens = this.estimateTokens(JSON.stringify({
76
- path: filePath,
77
- name: path.basename(filePath),
78
- commit: commitInfo,
79
- blob: fileInfo.hash,
80
- size: fileInfo.size,
81
- language: await detectLanguage(filePath),
82
- highlight: await getHighlightSyntax(filePath)
83
- }));
84
- const meta = {
85
- type,
86
- path: filePath,
87
- name: path.basename(filePath),
88
- commit: commitInfo,
89
- blob: fileInfo.hash,
90
- size: fileInfo.size,
91
- language: await detectLanguage(filePath),
92
- highlight: await getHighlightSyntax(filePath),
93
- tokens: {
94
- content: { estimate: contentTokens, estimatedAt: now },
95
- metadata: { estimate: metaTokens, estimatedAt: now }
96
- },
97
- importStartedAt: now,
98
- importFinishedAt: now,
99
- status: 'imported'
100
- };
101
- await this.chatManager.createChat(type, path.basename(filePath), parentChatId, this.repoGroupId, meta, content.toString(), orderWeight);
102
- return commitInfo;
103
- }
104
- /**
105
- * Updates an existing file chat.
106
- */
107
- async updateExistingFile(chatId, filePath) {
108
- // Get the current file information
109
- const fileInfo = await this.gitRepo.getFileInfo(filePath);
110
- const fileCommitHash = await this.gitRepo.getFileCommitHash(filePath);
111
- const commitInfo = await this.gitRepo.getCommitInfo(fileCommitHash);
112
- const content = await this.gitRepo.readFile(filePath);
113
- const now = new Date().toISOString();
114
- // Get the existing chat and meta
115
- const chat = await this.chatManager.getChatById(chatId);
116
- const oldMeta = chat.meta;
117
- // Skip update if the commit hash hasn't changed
118
- if (oldMeta.commit?.hash === commitInfo.hash) {
119
- this.logger.log(`Skipping update for file '${filePath}' (commit hash unchanged)`);
120
- return commitInfo;
121
- }
122
- // Estimate tokens for content and metadata
123
- const contentTokens = this.estimateTokens(content.toString());
124
- const metaTokens = this.estimateTokens(JSON.stringify({
125
- path: filePath,
126
- name: path.basename(filePath),
127
- commit: commitInfo,
128
- blob: fileInfo.hash,
129
- size: fileInfo.size,
130
- language: await detectLanguage(filePath),
131
- highlight: await getHighlightSyntax(filePath)
132
- }));
133
- // Create updated metadata
134
- const updatedMeta = {
135
- ...oldMeta,
136
- commit: commitInfo,
137
- blob: fileInfo.hash,
138
- size: fileInfo.size,
139
- importFinishedAt: now,
140
- status: 'imported'
141
- };
142
- // We don't want to override tokens.analysis with a shallow copy
143
- updatedMeta.tokens.content = { estimate: contentTokens, estimatedAt: now },
144
- updatedMeta.tokens.metadata = { estimate: metaTokens, estimatedAt: now };
145
- // Update the chat metadata
146
- await this.chatManager.updateFileMetadata(chatId, filePath, commitInfo);
147
- // Update the meta message
148
- const metaMessage = await this.chatManager.getMessageByChatIdAndType(chatId, 'chat-meta');
149
- await this.chatManager.updateMessage(metaMessage.id, {
150
- message: JSON.stringify(updatedMeta, null, 2)
151
- });
152
- // Update the main message with new content
153
- const mainMessage = await this.chatManager.getMessageByChatIdAndType(chatId, 'git-blob');
154
- const gitBlobMessage = content.toString();
155
- await this.chatManager.updateMessage(mainMessage.id, {
156
- message: gitBlobMessage
157
- });
158
- return commitInfo;
159
- }
160
- /**
161
- * Determines whether a file should be skipped based on the provided patterns.
162
- */
163
- async shouldSkipFile(filePath) {
164
- const { skipPatterns, includePatterns, skipBinaryFiles } = this.options;
165
- // Check against skip patterns first (fastest check)
166
- if (skipPatterns?.some(pattern => pattern.test(filePath))) {
167
- this.logger.log(`Skipping file '${filePath}' (matched skip pattern)`);
168
- return true;
169
- }
170
- // Check if file is binary (if skipBinaryFiles is enabled)
171
- if (skipBinaryFiles) {
172
- try {
173
- const isBinary = await FSUtils.isBinaryFile(filePath);
174
- if (isBinary) {
175
- this.logger.log(`Skipping binary file '${filePath}'`);
176
- return true;
177
- }
178
- }
179
- catch (error) {
180
- this.logger.log(`Error checking if file '${filePath}' is binary: ${error instanceof Error ? error.message : String(error)}`);
181
- }
182
- }
183
- // Check against include patterns if specified
184
- if (includePatterns?.length && !includePatterns.some(pattern => pattern.test(filePath))) {
185
- this.logger.log(`Skipping file '${filePath}' (did not match include pattern)`);
186
- return true;
187
- }
188
- return false;
189
- }
190
- }
191
-
192
- export { FileProcessor };
193
- //# sourceMappingURL=file-processor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-processor.js","sources":["../../../src/importer/file-processor.ts"],"sourcesContent":[null],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