@codebolt/agent 5.0.1 → 5.0.6

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 (160) hide show
  1. package/dist/agent.d.ts +86 -0
  2. package/dist/agent.js +324 -0
  3. package/dist/builderpattern/agent.js +2 -2
  4. package/dist/builderpattern/followupquestionbuilder.js +1 -1
  5. package/dist/builderpattern/llmoutputhandler.js +7 -7
  6. package/dist/builderpattern/usermessage.d.ts +1 -6
  7. package/dist/composablepattern/document.js +35 -2
  8. package/dist/followupquestionbuilder.d.ts +75 -0
  9. package/dist/followupquestionbuilder.js +197 -0
  10. package/dist/index.d.ts +14 -0
  11. package/dist/index.js +23 -0
  12. package/dist/llmoutputhandler.d.ts +102 -0
  13. package/dist/llmoutputhandler.js +452 -0
  14. package/dist/processor/types/interfaces.d.ts +21 -44
  15. package/dist/processor-pieces/index.d.ts +3 -0
  16. package/dist/processor-pieces/index.js +3 -0
  17. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
  18. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
  19. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
  20. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
  21. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
  22. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
  23. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
  24. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
  25. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
  26. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
  27. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
  28. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
  29. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
  30. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
  31. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
  32. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
  33. package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
  34. package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
  35. package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
  36. package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
  37. package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
  38. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
  39. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
  40. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
  41. package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
  42. package/dist/promptbuilder.d.ts +382 -0
  43. package/dist/promptbuilder.js +805 -0
  44. package/dist/systemprompt.d.ts +20 -0
  45. package/dist/systemprompt.js +48 -0
  46. package/dist/taskInstruction.d.ts +37 -0
  47. package/dist/taskInstruction.js +57 -0
  48. package/dist/unified/agent/agent.js +2 -2
  49. package/dist/unified/agent/codeboltAgent.d.ts +122 -0
  50. package/dist/unified/agent/codeboltAgent.js +210 -0
  51. package/dist/unified/base/initialPromptGenerator.js +18 -4
  52. package/dist/unified/base/responseExecutor.d.ts +3 -2
  53. package/dist/unified/base/responseExecutor.js +100 -56
  54. package/dist/unified/index.d.ts +4 -0
  55. package/dist/unified/index.js +12 -1
  56. package/dist/usermessage.d.ts +70 -0
  57. package/dist/usermessage.js +123 -0
  58. package/package.json +5 -5
  59. package/dist/local-tools/fileTools.d.ts +0 -26
  60. package/dist/local-tools/fileTools.js +0 -162
  61. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
  62. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
  63. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
  64. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
  65. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
  66. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
  67. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
  68. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
  69. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
  70. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
  71. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
  72. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
  73. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
  74. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
  75. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
  76. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
  77. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
  78. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
  79. package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
  80. package/dist/processor-pieces/additionalModifiers/index.js +0 -28
  81. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
  82. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
  83. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
  84. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
  85. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
  86. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
  87. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
  88. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
  89. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
  90. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
  91. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
  92. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
  93. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
  94. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
  95. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
  96. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
  97. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
  98. package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
  99. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
  100. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
  101. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
  102. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
  103. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
  104. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
  105. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
  106. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
  107. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
  108. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
  109. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
  110. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
  111. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
  112. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
  113. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
  114. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
  115. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
  116. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
  117. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
  118. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
  119. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
  120. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
  121. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
  122. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
  123. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
  124. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
  125. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
  126. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
  127. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
  128. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
  129. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
  130. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
  131. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
  132. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
  133. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
  134. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
  135. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
  136. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
  137. package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
  138. package/dist/processor-pieces/preToolCall/index.js +0 -18
  139. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
  140. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
  141. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
  142. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
  143. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
  144. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
  145. package/dist/unified/agent/tool.d.ts +0 -99
  146. package/dist/unified/agent/tool.js +0 -440
  147. package/dist/unified/examples/agentExample.d.ts +0 -46
  148. package/dist/unified/examples/agentExample.js +0 -464
  149. package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
  150. package/dist/unified/examples/documentationPatternExample.js +0 -385
  151. package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
  152. package/dist/unified/examples/followUpProcessorsExample.js +0 -311
  153. package/dist/unified/examples/orchestratorExample.d.ts +0 -16
  154. package/dist/unified/examples/orchestratorExample.js +0 -415
  155. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
  156. package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
  157. package/dist/unified/examples/workflowExample.d.ts +0 -12
  158. package/dist/unified/examples/workflowExample.js +0 -497
  159. package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
  160. package/dist/unified/orchestrator/orchestrator.js +0 -519
