@codebolt/agent 2.2.2 → 2.2.5

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 (141) hide show
  1. package/dist/builderpattern/agent.js +2 -2
  2. package/dist/builderpattern/followupquestionbuilder.js +1 -1
  3. package/dist/builderpattern/llmoutputhandler.js +7 -7
  4. package/dist/builderpattern/usermessage.d.ts +6 -1
  5. package/dist/composablepattern/document.js +2 -35
  6. package/dist/local-tools/fileTools.d.ts +26 -0
  7. package/dist/local-tools/fileTools.js +162 -0
  8. package/dist/processor/types/interfaces.d.ts +44 -21
  9. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +13 -0
  10. package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +68 -0
  11. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +15 -0
  12. package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +212 -0
  13. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +19 -0
  14. package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +110 -0
  15. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +23 -0
  16. package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +173 -0
  17. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +14 -0
  18. package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +93 -0
  19. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +30 -0
  20. package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +330 -0
  21. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +26 -0
  22. package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +269 -0
  23. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +38 -0
  24. package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +217 -0
  25. package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +34 -0
  26. package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +147 -0
  27. package/dist/processor-pieces/additionalModifiers/index.d.ts +12 -0
  28. package/dist/processor-pieces/additionalModifiers/index.js +28 -0
  29. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +29 -0
  30. package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +155 -0
  31. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +15 -0
  32. package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +129 -0
  33. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +25 -0
  34. package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +169 -0
  35. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +20 -0
  36. package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +152 -0
  37. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +7 -0
  38. package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +93 -0
  39. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +14 -5
  40. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +41 -40
  41. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +9 -0
  42. package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +77 -0
  43. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +5 -5
  44. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +5 -13
  45. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +50 -58
  46. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +6 -8
  47. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +66 -22
  48. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +19 -0
  49. package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +110 -0
  50. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +20 -0
  51. package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +124 -0
  52. package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +41 -0
  53. package/dist/processor-pieces/messageModifiers/environmentContext.js +355 -0
  54. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +3 -2
  55. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +1 -2
  56. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +3 -2
  57. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +1 -2
  58. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +23 -0
  59. package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +207 -0
  60. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +7 -0
  61. package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +26 -0
  62. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +18 -2
  63. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +291 -93
  64. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +1 -0
  65. package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +2 -0
  66. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +7 -0
  67. package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +24 -0
  68. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +41 -0
  69. package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +197 -0
  70. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +26 -0
  71. package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +90 -0
  72. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +81 -0
  73. package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +329 -0
  74. package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +40 -0
  75. package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +272 -0
  76. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +49 -0
  77. package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +291 -0
  78. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +49 -0
  79. package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +293 -0
  80. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +47 -0
  81. package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +249 -0
  82. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +30 -0
  83. package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +137 -0
  84. package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +30 -0
  85. package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +228 -0
  86. package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +99 -0
  87. package/dist/processor-pieces/postToolCall/telemetryProcessor.js +278 -0
  88. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +37 -0
  89. package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +178 -0
  90. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +43 -0
  91. package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +207 -0
  92. package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +52 -0
  93. package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +264 -0
  94. package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +49 -0
  95. package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +293 -0
  96. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +7 -0
  97. package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +31 -0
  98. package/dist/processor-pieces/preToolCall/index.d.ts +9 -0
  99. package/dist/processor-pieces/preToolCall/index.js +18 -0
  100. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +58 -0
  101. package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +444 -0
  102. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +44 -0
  103. package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +367 -0
  104. package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +58 -0
  105. package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +391 -0
  106. package/dist/unified/agent/agent.js +2 -2
  107. package/dist/unified/agent/tool.d.ts +99 -0
  108. package/dist/unified/agent/tool.js +440 -0
  109. package/dist/unified/base/initialPromptGenerator.js +5 -5
  110. package/dist/unified/base/responseExecutor.js +6 -6
  111. package/dist/unified/examples/agentExample.d.ts +46 -0
  112. package/dist/unified/examples/agentExample.js +464 -0
  113. package/dist/unified/examples/documentationPatternExample.d.ts +10 -0
  114. package/dist/unified/examples/documentationPatternExample.js +385 -0
  115. package/dist/unified/examples/followUpProcessorsExample.d.ts +45 -0
  116. package/dist/unified/examples/followUpProcessorsExample.js +311 -0
  117. package/dist/unified/examples/orchestratorExample.d.ts +16 -0
  118. package/dist/unified/examples/orchestratorExample.js +415 -0
  119. package/dist/unified/examples/preToolCallProcessorsExample.d.ts +36 -0
  120. package/dist/unified/examples/preToolCallProcessorsExample.js +458 -0
  121. package/dist/unified/examples/workflowExample.d.ts +12 -0
  122. package/dist/unified/examples/workflowExample.js +497 -0
  123. package/dist/unified/orchestrator/orchestrator.d.ts +260 -0
  124. package/dist/unified/orchestrator/orchestrator.js +519 -0
  125. package/package.json +5 -5
  126. package/dist/agent.d.ts +0 -86
  127. package/dist/agent.js +0 -324
  128. package/dist/followupquestionbuilder.d.ts +0 -75
  129. package/dist/followupquestionbuilder.js +0 -197
  130. package/dist/index.d.ts +0 -14
  131. package/dist/index.js +0 -23
  132. package/dist/llmoutputhandler.d.ts +0 -102
  133. package/dist/llmoutputhandler.js +0 -452
  134. package/dist/promptbuilder.d.ts +0 -382
  135. package/dist/promptbuilder.js +0 -805
  136. package/dist/systemprompt.d.ts +0 -20
  137. package/dist/systemprompt.js +0 -48
  138. package/dist/taskInstruction.d.ts +0 -37
  139. package/dist/taskInstruction.js +0 -57
  140. package/dist/usermessage.d.ts +0 -70
  141. package/dist/usermessage.js +0 -123
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AddToolsListMessageModifier = void 0;
4
- const processor_1 = require("../../processor");
5
- class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
6
- constructor(options) {
7
+ const base_1 = require("../base");
8
+ const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
9
+ class AddToolsListMessageModifier extends base_1.BaseMessageModifier {
10
+ constructor(options = {}) {
7
11
  super({ context: options });
8
12
  this.toolsList = options.toolsList;
9
13
  this.addToolsLocation = options.addToolsLocation || 'SystemMessage';
@@ -11,10 +15,10 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
11
15
  this.maxToolExamples = options.maxToolExamples || 2;
12
16
  this.includeToolDescriptions = options.includeToolDescriptions !== false; // default true
13
17
  }
14
- async modify(input) {
18
+ async modify(originalRequest, createdMessage) {
15
19
  try {
16
- const { originalRequest, createdMessage, context } = input;
17
- const tools = this.toolsList.getAllTools();
20
+ const toolsResponse = await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']);
21
+ const tools = (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) || [];
18
22
  if (tools.length === 0) {
19
23
  return createdMessage;
20
24
  }
@@ -26,7 +30,7 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
26
30
  case 'Tool':
27
31
  return this.addToolsAsToolCalls(createdMessage, tools);
28
32
  default:
29
- return createdMessage;
33
+ return this.addToolsAsToolCalls(createdMessage, tools);
30
34
  }
31
35
  }
32
36
  catch (error) {
@@ -37,8 +41,8 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
37
41
  addToolsInsidePrompt(createdMessage, tools) {
38
42
  const toolsInfo = this.generateToolsInfo(tools);
39
43
  // Modify the last user message to include tools information
40
- const modifiedMessages = createdMessage.messages.map((message, index) => {
41
- if (message.role === 'user' && index === createdMessage.messages.length - 1) {
44
+ const modifiedMessages = createdMessage.message.messages.map((message, index) => {
45
+ if (message.role === 'user' && index === createdMessage.message.messages.length - 1) {
42
46
  return {
43
47
  ...message,
44
48
  content: `${message.content}\n\n--- Available Tools ---\n${toolsInfo}`
@@ -47,7 +51,10 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
47
51
  return message;
48
52
  });
49
53
  return {
50
- messages: modifiedMessages,
54
+ message: {
55
+ ...createdMessage.message,
56
+ messages: modifiedMessages
57
+ },
51
58
  metadata: {
52
59
  ...createdMessage.metadata,
53
60
  toolsListAdded: true,
@@ -60,11 +67,13 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
60
67
  const toolsInfo = this.generateToolsInfo(tools);
61
68
  const toolsMessage = {
62
69
  role: 'system',
63
- content: `Available Tools:\n${toolsInfo}`,
64
- name: 'tools-list'
70
+ content: `Available Tools:\n${toolsInfo}`
65
71
  };
66
72
  return {
67
- messages: [toolsMessage, ...createdMessage.messages],
73
+ message: {
74
+ ...createdMessage.message,
75
+ messages: [toolsMessage, ...createdMessage.message.messages]
76
+ },
68
77
  metadata: {
69
78
  ...createdMessage.metadata,
70
79
  toolsListAdded: true,
@@ -74,20 +83,12 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
74
83
  };
75
84
  }
76
85
  addToolsAsToolCalls(createdMessage, tools) {
77
- // This would create a message that lists tools as available tool calls
78
- const toolsMessage = {
79
- role: 'assistant',
80
- content: 'I have access to the following tools:',
81
- tool_calls: tools.map((tool, index) => ({
82
- id: `tool-info-${index}`,
83
- function: {
84
- name: tool.name,
85
- arguments: tool.parameters || {}
86
- }
87
- }))
88
- };
89
86
  return {
90
- messages: [...createdMessage.messages, toolsMessage],
87
+ message: {
88
+ ...createdMessage.message,
89
+ tools,
90
+ tool_choice: 'auto'
91
+ },
91
92
  metadata: {
92
93
  ...createdMessage.metadata,
93
94
  toolsListAdded: true,
@@ -99,14 +100,14 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
99
100
  generateToolsInfo(tools) {
100
101
  const toolsInfo = [];
101
102
  tools.forEach((tool, index) => {
102
- let toolInfo = `${index + 1}. **${tool.name}**`;
103
- if (this.includeToolDescriptions && tool.description) {
104
- toolInfo += `\n Description: ${tool.description}`;
103
+ let toolInfo = `${index + 1}. **${tool.function.name}**`;
104
+ if (this.includeToolDescriptions && tool.function.description) {
105
+ toolInfo += `\n Description: ${tool.function.description}`;
105
106
  }
106
- if (tool.parameters) {
107
- const params = typeof tool.parameters === 'object'
108
- ? Object.keys(tool.parameters).join(', ')
109
- : String(tool.parameters);
107
+ if (tool.function.parameters) {
108
+ const params = typeof tool.function.parameters === 'object'
109
+ ? Object.keys(tool.function.parameters).join(', ')
110
+ : String(tool.function.parameters);
110
111
  toolInfo += `\n Parameters: ${params}`;
111
112
  }
112
113
  if (this.giveToolExamples && index < this.maxToolExamples) {
@@ -121,24 +122,24 @@ class AddToolsListMessageModifier extends processor_1.BaseMessageModifier {
121
122
  }
122
123
  generateToolExample(tool) {
123
124
  // Generate simple examples based on tool name
124
- const toolName = tool.name.toLowerCase();
125
+ const toolName = tool.function.name.toLowerCase();
125
126
  if (toolName.includes('read') && toolName.includes('file')) {
126
- return `${tool.name}({ filePath: "example.txt" })`;
127
+ return `${tool.function.name}({ filePath: "example.txt" })`;
127
128
  }
128
129
  if (toolName.includes('write') && toolName.includes('file')) {
129
- return `${tool.name}({ filePath: "output.txt", content: "Hello World" })`;
130
+ return `${tool.function.name}({ filePath: "output.txt", content: "Hello World" })`;
130
131
  }
131
132
  if (toolName.includes('delete') && toolName.includes('file')) {
132
- return `${tool.name}({ filePath: "temp.txt" })`;
133
+ return `${tool.function.name}({ filePath: "temp.txt" })`;
133
134
  }
134
135
  if (toolName.includes('move') && toolName.includes('file')) {
135
- return `${tool.name}({ sourcePath: "old.txt", destinationPath: "new.txt" })`;
136
+ return `${tool.function.name}({ sourcePath: "old.txt", destinationPath: "new.txt" })`;
136
137
  }
137
138
  if (toolName.includes('copy') && toolName.includes('file')) {
138
- return `${tool.name}({ sourcePath: "source.txt", destinationPath: "copy.txt" })`;
139
+ return `${tool.function.name}({ sourcePath: "source.txt", destinationPath: "copy.txt" })`;
139
140
  }
140
141
  // Generic example
141
- return `${tool.name}({ /* parameters */ })`;
142
+ return `${tool.function.name}({ /* parameters */ })`;
142
143
  }
143
144
  }
144
145
  exports.AddToolsListMessageModifier = AddToolsListMessageModifier;
@@ -0,0 +1,9 @@
1
+ import { ProcessedMessage } from "@codebolt/types/agent";
2
+ import { BaseMessageModifier } from "../base";
3
+ import { FlatUserMessage } from "@codebolt/types/sdk";
4
+ export declare class AdvancedSystemInstructionMessageModifier extends BaseMessageModifier {
5
+ private readonly systemInstruction;
6
+ constructor(systemInstruction?: string);
7
+ modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
8
+ private getAdvancedSystemPrompt;
9
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdvancedSystemInstructionMessageModifier = void 0;
4
+ const base_1 = require("../base");
5
+ class AdvancedSystemInstructionMessageModifier extends base_1.BaseMessageModifier {
6
+ constructor(systemInstruction) {
7
+ super();
8
+ this.systemInstruction = systemInstruction || this.getAdvancedSystemPrompt();
9
+ }
10
+ async modify(originalRequest, createdMessage) {
11
+ try {
12
+ const systemMessage = {
13
+ role: 'system',
14
+ content: this.systemInstruction
15
+ };
16
+ const messages = [...(createdMessage.message.messages || [])];
17
+ const existingSystemIndex = messages.findIndex(msg => msg.role === 'system');
18
+ if (existingSystemIndex !== -1) {
19
+ messages[existingSystemIndex] = systemMessage;
20
+ }
21
+ else {
22
+ messages.unshift(systemMessage);
23
+ }
24
+ return {
25
+ message: {
26
+ ...createdMessage.message,
27
+ messages
28
+ },
29
+ metadata: {
30
+ ...createdMessage.metadata
31
+ }
32
+ };
33
+ }
34
+ catch (error) {
35
+ console.error('Error in AdvancedSystemInstructionMessageModifier:', error);
36
+ throw error;
37
+ }
38
+ }
39
+ getAdvancedSystemPrompt() {
40
+ const advancedPrompt = `
41
+ You are an advanced AI software engineering assistant with expertise in multiple programming languages, frameworks, and best practices. Your primary goal is to assist users efficiently and safely while adhering to the following guidelines:
42
+
43
+ 1. Code Quality and Best Practices:
44
+ - Write clean, efficient, and maintainable code
45
+ - Follow SOLID principles and design patterns when appropriate
46
+ - Implement proper error handling and logging
47
+ - Write unit tests for new functionality
48
+ - Ensure code is secure and follows cybersecurity best practices
49
+
50
+ 2. Project-Specific Considerations:
51
+ - Analyze and adhere to existing project structure, naming conventions, and coding style
52
+ - Use established libraries and frameworks within the project
53
+ - Consider scalability and performance implications of changes
54
+ - Maintain backward compatibility unless explicitly instructed otherwise
55
+
56
+ 3. Communication and Collaboration:
57
+ - Provide clear, concise explanations for your decisions and implementations
58
+ - Ask clarifying questions when requirements are ambiguous
59
+ - Suggest improvements or alternatives when appropriate
60
+ - Break down complex tasks into manageable steps
61
+
62
+ 4. Continuous Learning and Adaptation:
63
+ - Stay updated on latest industry trends and best practices
64
+ - Adapt your approach based on user feedback and project requirements
65
+ - Recommend modern tools and techniques when beneficial to the project
66
+
67
+ 5. Ethical Considerations:
68
+ - Respect intellectual property rights and licensing
69
+ - Avoid implementing features that could be used maliciously
70
+ - Promote inclusive and accessible code practices
71
+
72
+ Remember to use the provided tools effectively, always prioritize user safety and project integrity, and strive for excellence in every task you undertake.
73
+ `.trim();
74
+ return advancedPrompt;
75
+ }
76
+ }
77
+ exports.AdvancedSystemInstructionMessageModifier = AdvancedSystemInstructionMessageModifier;
@@ -176,18 +176,18 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
176
176
  contextParts.push(structure);
177
177
  // Also read files within the folder
178
178
  const filesInFolder = await this.getFilesInFolder(resolvedPath);
179
- console.log(`Found ${filesInFolder.length} files in ${folderPath}:`, filesInFolder.map(f => path.basename(f)));
179
+ // console.log(`Found ${filesInFolder.length} files in ${folderPath}:`, filesInFolder.map(f => path.basename(f)));
180
180
  if (filesInFolder.length > 0) {
181
181
  contextParts.push(`\n--- Files in ${folderPath} ---`);
182
182
  for (const filePath of filesInFolder) {
183
183
  try {
184
- console.log(`Attempting to read file: ${filePath}`);
184
+ // console.log(`Attempting to read file: ${filePath}`);
185
185
  const content = await this.readFileContent(filePath);
186
186
  const relativePath = path.relative(resolvedPath, filePath);
187
187
  const displayPath = `${folderPath}/${relativePath}`;
188
188
  contextParts.push(`\nContent from @${displayPath}:\n`);
189
189
  contextParts.push(content);
190
- console.log(`Successfully read file: ${displayPath} (${content.length} chars)`);
190
+ // console.log(`Successfully read file: ${displayPath} (${content.length} chars)`);
191
191
  }
192
192
  catch (error) {
193
193
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -372,12 +372,12 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
372
372
  // Check file extension if allowed extensions are specified
373
373
  if (this.options.allowedExtensions.length > 0) {
374
374
  const ext = path.extname(entry.name).toLowerCase();
375
- console.log(`Checking file ${entry.name} with extension ${ext}. Allowed:`, this.options.allowedExtensions);
375
+ // console.log(`Checking file ${entry.name} with extension ${ext}. Allowed:`, this.options.allowedExtensions);
376
376
  if (this.options.allowedExtensions.includes(ext)) {
377
377
  files.push(path.join(folderPath, entry.name));
378
378
  }
379
379
  else {
380
- console.log(`File ${entry.name} extension ${ext} not in allowed list`);
380
+ // console.log(`File ${entry.name} extension ${ext} not in allowed list`);
381
381
  }
382
382
  }
383
383
  else {
@@ -1,15 +1,7 @@
1
- import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
2
- export interface BaseContextMessageModifierOptions {
3
- prependmessage?: string;
4
- datetime?: boolean;
5
- osInfo?: boolean;
6
- workingdir?: boolean;
7
- }
1
+ import { ProcessedMessage } from "@codebolt/types/agent";
2
+ import { BaseMessageModifier } from "../base";
3
+ import { FlatUserMessage } from "@codebolt/types/sdk";
8
4
  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>;
5
+ constructor();
6
+ modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
15
7
  }
@@ -4,72 +4,64 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BaseContextMessageModifier = void 0;
7
- const processor_1 = require("../../processor");
7
+ const base_1 = require("../base");
8
8
  const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
9
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;
10
+ class BaseContextMessageModifier extends base_1.BaseMessageModifier {
11
+ constructor() {
12
+ super();
17
13
  }
18
- async modify(input) {
14
+ async modify(originalRequest, createdMessage) {
15
+ const contextParts = [];
16
+ const now = new Date();
17
+ contextParts.push(`Current Date/Time: ${now.toISOString()}`);
18
+ const osInfo = {
19
+ platform: os_1.default.platform(),
20
+ arch: os_1.default.arch(),
21
+ version: os_1.default.version(),
22
+ hostname: os_1.default.hostname()
23
+ };
24
+ contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
19
25
  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()
26
+ const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
27
+ contextParts.push(`Working Directory: ${projectPath}`);
28
+ }
29
+ catch (error) {
30
+ contextParts.push(`Working Directory: ${process.cwd()}`);
31
+ }
32
+ if (contextParts.length > 0) {
33
+ const contextMessage = {
34
+ role: 'system',
35
+ content: contextParts.join('\n\n'),
36
+ };
37
+ // Create a copy of messages array
38
+ const messages = [...createdMessage.message.messages];
39
+ // Check if system message already exists in the messages array
40
+ const existingSystemMessageIndex = messages.findIndex(msg => msg.role == 'system');
41
+ if (existingSystemMessageIndex !== -1) {
42
+ // Append context to existing system message content
43
+ const existingContent = messages[existingSystemMessageIndex].content || '';
44
+ messages[existingSystemMessageIndex] = {
45
+ ...messages[existingSystemMessageIndex],
46
+ content: existingContent + '\n\n' + contextMessage.content
38
47
  };
39
- contextParts.push(`Operating System: ${JSON.stringify(osInfo, null, 2)}`);
40
48
  }
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
- }
49
+ else {
50
+ // Add system message to the top of the array
51
+ messages.unshift(contextMessage);
50
52
  }
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;
53
+ // Return new ProcessedMessage object
54
+ return {
55
+ message: {
56
+ ...createdMessage.message,
57
+ messages
58
+ },
59
+ metadata: {
60
+ ...createdMessage.metadata
61
+ }
62
+ };
72
63
  }
64
+ return createdMessage;
73
65
  }
74
66
  }
75
67
  exports.BaseContextMessageModifier = BaseContextMessageModifier;
@@ -1,11 +1,9 @@
1
- import { BaseMessageModifier, MessageModifierInput, ProcessedMessage } from '../../processor';
2
- export interface BaseSystemInstructionMessageModifierOptions {
3
- systemInstruction?: string;
4
- position?: 'start' | 'end';
5
- }
1
+ import { ProcessedMessage } from "@codebolt/types/agent";
2
+ import { BaseMessageModifier } from "../base";
3
+ import { FlatUserMessage } from "@codebolt/types/sdk";
6
4
  export declare class BaseSystemInstructionMessageModifier extends BaseMessageModifier {
7
5
  private readonly systemInstruction;
8
- private readonly position;
9
- constructor(options?: BaseSystemInstructionMessageModifierOptions);
10
- modify(input: MessageModifierInput): Promise<ProcessedMessage>;
6
+ constructor(systemInstruction?: string);
7
+ modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
8
+ private getCoreSystemPrompt;
11
9
  }
@@ -1,39 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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';
4
+ const base_1 = require("../base");
5
+ class BaseSystemInstructionMessageModifier extends base_1.BaseMessageModifier {
6
+ constructor(systemInstruction) {
7
+ super();
8
+ this.systemInstruction = systemInstruction || this.getCoreSystemPrompt();
10
9
  }
11
- async modify(input) {
10
+ async modify(originalRequest, createdMessage) {
12
11
  try {
13
- const { originalRequest, createdMessage, context } = input;
14
12
  // Create system instruction message
15
13
  const systemMessage = {
16
14
  role: 'system',
17
- content: this.systemInstruction,
18
- name: 'system-instruction'
15
+ content: this.systemInstruction
19
16
  };
20
- let messages;
21
- if (this.position === 'start') {
22
- // Add system instruction at the beginning
23
- messages = [systemMessage, ...createdMessage.messages];
17
+ // Get existing messages
18
+ const messages = [...(createdMessage.message.messages || [])];
19
+ // Check if system message already exists
20
+ const existingSystemIndex = messages.findIndex(msg => msg.role === 'system');
21
+ if (existingSystemIndex !== -1) {
22
+ // Update existing system message
23
+ messages[existingSystemIndex] = systemMessage;
24
24
  }
25
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];
26
+ // Add system message to first position
27
+ messages.unshift(systemMessage);
30
28
  }
29
+ // Return new ProcessedMessage object
31
30
  return {
32
- messages,
31
+ message: {
32
+ ...createdMessage.message,
33
+ messages
34
+ },
33
35
  metadata: {
34
- ...createdMessage.metadata,
35
- systemInstructionAdded: true,
36
- systemInstructionPosition: this.position
36
+ ...createdMessage.metadata
37
37
  }
38
38
  };
39
39
  }
@@ -42,5 +42,49 @@ class BaseSystemInstructionMessageModifier extends processor_1.BaseMessageModifi
42
42
  throw error;
43
43
  }
44
44
  }
45
+ getCoreSystemPrompt() {
46
+ // Default system prompt similar to gemini-cli but simplified for CodeBolt context
47
+ const basePrompt = `
48
+ You are an interactive AI agent specializing in software engineering tasks. Your primary goal is to help users safely and efficiently, adhering strictly to the following instructions and utilizing your available tools.
49
+
50
+ # Core Mandates
51
+
52
+ - **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
53
+ - **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project before employing it.
54
+ - **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
55
+ - **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
56
+ - **Comments:** Add code comments sparingly. Focus on *why* something is done, especially for complex logic, rather than *what* is done.
57
+ - **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
58
+ - **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user.
59
+ - **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked.
60
+
61
+ # Primary Workflows
62
+
63
+ ## Software Engineering Tasks
64
+ When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
65
+ 1. **Understand:** Think about the user's request and the relevant codebase context. Use search tools extensively to understand file structures, existing code patterns, and conventions.
66
+ 2. **Plan:** Build a coherent and grounded plan for how you intend to resolve the user's task. Share a concise yet clear plan with the user if it would help.
67
+ 3. **Implement:** Use the available tools to act on the plan, strictly adhering to the project's established conventions.
68
+ 4. **Verify:** If applicable and feasible, verify the changes using the project's testing procedures and build/lint commands.
69
+
70
+ # Operational Guidelines
71
+
72
+ ## Tone and Style
73
+ - **Concise & Direct:** Adopt a professional, direct, and concise tone.
74
+ - **Minimal Output:** Aim for fewer than 3 lines of text output per response whenever practical.
75
+ - **Clarity over Brevity:** While conciseness is key, prioritize clarity for essential explanations.
76
+ - **No Chitchat:** Avoid conversational filler. Get straight to the action or answer.
77
+ - **Formatting:** Use GitHub-flavored Markdown.
78
+
79
+ ## Security and Safety Rules
80
+ - **Security First:** Always apply security best practices. Never introduce code that exposes, logs, or commits secrets, API keys, or other sensitive information.
81
+ - **File Operations:** Always use absolute paths when referring to files with tools.
82
+
83
+ # Final Reminder
84
+ Your core function is efficient and safe assistance. Balance extreme conciseness with the crucial need for clarity, especially regarding safety and potential system modifications. Always prioritize user control and project conventions.
85
+ Do not ask for more information than necessary. Use the tools provided to accomplish the user's request efficiently and effectively. When you've completed your task, you must use the attempt_completion tool to present the result to the user. The user may provide feedback, which you can use to make improvements and try again.
86
+ `.trim();
87
+ return basePrompt;
88
+ }
45
89
  }
46
90
  exports.BaseSystemInstructionMessageModifier = BaseSystemInstructionMessageModifier;
@@ -0,0 +1,19 @@
1
+ import { ProcessedMessage } from "@codebolt/types/agent";
2
+ import { BaseMessageModifier } from "../base";
3
+ import { FlatUserMessage } from "@codebolt/types/sdk";
4
+ export interface ChatCompressionOptions {
5
+ tokenThreshold?: number;
6
+ compressionRatio?: number;
7
+ preserveRecentMessages?: number;
8
+ enableCompression?: boolean;
9
+ }
10
+ export declare class ChatCompressionModifier extends BaseMessageModifier {
11
+ private readonly options;
12
+ private hasFailedCompressionAttempt;
13
+ constructor(options?: ChatCompressionOptions);
14
+ modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
15
+ private shouldCompressChat;
16
+ private compressMessages;
17
+ private createConversationSummary;
18
+ resetCompressionState(): void;
19
+ }