@codebolt/agent 1.2.1 → 2.2.2

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 (183) hide show
  1. package/README.md +157 -66
  2. package/dist/builderpattern/agent.d.ts +86 -0
  3. package/dist/builderpattern/agent.js +324 -0
  4. package/dist/builderpattern/followupquestionbuilder.d.ts +75 -0
  5. package/dist/builderpattern/followupquestionbuilder.js +197 -0
  6. package/dist/builderpattern/index.d.ts +14 -0
  7. package/dist/builderpattern/index.js +23 -0
  8. package/dist/builderpattern/llmoutputhandler.d.ts +102 -0
  9. package/dist/builderpattern/llmoutputhandler.js +452 -0
  10. package/dist/builderpattern/promptbuilder.d.ts +382 -0
  11. package/dist/builderpattern/promptbuilder.js +805 -0
  12. package/dist/builderpattern/systemprompt.d.ts +20 -0
  13. package/dist/builderpattern/systemprompt.js +48 -0
  14. package/dist/builderpattern/taskInstruction.d.ts +37 -0
  15. package/dist/builderpattern/taskInstruction.js +57 -0
  16. package/dist/builderpattern/usermessage.d.ts +70 -0
  17. package/dist/builderpattern/usermessage.js +123 -0
  18. package/dist/composablepattern/agent.d.ts +169 -0
  19. package/dist/composablepattern/agent.js +598 -0
  20. package/dist/composablepattern/codebolt-storage.d.ts +67 -0
  21. package/dist/composablepattern/codebolt-storage.js +320 -0
  22. package/dist/composablepattern/document.d.ts +149 -0
  23. package/dist/composablepattern/document.js +405 -0
  24. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +12 -0
  25. package/dist/composablepattern/examples/codebolt-integration-example.js +218 -0
  26. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +40 -0
  27. package/dist/composablepattern/examples/codebolt-storage-example.js +223 -0
  28. package/dist/composablepattern/examples/custom-steps-example.d.ts +20 -0
  29. package/dist/composablepattern/examples/custom-steps-example.js +455 -0
  30. package/dist/composablepattern/examples/document-agent.d.ts +17 -0
  31. package/dist/composablepattern/examples/document-agent.js +107 -0
  32. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +8 -0
  33. package/dist/composablepattern/examples/simple-codebolt-integration.js +164 -0
  34. package/dist/composablepattern/examples/weather-agent.d.ts +18 -0
  35. package/dist/composablepattern/examples/weather-agent.js +86 -0
  36. package/dist/composablepattern/examples/workflow-example.d.ts +12 -0
  37. package/dist/composablepattern/examples/workflow-example.js +463 -0
  38. package/dist/composablepattern/index.d.ts +63 -0
  39. package/dist/composablepattern/index.js +115 -0
  40. package/dist/composablepattern/memory.d.ts +89 -0
  41. package/dist/composablepattern/memory.js +141 -0
  42. package/dist/composablepattern/tool.d.ts +84 -0
  43. package/dist/composablepattern/tool.js +260 -0
  44. package/dist/composablepattern/types.d.ts +194 -0
  45. package/dist/composablepattern/types.js +6 -0
  46. package/dist/composablepattern/user-context.d.ts +214 -0
  47. package/dist/composablepattern/user-context.js +275 -0
  48. package/dist/composablepattern/workflow.d.ts +388 -0
  49. package/dist/composablepattern/workflow.js +562 -0
  50. package/dist/processor/agent/agentStep.d.ts +49 -0
  51. package/dist/processor/agent/agentStep.js +241 -0
  52. package/dist/processor/agent/toolExecutor.d.ts +19 -0
  53. package/dist/processor/agent/toolExecutor.js +90 -0
  54. package/dist/processor/index.d.ts +7 -0
  55. package/dist/processor/index.js +36 -0
  56. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +20 -0
  57. package/dist/processor/messageModifiers/baseMessageModifier.js +55 -0
  58. package/dist/processor/processors/baseProcessor.d.ts +14 -0
  59. package/dist/processor/processors/baseProcessor.js +29 -0
  60. package/dist/processor/tools/baseTool.d.ts +10 -0
  61. package/dist/processor/tools/baseTool.js +20 -0
  62. package/dist/processor/tools/toolList.d.ts +9 -0
  63. package/dist/processor/tools/toolList.js +22 -0
  64. package/dist/processor/types/interfaces.d.ts +94 -0
  65. package/dist/processor/types/interfaces.js +2 -0
  66. package/dist/processor-pieces/base/baseMessageModifier.d.ts +12 -0
  67. package/dist/processor-pieces/base/baseMessageModifier.js +15 -0
  68. package/dist/processor-pieces/base/basePostInferenceProcessor.d.ts +13 -0
  69. package/dist/processor-pieces/base/basePostInferenceProcessor.js +18 -0
  70. package/dist/processor-pieces/base/basePostToolCallProcessor.d.ts +15 -0
  71. package/dist/processor-pieces/base/basePostToolCallProcessor.js +25 -0
  72. package/dist/processor-pieces/base/basePreInferenceProcessor.d.ts +12 -0
  73. package/dist/processor-pieces/base/basePreInferenceProcessor.js +17 -0
  74. package/dist/processor-pieces/base/basePreToolCallProcessor.d.ts +18 -0
  75. package/dist/processor-pieces/base/basePreToolCallProcessor.js +66 -0
  76. package/dist/processor-pieces/base/index.d.ts +9 -0
  77. package/dist/processor-pieces/base/index.js +18 -0
  78. package/dist/processor-pieces/index.d.ts +1 -0
  79. package/dist/processor-pieces/index.js +59 -0
  80. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +22 -0
  81. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +144 -0
  82. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +13 -0
  83. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +68 -0
  84. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +25 -0
  85. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +453 -0
  86. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +15 -0
  87. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +75 -0
  88. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +11 -0
  89. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +46 -0
  90. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +18 -0
  91. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +104 -0
  92. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +23 -0
  93. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +173 -0
  94. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +14 -0
  95. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +130 -0
  96. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +36 -0
  97. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +418 -0
  98. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +26 -0
  99. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +260 -0
  100. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +12 -0
  101. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +60 -0
  102. package/dist/processor-pieces/messageModifiers/ideContextModifier.d.ts +34 -0
  103. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +157 -0
  104. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +18 -0
  105. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +222 -0
  106. package/dist/processor-pieces/messageModifiers/index.d.ts +11 -0
  107. package/dist/processor-pieces/messageModifiers/index.js +26 -0
  108. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +15 -0
  109. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +129 -0
  110. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +20 -0
  111. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +152 -0
  112. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +22 -0
  113. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +194 -0
  114. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.d.ts +29 -0
  115. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +174 -0
  116. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -0
  117. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -0
  118. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.d.ts +25 -0
  119. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +225 -0
  120. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +35 -0
  121. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +255 -0
  122. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -0
  123. package/dist/processor-pieces/preInferenceProcessors/index.js +2 -0
  124. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +1 -0
  125. package/dist/processor-pieces/pretoolCallProcessors/index.js +2 -0
  126. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +41 -0
  127. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +197 -0
  128. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +26 -0
  129. package/dist/processor-pieces/processors/chatCompressionProcessor.js +90 -0
  130. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +81 -0
  131. package/dist/processor-pieces/processors/chatRecordingProcessor.js +329 -0
  132. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +40 -0
  133. package/dist/processor-pieces/processors/contextManagementProcessor.js +305 -0
  134. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +30 -0
  135. package/dist/processor-pieces/processors/loopDetectionProcessor.js +137 -0
  136. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +30 -0
  137. package/dist/processor-pieces/processors/responseValidationProcessor.js +228 -0
  138. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +99 -0
  139. package/dist/processor-pieces/processors/telemetryProcessor.js +311 -0
  140. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +37 -0
  141. package/dist/processor-pieces/processors/tokenManagementProcessor.js +178 -0
  142. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +43 -0
  143. package/dist/processor-pieces/processors/toolExecutionProcessor.js +207 -0
  144. package/dist/processor-pieces/tools/fileTools.d.ts +26 -0
  145. package/dist/processor-pieces/tools/fileTools.js +162 -0
  146. package/dist/processor-pieces/utils/messageModifierHelper.d.ts +4 -0
  147. package/dist/processor-pieces/utils/messageModifierHelper.js +58 -0
  148. package/dist/types/commonTypes.d.ts +4 -0
  149. package/dist/types/processorTypes.d.ts +67 -0
  150. package/dist/types/processorTypes.js +58 -0
  151. package/dist/unified/agent/agent.d.ts +17 -0
  152. package/dist/unified/agent/agent.js +79 -0
  153. package/dist/unified/agent/team.d.ts +2 -0
  154. package/dist/unified/agent/team.js +6 -0
  155. package/dist/unified/agent/tools.d.ts +44 -0
  156. package/dist/unified/agent/tools.js +487 -0
  157. package/dist/unified/agent/workflow.d.ts +24 -0
  158. package/dist/unified/agent/workflow.js +275 -0
  159. package/dist/unified/agent/workflowControls.d.ts +11 -0
  160. package/dist/unified/agent/workflowControls.js +20 -0
  161. package/dist/unified/agent/workflowSteps.d.ts +63 -0
  162. package/dist/unified/agent/workflowSteps.js +284 -0
  163. package/dist/unified/base/agentStep.d.ts +32 -0
  164. package/dist/unified/base/agentStep.js +96 -0
  165. package/dist/unified/base/create/createInitialPromptGenerators.d.ts +5 -0
  166. package/dist/unified/base/create/createInitialPromptGenerators.js +17 -0
  167. package/dist/unified/base/index.d.ts +5 -0
  168. package/dist/unified/base/index.js +13 -0
  169. package/dist/unified/base/initialPromptGenerator.d.ts +48 -0
  170. package/dist/unified/base/initialPromptGenerator.js +118 -0
  171. package/dist/unified/base/responseExecutor.d.ts +36 -0
  172. package/dist/unified/base/responseExecutor.js +283 -0
  173. package/dist/unified/index.d.ts +18 -0
  174. package/dist/unified/index.js +42 -0
  175. package/dist/unified/team/team.d.ts +1 -0
  176. package/dist/unified/team/team.js +2 -0
  177. package/dist/unified/types/libTypes.d.ts +378 -0
  178. package/dist/unified/types/libTypes.js +6 -0
  179. package/dist/unified/types/types.d.ts +212 -0
  180. package/dist/unified/types/types.js +43 -0
  181. package/dist/unified/utils/utils.d.ts +40 -0
  182. package/dist/unified/utils/utils.js +219 -0
  183. package/package.json +29 -7