@@ -37,49 +37,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.WorkingDirectoryMessageModifier = void 0;
40
- const base_1 = require("../base");
40
+ const processor_1 = require("../../processor");
41
41
  const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
42
42
  const path = __importStar(require("path"));
43
- const fs = __importStar(require("fs/promises"));
44
- class WorkingDirectoryMessageModifier extends base_1.BaseMessageModifier {
43
+ class WorkingDirectoryMessageModifier extends processor_1.BaseMessageModifier {
45
44
  constructor(options = {}) {
46
45
  super({ context: options });
47
- this.defaultIgnoredFolders = new Set(['node_modules', '.git', 'dist', '.codebolt', '.codeboltAgents']);
48
- this.truncationIndicator = '...';
49
46
  this.showFolderStructureSummary = options.showFolderStructureSummary || false;
50
47
  this.listFiles = options.listFiles || false;
51
48
  this.listFilesDepth = options.listFilesDepth || 2;
52
- this.listFilesLimit = options.listFilesLimit || 100;
49
+ this.listFilesLimit = options.listFilesLimit || 200;
53
50
  this.listFilesIgnoreFromGitignore = options.listFilesIgnoreFromGitignore || true;
54
- this.listFilesIgnore = options.listFilesIgnore || ['node_modules', '.git', 'dist', '.codebolt', '.codeboltAgents'];
55
- this.maxItems = options.maxItems || 200;
56
- this.showFullDirectoryContext = options.showFullDirectoryContext || true;
51
+ this.listFilesIgnore = options.listFilesIgnore || ['node_modules', '.git', 'dist', 'build'];
57
52
  }
58
- async modify(originalRequest, createdMessage) {
53
+ async modify(input) {
59
54
  try {
55
+ const { originalRequest, createdMessage, context } = input;
60
56
  const contextParts = [];
61
57
  // Get project information
62
58
  try {
63
- const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
64
- if (!projectPath) {
65
- throw new Error('Project path not available');
59
+ const projectPathResponse = await codeboltjs_1.default.project.getProjectPath();
60
+ const projectPath = typeof projectPathResponse === 'string'
61
+ ? projectPathResponse
62
+ : (projectPathResponse === null || projectPathResponse === void 0 ? void 0 : projectPathResponse.path) || String(projectPathResponse) || '';
63
+ contextParts.push(`Project Directory: ${projectPath}`);
64
+ if (this.showFolderStructureSummary) {
65
+ const summary = await this.generateFolderStructureSummary(projectPath);
66
+ contextParts.push(`Folder Structure Summary:\n${summary}`);
66
67
  }
67
- // Generate comprehensive directory context similar to gemini-cli
68
- if (this.showFullDirectoryContext) {
69
- const directoryContext = await this.getDirectoryContextString(projectPath);
70
- contextParts.push(directoryContext);
71
- }
72
- else {
73
- // Fallback to original behavior
74
- contextParts.push(`Project Directory: ${projectPath}`);
75
- if (this.showFolderStructureSummary) {
76
- const summary = await this.generateFolderStructureSummary(projectPath);
77
- contextParts.push(`Folder Structure Summary:\n${summary}`);
78
- }
79
- if (this.listFiles) {
80
- const filesList = await this.generateFilesList(projectPath);
81
- contextParts.push(`Files List:\n${filesList}`);
82
- }
68
+ if (this.listFiles) {
69
+ const filesList = await this.generateFilesList(projectPath);
70
+ contextParts.push(`Files List:\n${filesList}`);
83
71
  }
84
72
  }
85
73
  catch (error) {
@@ -88,30 +76,13 @@ class WorkingDirectoryMessageModifier extends base_1.BaseMessageModifier {
88
76
  }
89
77
  // Create context message if we have any context parts
90
78
  if (contextParts.length > 0) {
91
- const contextContent = contextParts.join('\n\n');
92
- const messages = [...createdMessage.message.messages];
93
- // Find existing system message
94
- const systemMessageIndex = messages.findIndex(msg => msg.role === 'system');
95
- if (systemMessageIndex !== -1) {
96
- // Update existing system message
97
- messages[systemMessageIndex] = {
98
- ...messages[systemMessageIndex],
99
- content: `${messages[systemMessageIndex].content}\n\n${contextContent}`
100
- };
101
- }
102
- else {
103
- // Add new system message at the top
104
- messages.unshift({
105
- role: 'system',
106
- content: contextContent
107
- });
108
- }
79
+ const contextMessage = {
80
+ role: 'system',
81
+ content: contextParts.join('\n\n'),
82
+ name: 'working-directory-context'
83
+ };
109
84
  return {
110
- ...createdMessage,
111
- message: {
112
- ...createdMessage.message,
113
- messages
114
- },
85
+ messages: [contextMessage, ...createdMessage.messages],
115
86
  metadata: {
116
87
  ...createdMessage.metadata,
117
88
  workingDirectoryContextAdded: true,
@@ -128,14 +99,44 @@ class WorkingDirectoryMessageModifier extends base_1.BaseMessageModifier {
128
99
  }
129
100
  async generateFolderStructureSummary(projectPath) {
130
101
  try {
102
+ // Use CodeBolt's directory listing with recursive option
103
+ const response = await codeboltjs_1.default.fs.listDirectory({
104
+ path: projectPath,
105
+ show_hidden: false,
106
+ detailed: false,
107
+ limit: 200,
108
+ notifyUser: false
109
+ });
131
110
  const directories = new Set();
132
- await this.collectDirectories(projectPath, directories, 0, 3); // Max depth of 3
133
- const sortedDirs = Array.from(directories)
134
- .filter(dir => dir !== projectPath && !this.shouldIgnore(dir))
135
- .sort()
136
- .slice(0, 20);
111
+ // Extract directories from the response
112
+ if (response && response.success) {
113
+ let entries;
114
+ if (typeof response.result === 'string') {
115
+ // If result is a string, we'll need to parse it or work with what we have
116
+ return response.result.split('\n').slice(0, 20).join('\n');
117
+ }
118
+ else if (response.result && response.result.entries) {
119
+ entries = response.result.entries;
120
+ }
121
+ else if (response.entries) {
122
+ entries = response.entries;
123
+ }
124
+ if (entries) {
125
+ entries.forEach((entry) => {
126
+ if (entry.type === 'directory' && !this.shouldIgnore(entry.path || entry.name)) {
127
+ directories.add(entry.path || entry.name);
128
+ }
129
+ // Also get parent directories of files
130
+ const dir = path.dirname(entry.path || entry.name);
131
+ if (dir !== '.' && !this.shouldIgnore(dir)) {
132
+ directories.add(dir);
133
+ }
134
+ });
135
+ }
136
+ }
137
+ const sortedDirs = Array.from(directories).sort();
137
138
  return sortedDirs.length > 0
138
- ? sortedDirs.join('\n')
139
+ ? sortedDirs.slice(0, 20).join('\n')
139
140
  : 'No accessible directories found';
140
141
  }
141
142
  catch (error) {
@@ -144,249 +145,50 @@ class WorkingDirectoryMessageModifier extends base_1.BaseMessageModifier {
144
145
  }
145
146
  async generateFilesList(projectPath) {
146
147
  try {
148
+ // Use CodeBolt's directory listing to get files
149
+ const response = await codeboltjs_1.default.fs.listDirectory({
150
+ path: projectPath,
151
+ show_hidden: false,
152
+ detailed: false,
153
+ limit: this.listFilesLimit,
154
+ notifyUser: false
155
+ });
147
156
  const files = [];
148
- await this.collectFiles(projectPath, files, 0, 2); // Max depth of 2
149
- const filteredFiles = files
150
- .filter(filePath => !this.shouldIgnore(filePath))
151
- .slice(0, this.listFilesLimit)
152
- .map(filePath => path.basename(filePath));
153
- return filteredFiles.length > 0
154
- ? filteredFiles.join('\n')
155
- : 'No accessible files found';
156
- }
157
- catch (error) {
158
- return 'Unable to generate files list';
159
- }
160
- }
161
- async collectDirectories(dirPath, directories, currentDepth, maxDepth) {
162
- if (currentDepth >= maxDepth)
163
- return;
164
- try {
165
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
166
- for (const entry of entries) {
167
- if (entry.isDirectory()) {
168
- const fullPath = path.join(dirPath, entry.name);
169
- if (!this.shouldIgnore(fullPath)) {
170
- directories.add(fullPath);
171
- await this.collectDirectories(fullPath, directories, currentDepth + 1, maxDepth);
172
- }
157
+ // Extract files from the response
158
+ if (response && response.success) {
159
+ let entries;
160
+ if (typeof response.result === 'string') {
161
+ // If result is a string, split and filter for files
162
+ return response.result.split('\n')
163
+ .filter((line) => !this.shouldIgnore(line))
164
+ .slice(0, this.listFilesLimit)
165
+ .join('\n');
173
166
  }
174
- }
175
- }
176
- catch (error) {
177
- // Skip directories we can't read
178
- }
179
- }
180
- async collectFiles(dirPath, files, currentDepth, maxDepth) {
181
- if (currentDepth >= maxDepth || files.length >= this.listFilesLimit)
182
- return;
183
- try {
184
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
185
- for (const entry of entries) {
186
- if (entry.isFile()) {
187
- const fullPath = path.join(dirPath, entry.name);
188
- if (!this.shouldIgnore(fullPath)) {
189
- files.push(fullPath);
190
- if (files.length >= this.listFilesLimit)
191
- break;
192
- }
167
+ else if (response.result && response.result.entries) {
168
+ entries = response.result.entries;
193
169
  }
194
- else if (entry.isDirectory() && currentDepth < maxDepth - 1) {
195
- const fullPath = path.join(dirPath, entry.name);
196
- if (!this.shouldIgnore(fullPath)) {
197
- await this.collectFiles(fullPath, files, currentDepth + 1, maxDepth);
198
- }
170
+ else if (response.entries) {
171
+ entries = response.entries;
172
+ }
173
+ if (entries) {
174
+ entries.forEach((entry) => {
175
+ if (entry.type === 'file' && !this.shouldIgnore(entry.path || entry.name)) {
176
+ files.push(entry.path || entry.name);
177
+ }
178
+ });
199
179
  }
200
180
  }
181
+ const filteredFiles = files.slice(0, this.listFilesLimit);
182
+ return filteredFiles.length > 0
183
+ ? filteredFiles.join('\n')
184
+ : 'No accessible files found';
201
185
  }
202
186
  catch (error) {
203
- // Skip directories we can't read
187
+ return 'Unable to generate files list';
204
188
  }
205
189
  }
206
190
  shouldIgnore(filePath) {
207
- const basename = path.basename(filePath);
208
- // Ignore any folder/file that starts with a dot
209
- if (basename.startsWith('.')) {
210
- return true;
211
- }
212
- return this.listFilesIgnore.some(ignore => filePath.includes(ignore) || basename === ignore);
213
- }
214
- // Comprehensive directory context methods exactly like gemini-cli
215
- async getDirectoryContextString(projectPath) {
216
- const folderStructure = await this.getFolderStructure(projectPath);
217
- const workingDirPreamble = `I'm currently working in the directory: ${projectPath}`;
218
- return `${workingDirPreamble}
219
- Here is the folder structure of the current working directories:
220
-
221
- ${folderStructure}`;
222
- }
223
- async getFolderStructure(directory) {
224
- const resolvedPath = path.resolve(directory);
225
- try {
226
- const structureRoot = await this.readFullStructure(resolvedPath);
227
- if (!structureRoot) {
228
- return `Error: Could not read directory "${resolvedPath}". Check path and permissions.`;
229
- }
230
- const structureLines = [];
231
- this.formatStructure(structureRoot, '', true, true, structureLines);
232
- const isTruncated = this.isTruncated(structureRoot);
233
- let summary = `Showing up to ${this.maxItems} items (files + folders).`;
234
- if (isTruncated) {
235
- summary += ` Folders or files indicated with ${this.truncationIndicator} contain more items not shown, were ignored, or the display limit (${this.maxItems} items) was reached.`;
236
- }
237
- return `${summary}\n\n${resolvedPath}${path.sep}\n${structureLines.join('\n')}`;
238
- }
239
- catch (error) {
240
- console.error(`Error getting folder structure for ${resolvedPath}:`, error);
241
- return `Error processing directory "${resolvedPath}": ${error instanceof Error ? error.message : String(error)}`;
242
- }
243
- }
244
- async readFullStructure(rootPath) {
245
- const rootName = path.basename(rootPath);
246
- const rootNode = {
247
- name: rootName,
248
- path: rootPath,
249
- files: [],
250
- subFolders: [],
251
- totalChildren: 0,
252
- totalFiles: 0,
253
- };
254
- const queue = [
255
- { folderInfo: rootNode, currentPath: rootPath },
256
- ];
257
- let currentItemCount = 0;
258
- const processedPaths = new Set();
259
- while (queue.length > 0) {
260
- const { folderInfo, currentPath } = queue.shift();
261
- if (processedPaths.has(currentPath)) {
262
- continue;
263
- }
264
- processedPaths.add(currentPath);
265
- if (currentItemCount >= this.maxItems) {
266
- continue;
267
- }
268
- let entries;
269
- try {
270
- const rawEntries = await fs.readdir(currentPath, { withFileTypes: true });
271
- entries = rawEntries.sort((a, b) => a.name.localeCompare(b.name));
272
- }
273
- catch (error) {
274
- if (error.code === 'EACCES' || error.code === 'ENOENT') {
275
- console.warn(`Warning: Could not read directory ${currentPath}: ${error.message}`);
276
- if (currentPath === rootPath && error.code === 'ENOENT') {
277
- return null;
278
- }
279
- continue;
280
- }
281
- throw error;
282
- }
283
- const filesInCurrentDir = [];
284
- const subFoldersInCurrentDir = [];
285
- // Process files first
286
- for (const entry of entries) {
287
- if (entry.isFile()) {
288
- if (currentItemCount >= this.maxItems) {
289
- folderInfo.hasMoreFiles = true;
290
- break;
291
- }
292
- const fileName = entry.name;
293
- const filePath = path.join(currentPath, fileName);
294
- if (!this.shouldIgnore(filePath)) {
295
- filesInCurrentDir.push(fileName);
296
- currentItemCount++;
297
- folderInfo.totalFiles++;
298
- folderInfo.totalChildren++;
299
- }
300
- }
301
- }
302
- folderInfo.files = filesInCurrentDir;
303
- // Process directories
304
- for (const entry of entries) {
305
- if (entry.isDirectory()) {
306
- if (currentItemCount >= this.maxItems) {
307
- folderInfo.hasMoreSubfolders = true;
308
- break;
309
- }
310
- const subFolderName = entry.name;
311
- const subFolderPath = path.join(currentPath, subFolderName);
312
- const isIgnored = this.defaultIgnoredFolders.has(subFolderName) ||
313
- subFolderName.startsWith('.') ||
314
- this.shouldIgnore(subFolderPath);
315
- if (isIgnored) {
316
- const ignoredSubFolder = {
317
- name: subFolderName,
318
- path: subFolderPath,
319
- files: [],
320
- subFolders: [],
321
- totalChildren: 0,
322
- totalFiles: 0,
323
- isIgnored: true,
324
- };
325
- subFoldersInCurrentDir.push(ignoredSubFolder);
326
- currentItemCount++;
327
- folderInfo.totalChildren++;
328
- continue;
329
- }
330
- const subFolderNode = {
331
- name: subFolderName,
332
- path: subFolderPath,
333
- files: [],
334
- subFolders: [],
335
- totalChildren: 0,
336
- totalFiles: 0,
337
- };
338
- subFoldersInCurrentDir.push(subFolderNode);
339
- currentItemCount++;
340
- folderInfo.totalChildren++;
341
- queue.push({ folderInfo: subFolderNode, currentPath: subFolderPath });
342
- }
343
- }
344
- folderInfo.subFolders = subFoldersInCurrentDir;
345
- }
346
- return rootNode;
347
- }
348
- formatStructure(node, currentIndent, isLastChildOfParent, isProcessingRootNode, builder) {
349
- const connector = isLastChildOfParent ? '└───' : '├───';
350
- if (!isProcessingRootNode || node.isIgnored) {
351
- builder.push(`${currentIndent}${connector}${node.name}${path.sep}${node.isIgnored ? this.truncationIndicator : ''}`);
352
- }
353
- const indentForChildren = isProcessingRootNode
354
- ? ''
355
- : currentIndent + (isLastChildOfParent ? ' ' : '│ ');
356
- // Render files
357
- const fileCount = node.files.length;
358
- for (let i = 0; i < fileCount; i++) {
359
- const isLastFileAmongSiblings = i === fileCount - 1 &&
360
- node.subFolders.length === 0 &&
361
- !node.hasMoreSubfolders;
362
- const fileConnector = isLastFileAmongSiblings ? '└───' : '├───';
363
- builder.push(`${indentForChildren}${fileConnector}${node.files[i]}`);
364
- }
365
- if (node.hasMoreFiles) {
366
- const isLastIndicatorAmongSiblings = node.subFolders.length === 0 && !node.hasMoreSubfolders;
367
- const fileConnector = isLastIndicatorAmongSiblings ? '└───' : '├───';
368
- builder.push(`${indentForChildren}${fileConnector}${this.truncationIndicator}`);
369
- }
370
- // Render subfolders
371
- const subFolderCount = node.subFolders.length;
372
- for (let i = 0; i < subFolderCount; i++) {
373
- const isLastSubfolderAmongSiblings = i === subFolderCount - 1 && !node.hasMoreSubfolders;
374
- this.formatStructure(node.subFolders[i], indentForChildren, isLastSubfolderAmongSiblings, false, builder);
375
- }
376
- if (node.hasMoreSubfolders) {
377
- builder.push(`${indentForChildren}└───${this.truncationIndicator}`);
378
- }
379
- }
380
- isTruncated(node) {
381
- if (node.hasMoreFiles || node.hasMoreSubfolders || node.isIgnored) {
382
- return true;
383
- }
384
- for (const sub of node.subFolders) {
385
- if (this.isTruncated(sub)) {
386
- return true;
387
- }
388
- }
389
- return false;
191
+ return this.listFilesIgnore.some(ignore => filePath.includes(ignore) || path.basename(filePath) === ignore);
390
192
  }
391
193
  }
392
194
  exports.WorkingDirectoryMessageModifier = WorkingDirectoryMessageModifier;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Conversation Compactor Modifier
3
+ * Post-Tool Call processor for compacting conversation history to reduce context size
4
+ */
5
+ import { BasePostToolCallProcessor } from '../base/basePostToolCallProcessor';
6
+ import { PostToolCallProcessorInput, PostToolCallProcessorOutput } from '@codebolt/types/agent';
7
+ export interface ConversationCompactorOptions {
8
+ maxMessages?: number;
9
+ preserveSystemMessages?: boolean;
10
+ preserveLastUserMessages?: number;
11
+ preserveLastToolResults?: number;
12
+ compactStrategy?: 'simple' | 'smart' | 'summarize';
13
+ }
14
+ export declare class ConversationCompactorModifier extends BasePostToolCallProcessor {
15
+ private options;
16
+ constructor(options?: ConversationCompactorOptions);
17
+ modify(input: PostToolCallProcessorInput): Promise<PostToolCallProcessorOutput>;
18
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * Conversation Compactor Modifier
4
+ * Post-Tool Call processor for compacting conversation history to reduce context size
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ConversationCompactorModifier = void 0;
8
+ const basePostToolCallProcessor_1 = require("../base/basePostToolCallProcessor");
9
+ class ConversationCompactorModifier extends basePostToolCallProcessor_1.BasePostToolCallProcessor {
10
+ constructor(options = {}) {
11
+ super();
12
+ this.options = {
13
+ maxMessages: 50,
14
+ preserveSystemMessages: true,
15
+ preserveLastUserMessages: 5,
16
+ preserveLastToolResults: 10,
17
+ compactStrategy: 'smart',
18
+ ...options
19
+ };
20
+ }
21
+ async modify(input) {
22
+ // For now, pass through the nextPrompt unchanged since we need to understand
23
+ // the ProcessedMessage structure better for compaction
24
+ // TODO: Implement conversation compaction logic once we understand the message structure
25
+ // Add metadata to track that this processor was applied
26
+ const modifiedNextPrompt = {
27
+ ...input.nextPrompt,
28
+ metadata: {
29
+ ...input.nextPrompt.metadata,
30
+ compactedBy: 'ConversationCompactorModifier',
31
+ compactedAt: new Date().toISOString(),
32
+ strategy: this.options.compactStrategy
33
+ }
34
+ };
35
+ return {
36
+ nextPrompt: modifiedNextPrompt,
37
+ shouldExit: false
38
+ };
39
+ }
40
+ }
41
+ exports.ConversationCompactorModifier = ConversationCompactorModifier;
@@ -1 +1,2 @@
1
- export {};
1
+ export { ShellProcessorModifier } from './shellProcessorModifier';
2
+ export { ConversationCompactorModifier, type ConversationCompactorOptions } from './conversationCompactorModifier';
@@ -1,2 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationCompactorModifier = exports.ShellProcessorModifier = void 0;
4
+ var shellProcessorModifier_1 = require("./shellProcessorModifier");
5
+ Object.defineProperty(exports, "ShellProcessorModifier", { enumerable: true, get: function () { return shellProcessorModifier_1.ShellProcessorModifier; } });
6
+ var conversationCompactorModifier_1 = require("./conversationCompactorModifier");
7
+ Object.defineProperty(exports, "ConversationCompactorModifier", { enumerable: true, get: function () { return conversationCompactorModifier_1.ConversationCompactorModifier; } });
@@ -1 +1 @@
1
- export {};
1
+ export { ChatCompressionModifier, type ChatCompressionOptions } from './chatCompressionModifier';
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatCompressionModifier = void 0;
4
+ var chatCompressionModifier_1 = require("./chatCompressionModifier");
5
+ Object.defineProperty(exports, "ChatCompressionModifier", { enumerable: true, get: function () { return chatCompressionModifier_1.ChatCompressionModifier; } });
@@ -1 +1,2 @@
1
- export {};
1
+ export { ToolParameterModifier, type ToolParameterModifierOptions } from './toolParameterModifier';
2
+ export { ToolValidationModifier, type ToolValidationModifierOptions } from './toolValidationModifier';
@@ -1,2 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolValidationModifier = exports.ToolParameterModifier = void 0;
4
+ var toolParameterModifier_1 = require("./toolParameterModifier");
5
+ Object.defineProperty(exports, "ToolParameterModifier", { enumerable: true, get: function () { return toolParameterModifier_1.ToolParameterModifier; } });
6
+ var toolValidationModifier_1 = require("./toolValidationModifier");
7
+ Object.defineProperty(exports, "ToolValidationModifier", { enumerable: true, get: function () { return toolValidationModifier_1.ToolValidationModifier; } });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Tool Parameter Modifier
3
+ * Pre-Tool Call processor for modifying tool parameters before execution
4
+ */
5
+ import { BasePreToolCallProcessor } from '../base/basePreToolCallProcessor';
6
+ import { PreToolCallProcessorInput, PreToolCallProcessorOutput } from '@codebolt/types/agent';
7
+ export interface ParameterTransformation {
8
+ sourcePath: string;
9
+ targetPath: string;
10
+ transformation?: (value: any) => any;
11
+ description?: string;
12
+ }
13
+ export interface ToolParameterModifierOptions {
14
+ parameterTransformations: Record<string, ParameterTransformation[]>;
15
+ toolNameMappings?: Record<string, string>;
16
+ }
17
+ export declare class ToolParameterModifier extends BasePreToolCallProcessor {
18
+ private options;
19
+ constructor(options: ToolParameterModifierOptions);
20
+ modify(input: PreToolCallProcessorInput): Promise<PreToolCallProcessorOutput>;
21
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Tool Parameter Modifier
4
+ * Pre-Tool Call processor for modifying tool parameters before execution
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ToolParameterModifier = void 0;
8
+ const basePreToolCallProcessor_1 = require("../base/basePreToolCallProcessor");
9
+ class ToolParameterModifier extends basePreToolCallProcessor_1.BasePreToolCallProcessor {
10
+ constructor(options) {
11
+ super();
12
+ this.options = options;
13
+ }
14
+ async modify(input) {
15
+ // For now, pass through unchanged since we need to understand the exact structure
16
+ // TODO: Implement parameter modification logic once we understand the message format
17
+ // Add metadata to track that this processor was applied
18
+ const modifiedNextPrompt = {
19
+ ...input.nextPrompt,
20
+ metadata: {
21
+ ...input.nextPrompt.metadata,
22
+ modifiedBy: 'ToolParameterModifier',
23
+ modifiedAt: new Date().toISOString()
24
+ }
25
+ };
26
+ return {
27
+ nextPrompt: modifiedNextPrompt,
28
+ shouldExit: false
29
+ };
30
+ }
31
+ }
32
+ exports.ToolParameterModifier = ToolParameterModifier;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tool Validation Modifier
3
+ * Pre-Tool Call processor for validating tool parameters before execution
4
+ */
5
+ import { BasePreToolCallProcessor } from '../base/basePreToolCallProcessor';
6
+ import { PreToolCallProcessorInput, PreToolCallProcessorOutput, ToolValidationRule } from '@codebolt/types/agent';
7
+ export interface ToolValidationModifierOptions {
8
+ validationRules: ToolValidationRule[];
9
+ strictMode?: boolean;
10
+ allowPartialValidation?: boolean;
11
+ }
12
+ export declare class ToolValidationModifier extends BasePreToolCallProcessor {
13
+ private options;
14
+ constructor(options: ToolValidationModifierOptions);
15
+ modify(input: PreToolCallProcessorInput): Promise<PreToolCallProcessorOutput>;
16
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * Tool Validation Modifier
4
+ * Pre-Tool Call processor for validating tool parameters before execution
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ToolValidationModifier = void 0;
8
+ const basePreToolCallProcessor_1 = require("../base/basePreToolCallProcessor");
9
+ class ToolValidationModifier extends basePreToolCallProcessor_1.BasePreToolCallProcessor {
10
+ constructor(options) {
11
+ super();
12
+ this.options = {
13
+ strictMode: false,
14
+ allowPartialValidation: true,
15
+ ...options
16
+ };
17
+ }
18
+ async modify(input) {
19
+ // For now, pass through unchanged since we need to understand the exact structure
20
+ // TODO: Implement tool validation logic once we understand the message format
21
+ // Add metadata to track that this processor was applied
22
+ const modifiedNextPrompt = {
23
+ ...input.nextPrompt,
24
+ metadata: {
25
+ ...input.nextPrompt.metadata,
26
+ validatedBy: 'ToolValidationModifier',
27
+ validatedAt: new Date().toISOString(),
28
+ validationMode: this.options.strictMode ? 'strict' : 'lenient'
29
+ }
30
+ };
31
+ return {
32
+ nextPrompt: modifiedNextPrompt,
33
+ shouldExit: false
34
+ };
35
+ }
36
+ }
37
+ exports.ToolValidationModifier = ToolValidationModifier;