@codebolt/agent 5.0.6 → 5.0.8
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.
- package/dist/processor-pieces/base/basePreToolCallProcessor.js +5 -2
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
- package/dist/types/InternalTypes.d.ts +8 -6
- package/dist/types/libFunctionTypes.d.ts +13 -19
- package/dist/types/libFunctionTypes.js +3 -0
- package/dist/types/processorTypes.d.ts +8 -8
- package/dist/types/processorTypes.js +6 -23
- package/dist/unified/agent/agent.js +1 -2
- package/dist/unified/agent/codeboltAgent.d.ts +23 -2
- package/dist/unified/agent/codeboltAgent.js +55 -12
- package/dist/unified/agent/tools.d.ts +7 -11
- package/dist/unified/agent/tools.js +12 -3
- package/dist/unified/agent/workflow.js +38 -20
- package/dist/unified/agent/workflowSteps.d.ts +1 -1
- package/dist/unified/agent/workflowSteps.js +58 -23
- package/dist/unified/base/agentStep.js +20 -1
- package/dist/unified/base/initialPromptGenerator.js +3 -1
- package/dist/unified/base/responseExecutor.d.ts +3 -0
- package/dist/unified/base/responseExecutor.js +41 -10
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +4 -1
- package/dist/unified/services/LoopDetectionService.d.ts +44 -0
- package/dist/unified/services/LoopDetectionService.js +79 -0
- package/dist/unified/utils/utils.d.ts +20 -1
- package/dist/unified/utils/utils.js +8 -4
- package/package.json +11 -6
|
@@ -27,13 +27,16 @@ class BasePreToolCallProcessor {
|
|
|
27
27
|
}
|
|
28
28
|
// Helper method to create intercepted tool result
|
|
29
29
|
createInterceptedTool(toolName, originalInput, result, reason) {
|
|
30
|
-
|
|
30
|
+
const interceptedTool = {
|
|
31
31
|
toolName,
|
|
32
32
|
originalInput,
|
|
33
33
|
result,
|
|
34
34
|
intercepted: true,
|
|
35
|
-
reason,
|
|
36
35
|
};
|
|
36
|
+
if (reason !== undefined) {
|
|
37
|
+
interceptedTool.reason = reason;
|
|
38
|
+
}
|
|
39
|
+
return interceptedTool;
|
|
37
40
|
}
|
|
38
41
|
// Helper method to validate tool call
|
|
39
42
|
validateToolCall(toolCall, validationRules) {
|
|
@@ -9,5 +9,5 @@ export interface ArgumentProcessorOptions {
|
|
|
9
9
|
export declare class ArgumentProcessorModifier extends BaseMessageModifier {
|
|
10
10
|
private readonly options;
|
|
11
11
|
constructor(options?: ArgumentProcessorOptions);
|
|
12
|
-
modify(
|
|
12
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
13
13
|
}
|
|
@@ -11,11 +11,11 @@ class ArgumentProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
11
11
|
includeCommandName: options.includeCommandName || false
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
modify(
|
|
14
|
+
modify(_originalRequest, createdMessage) {
|
|
15
15
|
var _a;
|
|
16
16
|
try {
|
|
17
17
|
// Get arguments from metadata
|
|
18
|
-
const invocation = (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a
|
|
18
|
+
const invocation = (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a['invocation'];
|
|
19
19
|
if (!(invocation === null || invocation === void 0 ? void 0 : invocation.args)) {
|
|
20
20
|
return Promise.resolve(createdMessage);
|
|
21
21
|
}
|
|
@@ -41,10 +41,6 @@ const base_1 = require("../base");
|
|
|
41
41
|
const fs = __importStar(require("node:fs/promises"));
|
|
42
42
|
const path = __importStar(require("node:path"));
|
|
43
43
|
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
44
|
-
const DEFAULT_FILE_FILTERING_OPTIONS = {
|
|
45
|
-
respectGitIgnore: true,
|
|
46
|
-
respectGeminiIgnore: true,
|
|
47
|
-
};
|
|
48
44
|
class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
49
45
|
constructor(options = {}) {
|
|
50
46
|
super();
|
|
@@ -71,24 +67,26 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
71
67
|
const lastUserMessageIndex = this.findLastUserMessage(messages);
|
|
72
68
|
if (lastUserMessageIndex !== -1 && result.processedContent) {
|
|
73
69
|
const lastUserMessage = messages[lastUserMessageIndex];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
if (lastUserMessage) {
|
|
71
|
+
// Convert string content to array format if needed
|
|
72
|
+
let currentContent;
|
|
73
|
+
if (Array.isArray(lastUserMessage.content)) {
|
|
74
|
+
currentContent = lastUserMessage.content;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Convert string content to array format
|
|
78
|
+
currentContent = [{ type: 'text', text: lastUserMessage.content }];
|
|
79
|
+
}
|
|
80
|
+
// Ensure processedContent is in array format
|
|
81
|
+
const newContent = Array.isArray(result.processedContent)
|
|
82
|
+
? result.processedContent
|
|
83
|
+
: [{ type: 'text', text: result.processedContent }];
|
|
84
|
+
// Merge existing content with processed content
|
|
85
|
+
messages[lastUserMessageIndex] = {
|
|
86
|
+
role: lastUserMessage.role,
|
|
87
|
+
content: [...currentContent, ...newContent]
|
|
88
|
+
};
|
|
82
89
|
}
|
|
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
90
|
}
|
|
93
91
|
return {
|
|
94
92
|
message: {
|
|
@@ -255,8 +253,9 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
255
253
|
try {
|
|
256
254
|
const pattern = `**/*${pathName}*`;
|
|
257
255
|
const matches = await this.findFiles(dir, pattern);
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
const firstMatch = matches[0];
|
|
257
|
+
if (firstMatch !== undefined) {
|
|
258
|
+
return path.relative(dir, firstMatch);
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
261
|
catch (error) {
|
|
@@ -289,16 +288,6 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
289
288
|
const results = [];
|
|
290
289
|
// Try to use read_many_files tool if available (like gemini-cli)
|
|
291
290
|
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
291
|
// Simulate read_many_files tool execution
|
|
303
292
|
for (const pathSpec of pathSpecs) {
|
|
304
293
|
try {
|
|
@@ -430,7 +419,8 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
430
419
|
}
|
|
431
420
|
findLastUserMessage(messages) {
|
|
432
421
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
433
|
-
|
|
422
|
+
const message = messages[i];
|
|
423
|
+
if (message && message.role === 'user') {
|
|
434
424
|
return i;
|
|
435
425
|
}
|
|
436
426
|
}
|
|
@@ -10,7 +10,7 @@ export interface ChatRecordingOptions {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class ChatRecordingModifier extends BaseMessageModifier {
|
|
12
12
|
private readonly options;
|
|
13
|
-
private recordingFile
|
|
13
|
+
private recordingFile;
|
|
14
14
|
constructor(options?: ChatRecordingOptions);
|
|
15
15
|
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
16
16
|
private initializeRecording;
|
|
@@ -110,8 +110,8 @@ class ChatRecordingModifier extends base_1.BaseMessageModifier {
|
|
|
110
110
|
for (const message of createdMessage.message.messages) {
|
|
111
111
|
const record = {
|
|
112
112
|
timestamp,
|
|
113
|
-
messageId: (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a
|
|
114
|
-
threadId: (_b = createdMessage.metadata) === null || _b === void 0 ? void 0 : _b
|
|
113
|
+
messageId: (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a['messageId'],
|
|
114
|
+
threadId: (_b = createdMessage.metadata) === null || _b === void 0 ? void 0 : _b['threadId'],
|
|
115
115
|
role: message.role,
|
|
116
116
|
content: typeof message.content === 'string' ? message.content : JSON.stringify(message.content)
|
|
117
117
|
};
|
|
@@ -8,7 +8,7 @@ export interface CoreSystemPromptOptions {
|
|
|
8
8
|
export declare class CoreSystemPromptModifier extends BaseMessageModifier {
|
|
9
9
|
private readonly options;
|
|
10
10
|
constructor(options?: CoreSystemPromptOptions);
|
|
11
|
-
modify(
|
|
11
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
12
12
|
private getCoreSystemPrompt;
|
|
13
13
|
private getDefaultSystemPrompt;
|
|
14
14
|
}
|
|
@@ -7,10 +7,10 @@ class CoreSystemPromptModifier extends base_1.BaseMessageModifier {
|
|
|
7
7
|
super();
|
|
8
8
|
this.options = options;
|
|
9
9
|
}
|
|
10
|
-
modify(
|
|
10
|
+
modify(_originalRequest, createdMessage) {
|
|
11
11
|
var _a;
|
|
12
12
|
// Get user memory from metadata or options
|
|
13
|
-
const userMemory = ((_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a
|
|
13
|
+
const userMemory = ((_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a['userMemory']) || this.options.userMemory;
|
|
14
14
|
const systemPrompt = this.options.customSystemPrompt || this.getCoreSystemPrompt(userMemory);
|
|
15
15
|
const systemMessage = {
|
|
16
16
|
role: 'system',
|
|
@@ -9,7 +9,7 @@ export declare class DirectoryContextModifier extends BaseMessageModifier {
|
|
|
9
9
|
private gitignorePatterns;
|
|
10
10
|
private gitignoreRegexes;
|
|
11
11
|
constructor(options?: DirectoryContextOptions);
|
|
12
|
-
modify(
|
|
12
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
13
13
|
private loadGitignorePatterns;
|
|
14
14
|
private parseGitignoreContent;
|
|
15
15
|
private isGitIgnored;
|
|
@@ -69,7 +69,7 @@ class DirectoryContextModifier extends base_1.BaseMessageModifier {
|
|
|
69
69
|
workspaceDirectories: options.workspaceDirectories || []
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
async modify(
|
|
72
|
+
async modify(_originalRequest, createdMessage) {
|
|
73
73
|
try {
|
|
74
74
|
// Get workspace directories from codebolt or use provided options
|
|
75
75
|
let workspaceDirectories = this.options.workspaceDirectories;
|
|
@@ -211,8 +211,10 @@ ${folderStructure}`;
|
|
|
211
211
|
const mergedOptions = {
|
|
212
212
|
maxItems: (_a = options === null || options === void 0 ? void 0 : options.maxItems) !== null && _a !== void 0 ? _a : MAX_ITEMS,
|
|
213
213
|
ignoredFolders: (_b = options === null || options === void 0 ? void 0 : options.ignoredFolders) !== null && _b !== void 0 ? _b : DEFAULT_IGNORED_FOLDERS,
|
|
214
|
-
fileIncludePattern: options === null || options === void 0 ? void 0 : options.fileIncludePattern,
|
|
215
214
|
};
|
|
215
|
+
if (options === null || options === void 0 ? void 0 : options.fileIncludePattern) {
|
|
216
|
+
mergedOptions.fileIncludePattern = options.fileIncludePattern;
|
|
217
|
+
}
|
|
216
218
|
try {
|
|
217
219
|
// 1. Read the structure using BFS, respecting maxItems
|
|
218
220
|
const structureRoot = await this.readFullStructure(resolvedPath, mergedOptions);
|
|
@@ -408,7 +410,10 @@ ${folderStructure}`;
|
|
|
408
410
|
for (let i = 0; i < subFolderCount; i++) {
|
|
409
411
|
const isLastSubfolderAmongSiblings = i === subFolderCount - 1 && !node.hasMoreSubfolders;
|
|
410
412
|
// Children are never the root node being processed initially.
|
|
411
|
-
|
|
413
|
+
const subFolder = node.subFolders[i];
|
|
414
|
+
if (subFolder) {
|
|
415
|
+
this.formatStructure(subFolder, indentForChildren, isLastSubfolderAmongSiblings, false, builder);
|
|
416
|
+
}
|
|
412
417
|
}
|
|
413
418
|
if (node.hasMoreSubfolders) {
|
|
414
419
|
builder.push(`${indentForChildren}└───${TRUNCATION_INDICATOR}`);
|
|
@@ -12,7 +12,7 @@ export declare class EnvironmentContextModifier extends BaseMessageModifier {
|
|
|
12
12
|
private readonly options;
|
|
13
13
|
private readonly defaultExcludePatterns;
|
|
14
14
|
constructor(options?: EnvironmentContextOptions);
|
|
15
|
-
modify(
|
|
15
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
16
16
|
private generateFullContext;
|
|
17
17
|
private findRelevantFiles;
|
|
18
18
|
private walkDirectory;
|
|
@@ -66,7 +66,7 @@ class EnvironmentContextModifier extends base_1.BaseMessageModifier {
|
|
|
66
66
|
excludePatterns: [...this.defaultExcludePatterns, ...(options.excludePatterns || [])]
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
async modify(
|
|
69
|
+
async modify(_originalRequest, createdMessage) {
|
|
70
70
|
try {
|
|
71
71
|
// Get current date formatted to user's locale
|
|
72
72
|
const today = new Date().toLocaleDateString(undefined, {
|
|
@@ -34,16 +34,21 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
34
34
|
const systemMessageIndex = messages.findIndex(msg => msg.role === 'system');
|
|
35
35
|
if (systemMessageIndex !== -1) {
|
|
36
36
|
// Append to existing system message
|
|
37
|
-
messages[systemMessageIndex]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const existingMessage = messages[systemMessageIndex];
|
|
38
|
+
if (existingMessage) {
|
|
39
|
+
messages[systemMessageIndex] = {
|
|
40
|
+
role: existingMessage.role,
|
|
41
|
+
content: `${existingMessage.content}\n\n${ideContextMessage.content}`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
else {
|
|
43
46
|
// Add new system message
|
|
44
47
|
messages.unshift(ideContextMessage);
|
|
45
48
|
}
|
|
46
|
-
|
|
49
|
+
if (newIdeContext) {
|
|
50
|
+
this.lastSentIdeContext = newIdeContext;
|
|
51
|
+
}
|
|
47
52
|
this.forceFullContext = false;
|
|
48
53
|
return Promise.resolve({
|
|
49
54
|
message: {
|
|
@@ -64,8 +69,8 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
64
69
|
}
|
|
65
70
|
getIdeContext(originalRequest, metadata) {
|
|
66
71
|
// Try to get IDE context from the metadata parameter first
|
|
67
|
-
if (metadata === null || metadata === void 0 ? void 0 : metadata
|
|
68
|
-
return metadata
|
|
72
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata['ideContext']) {
|
|
73
|
+
return metadata['ideContext'];
|
|
69
74
|
}
|
|
70
75
|
// Extract IDE context from the original message
|
|
71
76
|
const activeFile = originalRequest.activeFile;
|
|
@@ -102,7 +107,7 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
102
107
|
};
|
|
103
108
|
}
|
|
104
109
|
getIdeContextParts(forceFullContext, currentIdeContext) {
|
|
105
|
-
var _a;
|
|
110
|
+
var _a, _b, _c, _d, _e;
|
|
106
111
|
if (!((_a = currentIdeContext === null || currentIdeContext === void 0 ? void 0 : currentIdeContext.workspaceState) === null || _a === void 0 ? void 0 : _a.openFiles)) {
|
|
107
112
|
return { contextParts: [], newIdeContext: undefined };
|
|
108
113
|
}
|
|
@@ -119,14 +124,16 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
119
124
|
const activeFileData = {
|
|
120
125
|
path: activeFile.path
|
|
121
126
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
const cursor = activeFile['cursor'];
|
|
128
|
+
if (this.options.includeCursorPosition && cursor) {
|
|
129
|
+
activeFileData['cursor'] = {
|
|
130
|
+
line: cursor.line,
|
|
131
|
+
character: cursor.character,
|
|
126
132
|
};
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
const selectedText = activeFile['selectedText'];
|
|
135
|
+
if (this.options.includeSelectedText && selectedText) {
|
|
136
|
+
activeFileData['selectedText'] = selectedText;
|
|
130
137
|
}
|
|
131
138
|
contextData['activeFile'] = activeFileData;
|
|
132
139
|
}
|
|
@@ -146,9 +153,99 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
146
153
|
];
|
|
147
154
|
return { contextParts, newIdeContext: currentIdeContext };
|
|
148
155
|
}
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
// Calculate and send delta as JSON
|
|
157
|
+
const delta = {};
|
|
158
|
+
const changes = {};
|
|
159
|
+
const lastFiles = new Map((((_b = this.lastSentIdeContext.workspaceState) === null || _b === void 0 ? void 0 : _b.openFiles) || []).map((f) => [f.path, f]));
|
|
160
|
+
const currentFiles = new Map((((_c = currentIdeContext.workspaceState) === null || _c === void 0 ? void 0 : _c.openFiles) || []).map((f) => [
|
|
161
|
+
f.path,
|
|
162
|
+
f,
|
|
163
|
+
]));
|
|
164
|
+
const openedFiles = [];
|
|
165
|
+
for (const [path] of currentFiles.entries()) {
|
|
166
|
+
if (!lastFiles.has(path)) {
|
|
167
|
+
openedFiles.push(path);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (openedFiles.length > 0) {
|
|
171
|
+
changes['filesOpened'] = openedFiles;
|
|
172
|
+
}
|
|
173
|
+
const closedFiles = [];
|
|
174
|
+
for (const [path] of lastFiles.entries()) {
|
|
175
|
+
if (!currentFiles.has(path)) {
|
|
176
|
+
closedFiles.push(path);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (closedFiles.length > 0) {
|
|
180
|
+
changes['filesClosed'] = closedFiles;
|
|
181
|
+
}
|
|
182
|
+
const lastActiveFile = (((_d = this.lastSentIdeContext.workspaceState) === null || _d === void 0 ? void 0 : _d.openFiles) || []).find((f) => f.isActive);
|
|
183
|
+
const currentActiveFile = (((_e = currentIdeContext.workspaceState) === null || _e === void 0 ? void 0 : _e.openFiles) || []).find((f) => f.isActive);
|
|
184
|
+
if (currentActiveFile) {
|
|
185
|
+
if (!lastActiveFile || lastActiveFile.path !== currentActiveFile.path) {
|
|
186
|
+
const activeFileChange = {
|
|
187
|
+
path: currentActiveFile.path
|
|
188
|
+
};
|
|
189
|
+
if (this.options.includeCursorPosition && currentActiveFile.cursor) {
|
|
190
|
+
activeFileChange['cursor'] = {
|
|
191
|
+
line: currentActiveFile.cursor.line,
|
|
192
|
+
character: currentActiveFile.cursor.character,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (this.options.includeSelectedText && currentActiveFile.selectedText) {
|
|
196
|
+
activeFileChange['selectedText'] = currentActiveFile.selectedText;
|
|
197
|
+
}
|
|
198
|
+
changes['activeFileChanged'] = activeFileChange;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const lastCursor = lastActiveFile.cursor;
|
|
202
|
+
const currentCursor = currentActiveFile.cursor;
|
|
203
|
+
if (this.options.includeCursorPosition &&
|
|
204
|
+
currentCursor &&
|
|
205
|
+
(!lastCursor ||
|
|
206
|
+
lastCursor.line !== currentCursor.line ||
|
|
207
|
+
lastCursor.character !== currentCursor.character)) {
|
|
208
|
+
changes['cursorMoved'] = {
|
|
209
|
+
path: currentActiveFile.path,
|
|
210
|
+
cursor: {
|
|
211
|
+
line: currentCursor.line,
|
|
212
|
+
character: currentCursor.character,
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const lastSelectedText = lastActiveFile.selectedText || '';
|
|
217
|
+
const currentSelectedText = currentActiveFile.selectedText || '';
|
|
218
|
+
if (this.options.includeSelectedText &&
|
|
219
|
+
lastSelectedText !== currentSelectedText) {
|
|
220
|
+
changes['selectionChanged'] = {
|
|
221
|
+
path: currentActiveFile.path,
|
|
222
|
+
selectedText: currentSelectedText,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (lastActiveFile) {
|
|
228
|
+
changes['activeFileChanged'] = {
|
|
229
|
+
path: null,
|
|
230
|
+
previousPath: lastActiveFile.path,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (Object.keys(changes).length === 0) {
|
|
234
|
+
return { contextParts: [], newIdeContext: currentIdeContext };
|
|
235
|
+
}
|
|
236
|
+
delta['changes'] = changes;
|
|
237
|
+
const jsonString = JSON.stringify(delta, null, 2);
|
|
238
|
+
const contextParts = [
|
|
239
|
+
"Here is a summary of changes in the user's editor context, in JSON format. This is for your information only.",
|
|
240
|
+
'```json',
|
|
241
|
+
jsonString,
|
|
242
|
+
'```',
|
|
243
|
+
"Don't acknowledge this context in your response unless specifically asked about it."
|
|
244
|
+
];
|
|
245
|
+
return {
|
|
246
|
+
contextParts,
|
|
247
|
+
newIdeContext: currentIdeContext,
|
|
248
|
+
};
|
|
152
249
|
}
|
|
153
250
|
setForceFullContext(force) {
|
|
154
251
|
this.forceFullContext = force;
|
|
@@ -11,5 +11,5 @@ export interface MemoryImportOptions {
|
|
|
11
11
|
export declare class MemoryImportModifier extends BaseMessageModifier {
|
|
12
12
|
private readonly options;
|
|
13
13
|
constructor(options?: MemoryImportOptions);
|
|
14
|
-
modify(
|
|
14
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
15
15
|
}
|
|
@@ -48,7 +48,8 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
48
48
|
maxImports: options.maxImports || 10
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
async modify(
|
|
51
|
+
async modify(_originalRequest, createdMessage) {
|
|
52
|
+
var _a, _b, _c, _d;
|
|
52
53
|
try {
|
|
53
54
|
if (!this.options.enableMemoryImport) {
|
|
54
55
|
return createdMessage;
|
|
@@ -64,21 +65,28 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
64
65
|
const processedImports = [];
|
|
65
66
|
let match;
|
|
66
67
|
let importCount = 0;
|
|
67
|
-
|
|
68
|
+
const basePath = (_a = this.options.basePath) !== null && _a !== void 0 ? _a : process.cwd();
|
|
69
|
+
const maxImports = (_b = this.options.maxImports) !== null && _b !== void 0 ? _b : 10;
|
|
70
|
+
const maxFileSize = (_c = this.options.maxFileSize) !== null && _c !== void 0 ? _c : 1024 * 1024;
|
|
71
|
+
const allowedExtensions = (_d = this.options.allowedExtensions) !== null && _d !== void 0 ? _d : [];
|
|
72
|
+
while ((match = memoryImportPattern.exec(userMessage.content)) !== null && importCount < maxImports) {
|
|
68
73
|
const filePath = match[1];
|
|
69
|
-
|
|
74
|
+
if (!filePath) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(basePath, filePath);
|
|
70
78
|
try {
|
|
71
79
|
// Check if file exists and is allowed
|
|
72
80
|
const stats = await fs.promises.stat(fullPath);
|
|
73
81
|
if (!stats.isFile()) {
|
|
74
82
|
continue;
|
|
75
83
|
}
|
|
76
|
-
if (stats.size >
|
|
84
|
+
if (stats.size > maxFileSize) {
|
|
77
85
|
content = content.replace(match[0], `[File too large: ${filePath}]`);
|
|
78
86
|
continue;
|
|
79
87
|
}
|
|
80
88
|
const ext = path.extname(filePath);
|
|
81
|
-
if (!
|
|
89
|
+
if (!allowedExtensions.includes(ext)) {
|
|
82
90
|
content = content.replace(match[0], `[Unsupported file type: ${filePath}]`);
|
|
83
91
|
continue;
|
|
84
92
|
}
|
|
@@ -7,6 +7,11 @@ export interface ToolInjectionOptions {
|
|
|
7
7
|
maxToolsInMessage?: number;
|
|
8
8
|
giveToolExamples?: boolean;
|
|
9
9
|
maxToolExamples?: number;
|
|
10
|
+
/**
|
|
11
|
+
* List of allowed tool names. If provided, only these tools will be available.
|
|
12
|
+
* If not provided, all tools will be available.
|
|
13
|
+
*/
|
|
14
|
+
allowedTools?: string[];
|
|
10
15
|
}
|
|
11
16
|
export declare class ToolInjectionModifier extends BaseMessageModifier {
|
|
12
17
|
private readonly options;
|
|
@@ -24,6 +24,10 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
24
24
|
let mentionedMCPs = originalRequest.mentionedMCPs || [];
|
|
25
25
|
const { data: mentionedTools } = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
|
|
26
26
|
tools = [...tools, ...(mentionedTools || [])];
|
|
27
|
+
// Filter tools if allowedTools is specified
|
|
28
|
+
if (this.options.allowedTools && this.options.allowedTools.length > 0) {
|
|
29
|
+
tools = tools.filter((tool) => this.options.allowedTools.includes(tool.function.name));
|
|
30
|
+
}
|
|
27
31
|
if (tools.length === 0) {
|
|
28
32
|
return createdMessage;
|
|
29
33
|
}
|
|
@@ -123,9 +123,13 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
123
123
|
// Compare each message with every other message
|
|
124
124
|
for (let i = 0; i < messages.length - 1; i++) {
|
|
125
125
|
for (let j = i + 1; j < messages.length; j++) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
const msgI = messages[i];
|
|
127
|
+
const msgJ = messages[j];
|
|
128
|
+
if (msgI && msgJ) {
|
|
129
|
+
const similarity = this.calculateSimilarity(msgI.content, msgJ.content);
|
|
130
|
+
if (similarity >= this.options.similarityThreshold) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
}
|
|
@@ -140,24 +144,36 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
140
144
|
return 1 - (distance / maxLength);
|
|
141
145
|
}
|
|
142
146
|
levenshteinDistance(str1, str2) {
|
|
147
|
+
var _a, _b, _c, _d;
|
|
143
148
|
const matrix = [];
|
|
144
149
|
for (let i = 0; i <= str2.length; i++) {
|
|
145
150
|
matrix[i] = [i];
|
|
146
151
|
}
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
const firstRow = matrix[0];
|
|
153
|
+
if (firstRow) {
|
|
154
|
+
for (let j = 0; j <= str1.length; j++) {
|
|
155
|
+
firstRow[j] = j;
|
|
156
|
+
}
|
|
149
157
|
}
|
|
150
158
|
for (let i = 1; i <= str2.length; i++) {
|
|
159
|
+
const currentRow = matrix[i];
|
|
160
|
+
const prevRow = matrix[i - 1];
|
|
161
|
+
if (!currentRow || !prevRow)
|
|
162
|
+
continue;
|
|
151
163
|
for (let j = 1; j <= str1.length; j++) {
|
|
164
|
+
const prevDiag = (_a = prevRow[j - 1]) !== null && _a !== void 0 ? _a : 0;
|
|
165
|
+
const prevUp = (_b = prevRow[j]) !== null && _b !== void 0 ? _b : 0;
|
|
166
|
+
const prevLeft = (_c = currentRow[j - 1]) !== null && _c !== void 0 ? _c : 0;
|
|
152
167
|
if (str2.charAt(i - 1) === str1.charAt(j - 1)) {
|
|
153
|
-
|
|
168
|
+
currentRow[j] = prevDiag;
|
|
154
169
|
}
|
|
155
170
|
else {
|
|
156
|
-
|
|
171
|
+
currentRow[j] = Math.min(prevDiag + 1, prevLeft + 1, prevUp + 1);
|
|
157
172
|
}
|
|
158
173
|
}
|
|
159
174
|
}
|
|
160
|
-
|
|
175
|
+
const lastRow = matrix[str2.length];
|
|
176
|
+
return (_d = lastRow === null || lastRow === void 0 ? void 0 : lastRow[str1.length]) !== null && _d !== void 0 ? _d : 0;
|
|
161
177
|
}
|
|
162
178
|
cleanOldMessages(currentTime) {
|
|
163
179
|
const cutoffTime = currentTime - this.options.timeWindowMs;
|