@codebolt/agent 5.0.2 → 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
@@ -1,20 +0,0 @@
1
- /**
2
- * Example usage of ChatHistoryMessageModifier
3
- *
4
- * This file demonstrates how to integrate chat history into your agent's message processing pipeline.
5
- */
6
- import { InitialPromptGenerator } from '@codebolt/agent/unified';
7
- import { FlatUserMessage } from '@codebolt/types/sdk';
8
- export declare function createBasicChatHistoryAgent(): InitialPromptGenerator;
9
- export declare function createCompactChatHistoryAgent(): InitialPromptGenerator;
10
- export declare function createThreadAwareChatHistoryAgent(): InitialPromptGenerator;
11
- export declare function processMessageWithHistory(userMessage: FlatUserMessage): Promise<import("@codebolt/types/agent").ProcessedMessage>;
12
- export declare const chatHistoryOptions: {
13
- enableChatHistory: boolean;
14
- maxHistoryMessages: number;
15
- includeSystemMessages: boolean;
16
- historyContextLabel: string;
17
- filterByThreadId: boolean;
18
- includeTimestamps: boolean;
19
- compactFormat: boolean;
20
- };
@@ -1,124 +0,0 @@
1
- "use strict";
2
- /**
3
- * Example usage of ChatHistoryMessageModifier
4
- *
5
- * This file demonstrates how to integrate chat history into your agent's message processing pipeline.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.chatHistoryOptions = void 0;
9
- exports.createBasicChatHistoryAgent = createBasicChatHistoryAgent;
10
- exports.createCompactChatHistoryAgent = createCompactChatHistoryAgent;
11
- exports.createThreadAwareChatHistoryAgent = createThreadAwareChatHistoryAgent;
12
- exports.processMessageWithHistory = processMessageWithHistory;
13
- const chatHistoryMessageModifier_1 = require("./chatHistoryMessageModifier");
14
- const unified_1 = require("@codebolt/agent/unified");
15
- // Example 1: Basic chat history integration
16
- function createBasicChatHistoryAgent() {
17
- return new unified_1.InitialPromptGenerator({
18
- processors: [
19
- // Add chat history before other processors
20
- new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
21
- enableChatHistory: true,
22
- maxHistoryMessages: 5,
23
- includeTimestamps: true,
24
- compactFormat: false
25
- }),
26
- // ... other processors like system prompts, tools, etc.
27
- ],
28
- baseSystemPrompt: "You are a helpful assistant."
29
- });
30
- }
31
- // Example 2: Compact chat history for token efficiency
32
- function createCompactChatHistoryAgent() {
33
- return new unified_1.InitialPromptGenerator({
34
- processors: [
35
- new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
36
- enableChatHistory: true,
37
- maxHistoryMessages: 10,
38
- includeTimestamps: false,
39
- compactFormat: true,
40
- includeSystemMessages: false,
41
- historyContextLabel: "Previous Conversation"
42
- }),
43
- ],
44
- baseSystemPrompt: "You are a helpful assistant."
45
- });
46
- }
47
- // Example 3: Thread-specific chat history (when API supports it)
48
- function createThreadAwareChatHistoryAgent() {
49
- return new unified_1.InitialPromptGenerator({
50
- processors: [
51
- new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
52
- enableChatHistory: true,
53
- maxHistoryMessages: 8,
54
- filterByThreadId: true, // Filter by thread ID when supported
55
- includeTimestamps: true,
56
- compactFormat: false,
57
- historyContextLabel: "Thread History"
58
- }),
59
- ],
60
- baseSystemPrompt: "You are a helpful assistant."
61
- });
62
- }
63
- // Example 4: Usage in a real agent scenario
64
- async function processMessageWithHistory(userMessage) {
65
- const promptGenerator = new unified_1.InitialPromptGenerator({
66
- processors: [
67
- // Chat history comes first to provide context
68
- new chatHistoryMessageModifier_1.ChatHistoryMessageModifier({
69
- enableChatHistory: true,
70
- maxHistoryMessages: 5,
71
- includeTimestamps: false,
72
- compactFormat: true
73
- }),
74
- // Add other processors after history
75
- // new EnvironmentContextModifier(),
76
- // new CoreSystemPromptModifier({ systemPrompt: "..." }),
77
- // new ToolInjectionModifier(),
78
- ],
79
- baseSystemPrompt: "You are a helpful AI assistant."
80
- });
81
- try {
82
- const processedMessage = await promptGenerator.processMessage(userMessage);
83
- console.log('Message processed with chat history context');
84
- return processedMessage;
85
- }
86
- catch (error) {
87
- console.error('Error processing message with history:', error);
88
- throw error;
89
- }
90
- }
91
- // Example 5: Configuration options explained
92
- exports.chatHistoryOptions = {
93
- // Enable/disable chat history entirely
94
- enableChatHistory: true,
95
- // Maximum number of previous messages to include
96
- maxHistoryMessages: 10,
97
- // Include system messages in history
98
- includeSystemMessages: false,
99
- // Custom label for the history section
100
- historyContextLabel: "Previous Conversation",
101
- // Filter by thread ID (when API supports it)
102
- filterByThreadId: true,
103
- // Include timestamps with messages
104
- includeTimestamps: true,
105
- // Use compact format to save tokens
106
- compactFormat: false
107
- };
108
- // Example output format:
109
- /*
110
- === Chat History ===
111
- Thread ID: 6536c82f-c7d1-4dbd-8e68-c90f7ef5ebc3
112
- Recent 3 messages:
113
-
114
- **User (2025-01-15 10:30:15):**
115
- Can you help me with my React component?
116
-
117
- **Assistant (2025-01-15 10:30:45):**
118
- Of course! I'd be happy to help you with your React component. Could you please share the code or describe what specific issue you're facing?
119
-
120
- **User (2025-01-15 10:31:20):**
121
- I'm having trouble with state management in my component.
122
-
123
- === End Chat History ===
124
- */
@@ -1,41 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- export interface Part {
7
- text: string;
8
- }
9
- export interface EnvironmentContextOptions {
10
- workspaceDirectories: string[];
11
- includeFullContext?: boolean;
12
- maxItems?: number;
13
- ignoredFolders?: Set<string>;
14
- fileIncludePattern?: RegExp;
15
- respectGitIgnore?: boolean;
16
- respectGeminiIgnore?: boolean;
17
- }
18
- export interface FolderStructureOptions {
19
- maxItems?: number;
20
- ignoredFolders?: Set<string>;
21
- fileIncludePattern?: RegExp;
22
- respectGitIgnore?: boolean;
23
- respectGeminiIgnore?: boolean;
24
- }
25
- /**
26
- * Standalone version of getFolderStructure
27
- */
28
- export declare function getFolderStructure(targetPath: string, options?: FolderStructureOptions): Promise<string>;
29
- /**
30
- * Standalone version of getDirectoryContextString
31
- */
32
- export declare function getDirectoryContextString(workspaceDirectories: string[], options?: FolderStructureOptions): Promise<string>;
33
- /**
34
- * Standalone version of getEnvironmentContext
35
- */
36
- export declare function getEnvironmentContext(options: EnvironmentContextOptions): Promise<Part[]>;
37
- /**
38
- * Utility function to read multiple files (basic implementation for full context)
39
- * This is a simplified version - extend as needed for your use case
40
- */
41
- export declare function readMultipleFiles(basePath: string, patterns?: string[], options?: FolderStructureOptions): Promise<string>;
@@ -1,355 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright 2025 Google LLC
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.getFolderStructure = getFolderStructure;
42
- exports.getDirectoryContextString = getDirectoryContextString;
43
- exports.getEnvironmentContext = getEnvironmentContext;
44
- exports.readMultipleFiles = readMultipleFiles;
45
- const fs = __importStar(require("fs/promises"));
46
- const path = __importStar(require("path"));
47
- const MAX_ITEMS = 200;
48
- const DEFAULT_IGNORED_FOLDERS = new Set(['node_modules', '.git', 'dist']);
49
- /**
50
- * Simple gitignore pattern matcher (basic implementation)
51
- * For production use, consider using a dedicated gitignore library
52
- */
53
- function shouldIgnoreFile(filePath, options) {
54
- if (!options.respectGitIgnore && !options.respectGeminiIgnore) {
55
- return false;
56
- }
57
- // Basic ignore patterns - in production, you'd want to read actual .gitignore/.geminiignore files
58
- const commonIgnorePatterns = [
59
- /node_modules/,
60
- /\.git/,
61
- /dist/,
62
- /build/,
63
- /\.DS_Store/,
64
- /\.env/,
65
- /\.log$/,
66
- /\.tmp$/,
67
- /\.cache/
68
- ];
69
- return commonIgnorePatterns.some(pattern => pattern.test(filePath));
70
- }
71
- /**
72
- * Reads the full folder structure recursively
73
- */
74
- async function readFullStructure(rootPath, options) {
75
- const rootName = path.basename(rootPath);
76
- const rootNode = {
77
- name: rootName,
78
- path: rootPath,
79
- files: [],
80
- subFolders: [],
81
- totalChildren: 0,
82
- totalFiles: 0,
83
- };
84
- const queue = [
85
- { folderInfo: rootNode, currentPath: rootPath },
86
- ];
87
- let currentItemCount = 0;
88
- const processedPaths = new Set();
89
- while (queue.length > 0) {
90
- const { folderInfo, currentPath } = queue.shift();
91
- if (processedPaths.has(currentPath)) {
92
- continue;
93
- }
94
- processedPaths.add(currentPath);
95
- if (currentItemCount >= options.maxItems) {
96
- continue;
97
- }
98
- let entries;
99
- try {
100
- const rawEntries = await fs.readdir(currentPath, { withFileTypes: true });
101
- entries = rawEntries.sort((a, b) => a.name.localeCompare(b.name));
102
- }
103
- catch (error) {
104
- if (error.code === 'EACCES' || error.code === 'ENOENT') {
105
- console.warn(`Warning: Could not read directory ${currentPath}: ${error.message}`);
106
- if (currentPath === rootPath && error.code === 'ENOENT') {
107
- return null;
108
- }
109
- continue;
110
- }
111
- throw error;
112
- }
113
- const filesInCurrentDir = [];
114
- const subFoldersInCurrentDir = [];
115
- // Process files first
116
- for (const entry of entries) {
117
- if (entry.isFile()) {
118
- if (currentItemCount >= options.maxItems) {
119
- folderInfo.hasMoreFiles = true;
120
- break;
121
- }
122
- const fileName = entry.name;
123
- const filePath = path.join(currentPath, fileName);
124
- if (shouldIgnoreFile(filePath, options)) {
125
- continue;
126
- }
127
- if (!options.fileIncludePattern || options.fileIncludePattern.test(fileName)) {
128
- filesInCurrentDir.push(fileName);
129
- currentItemCount++;
130
- folderInfo.totalFiles++;
131
- folderInfo.totalChildren++;
132
- }
133
- }
134
- }
135
- folderInfo.files = filesInCurrentDir;
136
- // Process directories
137
- for (const entry of entries) {
138
- if (entry.isDirectory()) {
139
- if (currentItemCount >= options.maxItems) {
140
- folderInfo.hasMoreSubfolders = true;
141
- break;
142
- }
143
- const subFolderName = entry.name;
144
- const subFolderPath = path.join(currentPath, subFolderName);
145
- if (options.ignoredFolders.has(subFolderName) || shouldIgnoreFile(subFolderPath, options)) {
146
- const ignoredSubFolder = {
147
- name: subFolderName,
148
- path: subFolderPath,
149
- files: [],
150
- subFolders: [],
151
- totalChildren: 0,
152
- totalFiles: 0,
153
- isIgnored: true,
154
- };
155
- subFoldersInCurrentDir.push(ignoredSubFolder);
156
- currentItemCount++;
157
- folderInfo.totalChildren++;
158
- continue;
159
- }
160
- const subFolderNode = {
161
- name: subFolderName,
162
- path: subFolderPath,
163
- files: [],
164
- subFolders: [],
165
- totalChildren: 0,
166
- totalFiles: 0,
167
- };
168
- subFoldersInCurrentDir.push(subFolderNode);
169
- currentItemCount++;
170
- folderInfo.totalChildren++;
171
- queue.push({ folderInfo: subFolderNode, currentPath: subFolderPath });
172
- }
173
- }
174
- folderInfo.subFolders = subFoldersInCurrentDir;
175
- }
176
- return rootNode;
177
- }
178
- /**
179
- * Formats a folder structure into a readable string representation
180
- */
181
- function formatFolderStructure(folderInfo, prefix = '', isLast = true) {
182
- const connector = isLast ? '└── ' : '├── ';
183
- const extension = isLast ? ' ' : '│ ';
184
- let result = `${prefix}${connector}${folderInfo.name}`;
185
- if (folderInfo.isIgnored) {
186
- result += ' (ignored)';
187
- }
188
- result += '\n';
189
- // Add files
190
- const allFiles = [...folderInfo.files];
191
- if (folderInfo.hasMoreFiles) {
192
- allFiles.push('...');
193
- }
194
- allFiles.forEach((file, index) => {
195
- const isLastFile = index === allFiles.length - 1 && folderInfo.subFolders.length === 0;
196
- const fileConnector = isLastFile ? '└── ' : '├── ';
197
- result += `${prefix}${extension}${fileConnector}${file}\n`;
198
- });
199
- // Add subfolders
200
- folderInfo.subFolders.forEach((subFolder, index) => {
201
- const isLastSubFolder = index === folderInfo.subFolders.length - 1;
202
- result += formatFolderStructure(subFolder, prefix + extension, isLastSubFolder);
203
- });
204
- if (folderInfo.hasMoreSubfolders) {
205
- const moreConnector = '└── ';
206
- result += `${prefix}${extension}${moreConnector}...\n`;
207
- }
208
- return result;
209
- }
210
- /**
211
- * Standalone version of getFolderStructure
212
- */
213
- async function getFolderStructure(targetPath, options = {}) {
214
- var _a, _b, _c, _d, _e;
215
- const mergedOptions = {
216
- maxItems: (_a = options.maxItems) !== null && _a !== void 0 ? _a : MAX_ITEMS,
217
- ignoredFolders: (_b = options.ignoredFolders) !== null && _b !== void 0 ? _b : DEFAULT_IGNORED_FOLDERS,
218
- fileIncludePattern: (_c = options.fileIncludePattern) !== null && _c !== void 0 ? _c : /.*/,
219
- respectGitIgnore: (_d = options.respectGitIgnore) !== null && _d !== void 0 ? _d : true,
220
- respectGeminiIgnore: (_e = options.respectGeminiIgnore) !== null && _e !== void 0 ? _e : true,
221
- };
222
- try {
223
- const folderInfo = await readFullStructure(targetPath, mergedOptions);
224
- if (!folderInfo) {
225
- return `Error: Directory not found or inaccessible: ${targetPath}`;
226
- }
227
- return formatFolderStructure(folderInfo).trim();
228
- }
229
- catch (error) {
230
- return `Error reading folder structure: ${error.message}`;
231
- }
232
- }
233
- /**
234
- * Standalone version of getDirectoryContextString
235
- */
236
- async function getDirectoryContextString(workspaceDirectories, options = {}) {
237
- const folderStructures = await Promise.all(workspaceDirectories.map((dir) => getFolderStructure(dir, options)));
238
- const folderStructure = folderStructures.join('\n');
239
- let workingDirPreamble;
240
- if (workspaceDirectories.length === 1) {
241
- workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
242
- }
243
- else {
244
- const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
245
- workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
246
- }
247
- return `${workingDirPreamble}
248
- Here is the folder structure of the current working directories:
249
-
250
- ${folderStructure}`;
251
- }
252
- /**
253
- * Standalone version of getEnvironmentContext
254
- */
255
- async function getEnvironmentContext(options) {
256
- const today = new Date().toLocaleDateString(undefined, {
257
- weekday: 'long',
258
- year: 'numeric',
259
- month: 'long',
260
- day: 'numeric',
261
- });
262
- const platform = process.platform;
263
- const directoryContext = await getDirectoryContextString(options.workspaceDirectories, {
264
- maxItems: options.maxItems,
265
- ignoredFolders: options.ignoredFolders,
266
- fileIncludePattern: options.fileIncludePattern,
267
- respectGitIgnore: options.respectGitIgnore,
268
- respectGeminiIgnore: options.respectGeminiIgnore,
269
- });
270
- const context = `
271
- This is the Gemini CLI. We are setting up the context for our chat.
272
- Today's date is ${today}.
273
- My operating system is: ${platform}
274
- ${directoryContext}
275
- `.trim();
276
- const initialParts = [{ text: context }];
277
- // Add full file context if requested
278
- if (options.includeFullContext) {
279
- try {
280
- // This is a simplified version - in the original, this would use read_many_files tool
281
- // For standalone use, you might want to implement your own file reading logic
282
- const fullContextNote = `
283
- --- Full File Context (Standalone Version) ---
284
- Note: Full file context reading would require implementing file reading logic
285
- based on your specific needs. The original implementation uses the read_many_files tool
286
- from the Gemini CLI tool registry.
287
- `;
288
- initialParts.push({ text: fullContextNote });
289
- }
290
- catch (error) {
291
- console.error('Error reading full file context:', error);
292
- initialParts.push({
293
- text: '\n--- Error reading full file context ---',
294
- });
295
- }
296
- }
297
- return initialParts;
298
- }
299
- /**
300
- * Utility function to read multiple files (basic implementation for full context)
301
- * This is a simplified version - extend as needed for your use case
302
- */
303
- async function readMultipleFiles(basePath, patterns = ['**/*'], options = {}) {
304
- // This is a basic implementation - for production use, consider using a glob library
305
- // like 'glob' or 'fast-glob' for pattern matching
306
- try {
307
- const files = [];
308
- async function collectFiles(dirPath, currentDepth = 0) {
309
- var _a;
310
- if (currentDepth > 10)
311
- return; // Prevent infinite recursion
312
- try {
313
- const entries = await fs.readdir(dirPath, { withFileTypes: true });
314
- for (const entry of entries) {
315
- const fullPath = path.join(dirPath, entry.name);
316
- if (shouldIgnoreFile(fullPath, options)) {
317
- continue;
318
- }
319
- if (entry.isFile()) {
320
- files.push(fullPath);
321
- }
322
- else if (entry.isDirectory() && !((_a = options.ignoredFolders) === null || _a === void 0 ? void 0 : _a.has(entry.name))) {
323
- await collectFiles(fullPath, currentDepth + 1);
324
- }
325
- }
326
- }
327
- catch (error) {
328
- // Skip directories we can't read
329
- console.warn(`Warning: Could not read directory ${dirPath}: ${error.message}`);
330
- }
331
- }
332
- await collectFiles(basePath);
333
- // Read file contents (limit to reasonable size)
334
- const fileContents = [];
335
- for (const filePath of files.slice(0, 100)) { // Limit to first 100 files
336
- try {
337
- const stats = await fs.stat(filePath);
338
- if (stats.size > 100 * 1024) { // Skip files larger than 100KB
339
- fileContents.push(`${filePath}: [File too large, skipped]`);
340
- continue;
341
- }
342
- const content = await fs.readFile(filePath, 'utf-8');
343
- const relativePath = path.relative(basePath, filePath);
344
- fileContents.push(`--- ${relativePath} ---\n${content}\n`);
345
- }
346
- catch (error) {
347
- fileContents.push(`${filePath}: [Error reading file: ${error.message}]`);
348
- }
349
- }
350
- return fileContents.join('\n');
351
- }
352
- catch (error) {
353
- return `Error reading multiple files: ${error.message}`;
354
- }
355
- }
@@ -1,23 +0,0 @@
1
- import { ProcessedMessage } from "@codebolt/types/agent";
2
- import { BaseMessageModifier } from "../base";
3
- import { FlatUserMessage } from "@codebolt/types/sdk";
4
- /**
5
- * Message modifier that reads files and folders mentioned in the user message
6
- * Uses mentionedFiles and mentionedFolders from FlatUserMessage
7
- */
8
- export declare class MentionedFilesModifier extends BaseMessageModifier {
9
- constructor();
10
- modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
11
- /**
12
- * Resolves and reads a file, handling both files and directories
13
- */
14
- private resolveAndReadFile;
15
- /**
16
- * Formats file content for inclusion in the message
17
- */
18
- private formatFileContent;
19
- /**
20
- * Updates the user message with file content
21
- */
22
- private updateUserMessage;
23
- }