@@ -0,0 +1,453 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AtFileProcessorModifier = void 0;
40
+ const base_1 = require("../base");
41
+ const fs = __importStar(require("node:fs/promises"));
42
+ const path = __importStar(require("node:path"));
43
+ const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
44
+ const DEFAULT_FILE_FILTERING_OPTIONS = {
45
+ respectGitIgnore: true,
46
+ respectGeminiIgnore: true,
47
+ };
48
+ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
49
+ constructor(options = {}) {
50
+ super();
51
+ this.options = {
52
+ maxFileSize: options.maxFileSize || 1024 * 1024, // 1MB default
53
+ allowedExtensions: options.allowedExtensions || ['.ts', '.js', '.d.ts', '.json', '.md', '.txt', '.yml', '.yaml', '.xml', '.html', '.css', '.py', '.java', '.cpp', '.c', '.h'],
54
+ enableRecursiveSearch: options.enableRecursiveSearch !== false
55
+ };
56
+ }
57
+ async modify(originalRequest, createdMessage) {
58
+ try {
59
+ const mentionedFiles = originalRequest.mentionedFiles || [];
60
+ const mentionedFolders = originalRequest.mentionedFolders || [];
61
+ if (mentionedFiles.length === 0 && mentionedFolders.length === 0) {
62
+ return createdMessage;
63
+ }
64
+ // Process mentioned files and folders
65
+ const result = await this.processMentionedPaths(mentionedFiles, mentionedFolders);
66
+ if (!result.success) {
67
+ return createdMessage;
68
+ }
69
+ // Update the user message with processed content
70
+ const messages = [...createdMessage.message.messages];
71
+ const lastUserMessageIndex = this.findLastUserMessage(messages);
72
+ if (lastUserMessageIndex !== -1 && result.processedContent) {
73
+ const lastUserMessage = messages[lastUserMessageIndex];
74
+ // Convert string content to array format if needed
75
+ let currentContent;
76
+ if (Array.isArray(lastUserMessage.content)) {
77
+ currentContent = lastUserMessage.content;
78
+ }
79
+ else {
80
+ // Convert string content to array format
81
+ currentContent = [{ type: 'text', text: lastUserMessage.content }];
82
+ }
83
+ // Ensure processedContent is in array format
84
+ const newContent = Array.isArray(result.processedContent)
85
+ ? result.processedContent
86
+ : [{ type: 'text', text: result.processedContent }];
87
+ // Merge existing content with processed content
88
+ messages[lastUserMessageIndex] = {
89
+ ...lastUserMessage,
90
+ content: [...currentContent, ...newContent]
91
+ };
92
+ }
93
+ return {
94
+ message: {
95
+ ...createdMessage.message,
96
+ messages
97
+ },
98
+ metadata: {
99
+ ...createdMessage.metadata,
100
+ atFileProcessed: true,
101
+ processedFiles: mentionedFiles,
102
+ processedFolders: mentionedFolders,
103
+ filesRead: result.filesRead || []
104
+ }
105
+ };
106
+ }
107
+ catch (error) {
108
+ console.error('Error in AtFileProcessorModifier:', error);
109
+ return createdMessage;
110
+ }
111
+ }
112
+ async processMentionedPaths(mentionedFiles, mentionedFolders) {
113
+ const filesRead = [];
114
+ const contextParts = [];
115
+ // Get workspace directories
116
+ let workspaceDirectories = [];
117
+ try {
118
+ const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
119
+ workspaceDirectories = projectPath ? [projectPath] : [await this.getProjectPath()];
120
+ }
121
+ catch (error) {
122
+ workspaceDirectories = [await this.getProjectPath()];
123
+ }
124
+ // Process mentioned files using readManyFiles
125
+ if (mentionedFiles.length > 0) {
126
+ try {
127
+ const resolvedPaths = await Promise.all(mentionedFiles.map(async (filePath) => {
128
+ try {
129
+ await this.resolvePath(filePath, workspaceDirectories);
130
+ return filePath; // Keep original path for readManyFiles
131
+ }
132
+ catch (error) {
133
+ console.warn(`Could not resolve path: ${filePath}`);
134
+ return filePath; // Still try to read it
135
+ }
136
+ }));
137
+ const fileContents = await this.readManyFiles(resolvedPaths);
138
+ filesRead.push(...mentionedFiles);
139
+ if (fileContents.length > 0) {
140
+ contextParts.push(`\n--- Content from referenced files ---`);
141
+ for (const { path: filePath, content } of fileContents) {
142
+ contextParts.push(`\nContent from @${filePath}:\n`);
143
+ contextParts.push(content);
144
+ }
145
+ }
146
+ }
147
+ catch (error) {
148
+ console.error('Error reading mentioned files:', error);
149
+ // Fallback to individual file reading
150
+ contextParts.push(`\n--- Content from referenced files ---`);
151
+ for (const filePath of mentionedFiles) {
152
+ try {
153
+ const resolvedPath = await this.resolvePath(filePath, workspaceDirectories);
154
+ const content = await this.readFileContent(resolvedPath);
155
+ filesRead.push(filePath);
156
+ contextParts.push(`\nContent from @${filePath}:\n`);
157
+ contextParts.push(content);
158
+ }
159
+ catch (error) {
160
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
161
+ contextParts.push(`\nContent from @${filePath}:\n`);
162
+ contextParts.push(`[Error loading ${filePath}: ${errorMessage}]`);
163
+ }
164
+ }
165
+ }
166
+ }
167
+ // Process mentioned folders
168
+ if (mentionedFolders.length > 0) {
169
+ contextParts.push(`\n--- Folder Structures ---`);
170
+ for (const folderPath of mentionedFolders) {
171
+ try {
172
+ const resolvedPath = await this.resolvePath(folderPath, workspaceDirectories);
173
+ const structure = await this.getFolderStructure(resolvedPath);
174
+ filesRead.push(folderPath);
175
+ contextParts.push(`\nStructure of @${folderPath}:\n`);
176
+ contextParts.push(structure);
177
+ // Also read files within the folder
178
+ const filesInFolder = await this.getFilesInFolder(resolvedPath);
179
+ console.log(`Found ${filesInFolder.length} files in ${folderPath}:`, filesInFolder.map(f => path.basename(f)));
180
+ if (filesInFolder.length > 0) {
181
+ contextParts.push(`\n--- Files in ${folderPath} ---`);
182
+ for (const filePath of filesInFolder) {
183
+ try {
184
+ console.log(`Attempting to read file: ${filePath}`);
185
+ const content = await this.readFileContent(filePath);
186
+ const relativePath = path.relative(resolvedPath, filePath);
187
+ const displayPath = `${folderPath}/${relativePath}`;
188
+ contextParts.push(`\nContent from @${displayPath}:\n`);
189
+ contextParts.push(content);
190
+ console.log(`Successfully read file: ${displayPath} (${content.length} chars)`);
191
+ }
192
+ catch (error) {
193
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
194
+ const relativePath = path.relative(resolvedPath, filePath);
195
+ const displayPath = `${folderPath}/${relativePath}`;
196
+ console.error(`Error reading file ${displayPath}:`, errorMessage);
197
+ contextParts.push(`\nContent from @${displayPath}:\n`);
198
+ contextParts.push(`[Error reading file: ${errorMessage}]`);
199
+ }
200
+ }
201
+ }
202
+ else {
203
+ console.log(`No files found in ${folderPath} (resolved to ${resolvedPath})`);
204
+ }
205
+ }
206
+ catch (error) {
207
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
208
+ contextParts.push(`\nStructure of @${folderPath}:\n`);
209
+ contextParts.push(`[Error reading folder ${folderPath}: ${errorMessage}]`);
210
+ }
211
+ }
212
+ }
213
+ return {
214
+ success: true,
215
+ processedContent: this.buildContentParts(contextParts),
216
+ filesRead
217
+ };
218
+ }
219
+ buildContentParts(contextParts) {
220
+ const contentParts = [];
221
+ for (const part of contextParts) {
222
+ contentParts.push({
223
+ type: 'text',
224
+ text: part
225
+ });
226
+ }
227
+ return contentParts;
228
+ }
229
+ async resolvePath(pathName, workspaceDirectories) {
230
+ // Try to resolve the path in workspace directories
231
+ for (const dir of workspaceDirectories) {
232
+ try {
233
+ const absolutePath = path.resolve(dir, pathName);
234
+ await fs.stat(absolutePath); // Check if path exists
235
+ return absolutePath;
236
+ }
237
+ catch (error) {
238
+ if (this.isNodeError(error) && error.code === 'ENOENT') {
239
+ if (this.options.enableRecursiveSearch) {
240
+ // Try glob search
241
+ const globResult = await this.globSearch(pathName, dir);
242
+ if (globResult) {
243
+ return path.resolve(dir, globResult);
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ // Fallback to original path
250
+ const projectPath = await this.getProjectPath();
251
+ return path.isAbsolute(pathName) ? pathName : path.resolve(projectPath, pathName);
252
+ }
253
+ async globSearch(pathName, dir) {
254
+ // Simple glob search implementation
255
+ try {
256
+ const pattern = `**/*${pathName}*`;
257
+ const matches = await this.findFiles(dir, pattern);
258
+ if (matches.length > 0) {
259
+ return path.relative(dir, matches[0]);
260
+ }
261
+ }
262
+ catch (error) {
263
+ console.error('Glob search error:', error);
264
+ }
265
+ return null;
266
+ }
267
+ async findFiles(dir, pattern) {
268
+ // Simplified file finding - in real implementation would use proper glob
269
+ const matches = [];
270
+ const searchTerm = pattern.replace(/\*\*/g, '').replace(/\*/g, '');
271
+ try {
272
+ const entries = await fs.readdir(dir, { withFileTypes: true });
273
+ for (const entry of entries) {
274
+ if (entry.name.includes(searchTerm)) {
275
+ matches.push(path.join(dir, entry.name));
276
+ }
277
+ if (entry.isDirectory() && !entry.name.startsWith('.')) {
278
+ const subMatches = await this.findFiles(path.join(dir, entry.name), pattern);
279
+ matches.push(...subMatches);
280
+ }
281
+ }
282
+ }
283
+ catch (error) {
284
+ // Ignore errors in subdirectories
285
+ }
286
+ return matches.slice(0, 10); // Limit results
287
+ }
288
+ async readManyFiles(pathSpecs) {
289
+ const results = [];
290
+ // Try to use read_many_files tool if available (like gemini-cli)
291
+ try {
292
+ // In a real implementation, this would use the actual tool registry
293
+ // For now, we'll simulate the tool behavior
294
+ const toolArgs = {
295
+ paths: pathSpecs,
296
+ useDefaultExcludes: true,
297
+ file_filtering_options: {
298
+ respect_git_ignore: DEFAULT_FILE_FILTERING_OPTIONS.respectGitIgnore,
299
+ respect_gemini_ignore: DEFAULT_FILE_FILTERING_OPTIONS.respectGeminiIgnore,
300
+ }
301
+ };
302
+ // Simulate read_many_files tool execution
303
+ for (const pathSpec of pathSpecs) {
304
+ try {
305
+ if (pathSpec.includes('**') || pathSpec.includes('*')) {
306
+ // Handle directory patterns
307
+ const basePath = pathSpec.replace('/**', '').replace('**', '');
308
+ const files = await this.findFiles(basePath, '**/*');
309
+ for (const filePath of files.slice(0, 20)) { // Limit files
310
+ try {
311
+ const content = await this.readFileContent(filePath);
312
+ const projectPath = await this.getProjectPath();
313
+ results.push({ path: path.relative(projectPath, filePath), content });
314
+ }
315
+ catch (error) {
316
+ results.push({ path: filePath, content: `[Error reading file: ${error}]` });
317
+ }
318
+ }
319
+ }
320
+ else {
321
+ // Handle single file
322
+ const projectPath = await this.getProjectPath();
323
+ const resolvedPath = path.isAbsolute(pathSpec) ? pathSpec : path.resolve(projectPath, pathSpec);
324
+ const content = await this.readFileContent(resolvedPath);
325
+ results.push({ path: pathSpec, content });
326
+ }
327
+ }
328
+ catch (error) {
329
+ results.push({ path: pathSpec, content: `[Error reading: ${error}]` });
330
+ }
331
+ }
332
+ }
333
+ catch (error) {
334
+ console.error('Error in readManyFiles:', error);
335
+ // Fallback to individual file reading
336
+ for (const pathSpec of pathSpecs) {
337
+ try {
338
+ const projectPath = await this.getProjectPath();
339
+ const resolvedPath = path.isAbsolute(pathSpec) ? pathSpec : path.resolve(projectPath, pathSpec);
340
+ const content = await this.readFileContent(resolvedPath);
341
+ results.push({ path: pathSpec, content });
342
+ }
343
+ catch (error) {
344
+ results.push({ path: pathSpec, content: `[Error reading: ${error}]` });
345
+ }
346
+ }
347
+ }
348
+ return results;
349
+ }
350
+ async readFileContent(filePath) {
351
+ // Check file size
352
+ const stats = await fs.stat(filePath);
353
+ if (stats.size > this.options.maxFileSize) {
354
+ throw new Error(`File too large: ${stats.size} bytes`);
355
+ }
356
+ // Check file extension
357
+ if (this.options.allowedExtensions.length > 0) {
358
+ const ext = path.extname(filePath).toLowerCase();
359
+ if (!this.options.allowedExtensions.includes(ext)) {
360
+ throw new Error(`File type not allowed: ${ext}`);
361
+ }
362
+ }
363
+ const content = await fs.readFile(filePath, 'utf-8');
364
+ return content;
365
+ }
366
+ async getFilesInFolder(folderPath) {
367
+ try {
368
+ const entries = await fs.readdir(folderPath, { withFileTypes: true });
369
+ const files = [];
370
+ for (const entry of entries) {
371
+ if (entry.isFile() && !entry.name.startsWith('.')) {
372
+ // Check file extension if allowed extensions are specified
373
+ if (this.options.allowedExtensions.length > 0) {
374
+ const ext = path.extname(entry.name).toLowerCase();
375
+ console.log(`Checking file ${entry.name} with extension ${ext}. Allowed:`, this.options.allowedExtensions);
376
+ if (this.options.allowedExtensions.includes(ext)) {
377
+ files.push(path.join(folderPath, entry.name));
378
+ }
379
+ else {
380
+ console.log(`File ${entry.name} extension ${ext} not in allowed list`);
381
+ }
382
+ }
383
+ else {
384
+ files.push(path.join(folderPath, entry.name));
385
+ }
386
+ }
387
+ }
388
+ // Limit number of files to avoid overwhelming output
389
+ return files.slice(0, 10);
390
+ }
391
+ catch (error) {
392
+ console.error('Error reading files in folder:', error);
393
+ return [];
394
+ }
395
+ }
396
+ async getFolderStructure(folderPath) {
397
+ // Check if folder exists and is readable
398
+ const stats = await fs.stat(folderPath);
399
+ if (!stats.isDirectory()) {
400
+ throw new Error(`${folderPath} is not a directory`);
401
+ }
402
+ // Read directory structure
403
+ const entries = await fs.readdir(folderPath, { withFileTypes: true });
404
+ const lines = [];
405
+ // Sort entries: directories first, then files
406
+ const sortedEntries = entries.sort((a, b) => {
407
+ if (a.isDirectory() && !b.isDirectory())
408
+ return -1;
409
+ if (!a.isDirectory() && b.isDirectory())
410
+ return 1;
411
+ return a.name.localeCompare(b.name);
412
+ });
413
+ for (const entry of sortedEntries.slice(0, 50)) { // Limit to 50 entries
414
+ if (entry.name.startsWith('.'))
415
+ continue; // Skip hidden files
416
+ if (entry.isDirectory()) {
417
+ lines.push(`${path.basename(folderPath)}/${entry.name}/`);
418
+ }
419
+ else {
420
+ const filePath = path.join(folderPath, entry.name);
421
+ const fileStats = await fs.stat(filePath);
422
+ const size = fileStats.size < 1024 ? `${fileStats.size}B` : `${Math.round(fileStats.size / 1024)}KB`;
423
+ lines.push(`${path.basename(folderPath)}/${entry.name} (${size})`);
424
+ }
425
+ }
426
+ if (entries.length > 50) {
427
+ lines.push(`... and ${entries.length - 50} more items`);
428
+ }
429
+ return lines.join('\n');
430
+ }
431
+ findLastUserMessage(messages) {
432
+ for (let i = messages.length - 1; i >= 0; i--) {
433
+ if (messages[i].role === 'user') {
434
+ return i;
435
+ }
436
+ }
437
+ return -1;
438
+ }
439
+ async getProjectPath() {
440
+ try {
441
+ const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
442
+ return projectPath || process.cwd();
443
+ }
444
+ catch (error) {
445
+ console.warn('Failed to get project path from codebolt.project.getProjectPath(), falling back to process.cwd()');
446
+ return process.cwd();
447
+ }
448
+ }
449
+ isNodeError(error) {
450
+ return error instanceof Error && 'code' in error;
451
+ }
452
+ }
453
+ exports.AtFileProcessorModifier = AtFileProcessorModifier;
@@ -0,0 +1,15 @@
1
+ import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
2
+ export interface BaseContextMessageModifierOptions {
3
+ prependmessage?: string;
4
+ datetime?: boolean;
5
+ osInfo?: boolean;
6
+ workingdir?: boolean;
7
+ }
8
+ export declare class BaseContextMessageModifier extends BaseMessageModifier {
9
+ private readonly prependMessage;
10
+ private readonly includeDateTime;
11
+ private readonly includeOsInfo;
12
+ private readonly includeWorkingDir;
13
+ constructor(options?: BaseContextMessageModifierOptions);
14
+ modify(input: MessageModifierInput): Promise<ProcessedMessage>;
15
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseContextMessageModifier = void 0;
7
+ const processor_1 = require("../../processor");
8
+ const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
9
+ const os_1 = __importDefault(require("os"));
10
+ class BaseContextMessageModifier extends processor_1.BaseMessageModifier {
11
+ constructor(options = {}) {
12
+ super({ context: options });
13
+ this.prependMessage = options.prependmessage || '';
14
+ this.includeDateTime = options.datetime || false;
15
+ this.includeOsInfo = options.osInfo || false;
16
+ this.includeWorkingDir = options.workingdir || false;
17
+ }
18
+ async modify(input) {
19
+ try {
20
+ const { originalRequest, createdMessage, context } = input;
21
+ const contextParts = [];
22
+ // Add prepend message if provided
23
+ if (this.prependMessage) {
24
+ contextParts.push(this.prependMessage);
25
+ }
26
+ // Add date/time if requested
27
+ if (this.includeDateTime) {
28
+ const now = new Date();
29
+ contextParts.push(`Current Date/Time: ${now.toISOString()}`);
30
+ }
31
+ // Add OS info if requested
32
+ if (this.includeOsInfo) {
33
+ const osInfo = {
34
+ platform: os_1.default.platform(),
35
+ arch: os_1.default.arch(),
36
+ version: os_1.default.version(),
37
+ hostname: os_1.default.hostname()
38
+ };
39
+ contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
40
+ }
41
+ // Add working directory if requested
42
+ if (this.includeWorkingDir) {
43
+ try {
44
+ const projectPath = await codeboltjs_1.default.project.getProjectPath();
45
+ contextParts.push(`Working Directory: ${projectPath}`);
46
+ }
47
+ catch (error) {
48
+ contextParts.push(`Working Directory: ${process.cwd()}`);
49
+ }
50
+ }
51
+ // Create context message if we have any context parts
52
+ if (contextParts.length > 0) {
53
+ const contextMessage = {
54
+ role: 'system',
55
+ content: contextParts.join('\n\n'),
56
+ name: 'base-context'
57
+ };
58
+ return {
59
+ messages: [contextMessage, ...createdMessage.messages],
60
+ metadata: {
61
+ ...createdMessage.metadata,
62
+ baseContextAdded: true,
63
+ contextParts: contextParts.length
64
+ }
65
+ };
66
+ }
67
+ return createdMessage;
68
+ }
69
+ catch (error) {
70
+ console.error('Error in BaseContextMessageModifier:', error);
71
+ throw error;
72
+ }
73
+ }
74
+ }
75
+ exports.BaseContextMessageModifier = BaseContextMessageModifier;
@@ -0,0 +1,11 @@
1
+ import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
2
+ export interface BaseSystemInstructionMessageModifierOptions {
3
+ systemInstruction?: string;
4
+ position?: 'start' | 'end';
5
+ }
6
+ export declare class BaseSystemInstructionMessageModifier extends BaseMessageModifier {
7
+ private readonly systemInstruction;
8
+ private readonly position;
9
+ constructor(options?: BaseSystemInstructionMessageModifierOptions);
10
+ modify(input: MessageModifierInput): Promise<ProcessedMessage>;
11
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSystemInstructionMessageModifier = void 0;
4
+ const processor_1 = require("../../processor");
5
+ class BaseSystemInstructionMessageModifier extends processor_1.BaseMessageModifier {
6
+ constructor(options = {}) {
7
+ super({ context: options });
8
+ this.systemInstruction = options.systemInstruction || 'You are a helpful assistant.';
9
+ this.position = options.position || 'start';
10
+ }
11
+ async modify(input) {
12
+ try {
13
+ const { originalRequest, createdMessage, context } = input;
14
+ // Create system instruction message
15
+ const systemMessage = {
16
+ role: 'system',
17
+ content: this.systemInstruction,
18
+ name: 'system-instruction'
19
+ };
20
+ let messages;
21
+ if (this.position === 'start') {
22
+ // Add system instruction at the beginning
23
+ messages = [systemMessage, ...createdMessage.messages];
24
+ }
25
+ else {
26
+ // Add system instruction at the end (before user message)
27
+ const userMessages = createdMessage.messages.filter(m => m.role === 'user');
28
+ const otherMessages = createdMessage.messages.filter(m => m.role !== 'user');
29
+ messages = [...otherMessages, systemMessage, ...userMessages];
30
+ }
31
+ return {
32
+ messages,
33
+ metadata: {
34
+ ...createdMessage.metadata,
35
+ systemInstructionAdded: true,
36
+ systemInstructionPosition: this.position
37
+ }
38
+ };
39
+ }
40
+ catch (error) {
41
+ console.error('Error in BaseSystemInstructionMessageModifier:', error);
42
+ throw error;
43
+ }
44
+ }
45
+ }
46
+ exports.BaseSystemInstructionMessageModifier = BaseSystemInstructionMessageModifier;
@@ -0,0 +1,18 @@
1
+ import { ProcessedMessage } from "@codebolt/types/agent";
2
+ import { BaseMessageModifier } from "../base";
3
+ import { FlatUserMessage } from "@codebolt/types/sdk";
4
+ export interface ChatHistoryMessageModifierOptions {
5
+ enableChatHistory?: boolean;
6
+ maxHistoryMessages?: number;
7
+ includeSystemMessages?: boolean;
8
+ [key: string]: unknown;
9
+ }
10
+ export declare class ChatHistoryMessageModifier extends BaseMessageModifier {
11
+ private readonly enableChatHistory;
12
+ private readonly maxHistoryMessages;
13
+ private readonly includeSystemMessages;
14
+ constructor(options?: ChatHistoryMessageModifierOptions);
15
+ modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
16
+ private getChatHistory;
17
+ setMaxHistoryMessages(max: number): void;
18
+ }