@codebolt/agent 5.0.7 → 5.0.9

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/processor-pieces/base/basePreToolCallProcessor.js +5 -2
  2. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.d.ts +1 -1
  3. package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +2 -2
  4. package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +24 -34
  5. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.d.ts +1 -1
  6. package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +2 -2
  7. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.d.ts +1 -1
  8. package/dist/processor-pieces/messageModifiers/coreSystemPromptModifier.js +2 -2
  9. package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -1
  10. package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +8 -3
  11. package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -1
  12. package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +1 -1
  13. package/dist/processor-pieces/messageModifiers/ideContextModifier.js +114 -17
  14. package/dist/processor-pieces/messageModifiers/memoryImportModifier.d.ts +1 -1
  15. package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +13 -5
  16. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.d.ts +5 -0
  17. package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -0
  18. package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +24 -8
  19. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +202 -5
  20. package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +826 -19
  21. package/dist/processor-pieces/postToolCallProcessors/index.d.ts +1 -1
  22. package/dist/processor-pieces/postToolCallProcessors/index.js +2 -1
  23. package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +7 -4
  24. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.d.ts +1 -1
  25. package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +12 -16
  26. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +2 -3
  27. package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +1 -2
  28. package/dist/processor-pieces/utils/messageModifierHelper.js +5 -2
  29. package/dist/types/InternalTypes.d.ts +8 -6
  30. package/dist/unified/agent/agent.js +1 -2
  31. package/dist/unified/agent/codeboltAgent.d.ts +23 -2
  32. package/dist/unified/agent/codeboltAgent.js +55 -12
  33. package/dist/unified/agent/tools.d.ts +7 -11
  34. package/dist/unified/agent/tools.js +12 -3
  35. package/dist/unified/agent/workflow.js +38 -20
  36. package/dist/unified/agent/workflowSteps.d.ts +1 -1
  37. package/dist/unified/agent/workflowSteps.js +58 -23
  38. package/dist/unified/base/agentStep.js +20 -1
  39. package/dist/unified/base/initialPromptGenerator.js +3 -1
  40. package/dist/unified/base/responseExecutor.d.ts +3 -0
  41. package/dist/unified/base/responseExecutor.js +47 -21
  42. package/dist/unified/index.d.ts +1 -0
  43. package/dist/unified/index.js +4 -1
  44. package/dist/unified/services/LoopDetectionService.d.ts +44 -0
  45. package/dist/unified/services/LoopDetectionService.js +79 -0
  46. package/dist/unified/utils/utils.d.ts +20 -1
  47. package/dist/unified/utils/utils.js +8 -4
  48. package/package.json +5 -5
  49. package/dist/agent.d.ts +0 -86
  50. package/dist/agent.js +0 -324
  51. package/dist/builderpattern/agent.d.ts +0 -86
  52. package/dist/builderpattern/agent.js +0 -324
  53. package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
  54. package/dist/builderpattern/followupquestionbuilder.js +0 -197
  55. package/dist/builderpattern/index.d.ts +0 -14
  56. package/dist/builderpattern/index.js +0 -23
  57. package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
  58. package/dist/builderpattern/llmoutputhandler.js +0 -452
  59. package/dist/builderpattern/promptbuilder.d.ts +0 -382
  60. package/dist/builderpattern/promptbuilder.js +0 -805
  61. package/dist/builderpattern/systemprompt.d.ts +0 -20
  62. package/dist/builderpattern/systemprompt.js +0 -48
  63. package/dist/builderpattern/taskInstruction.d.ts +0 -37
  64. package/dist/builderpattern/taskInstruction.js +0 -57
  65. package/dist/builderpattern/usermessage.d.ts +0 -70
  66. package/dist/builderpattern/usermessage.js +0 -123
  67. package/dist/composablepattern/agent.d.ts +0 -169
  68. package/dist/composablepattern/agent.js +0 -598
  69. package/dist/composablepattern/codebolt-storage.d.ts +0 -67
  70. package/dist/composablepattern/codebolt-storage.js +0 -320
  71. package/dist/composablepattern/document.d.ts +0 -149
  72. package/dist/composablepattern/document.js +0 -405
  73. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
  74. package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
  75. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
  76. package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
  77. package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
  78. package/dist/composablepattern/examples/custom-steps-example.js +0 -455
  79. package/dist/composablepattern/examples/document-agent.d.ts +0 -17
  80. package/dist/composablepattern/examples/document-agent.js +0 -107
  81. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
  82. package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
  83. package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
  84. package/dist/composablepattern/examples/weather-agent.js +0 -86
  85. package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
  86. package/dist/composablepattern/examples/workflow-example.js +0 -463
  87. package/dist/composablepattern/index.d.ts +0 -63
  88. package/dist/composablepattern/index.js +0 -115
  89. package/dist/composablepattern/memory.d.ts +0 -89
  90. package/dist/composablepattern/memory.js +0 -141
  91. package/dist/composablepattern/tool.d.ts +0 -84
  92. package/dist/composablepattern/tool.js +0 -260
  93. package/dist/composablepattern/types.d.ts +0 -194
  94. package/dist/composablepattern/types.js +0 -6
  95. package/dist/composablepattern/user-context.d.ts +0 -214
  96. package/dist/composablepattern/user-context.js +0 -275
  97. package/dist/composablepattern/workflow.d.ts +0 -388
  98. package/dist/composablepattern/workflow.js +0 -562
  99. package/dist/followupquestionbuilder.d.ts +0 -75
  100. package/dist/followupquestionbuilder.js +0 -197
  101. package/dist/index.d.ts +0 -14
  102. package/dist/index.js +0 -23
  103. package/dist/llmoutputhandler.d.ts +0 -102
  104. package/dist/llmoutputhandler.js +0 -452
  105. package/dist/processor/agent/agentStep.d.ts +0 -49
  106. package/dist/processor/agent/agentStep.js +0 -241
  107. package/dist/processor/agent/toolExecutor.d.ts +0 -19
  108. package/dist/processor/agent/toolExecutor.js +0 -90
  109. package/dist/processor/index.d.ts +0 -7
  110. package/dist/processor/index.js +0 -36
  111. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
  112. package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
  113. package/dist/processor/processors/baseProcessor.d.ts +0 -14
  114. package/dist/processor/processors/baseProcessor.js +0 -29
  115. package/dist/processor/tools/baseTool.d.ts +0 -10
  116. package/dist/processor/tools/baseTool.js +0 -20
  117. package/dist/processor/tools/toolList.d.ts +0 -9
  118. package/dist/processor/tools/toolList.js +0 -22
  119. package/dist/processor/types/interfaces.d.ts +0 -94
  120. package/dist/processor/types/interfaces.js +0 -2
  121. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
  122. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
  123. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
  124. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
  125. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
  126. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
  127. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
  128. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
  129. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
  130. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
  131. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
  132. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
  133. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
  134. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
  135. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
  136. package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
  137. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
  138. package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
  139. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
  140. package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
  141. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
  142. package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
  143. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
  144. package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
  145. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
  146. package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
  147. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
  148. package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
  149. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
  150. package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
  151. package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
  152. package/dist/processor-pieces/tools/fileTools.js +0 -162
  153. package/dist/promptbuilder.d.ts +0 -382
  154. package/dist/promptbuilder.js +0 -805
  155. package/dist/systemprompt.d.ts +0 -20
  156. package/dist/systemprompt.js +0 -48
  157. package/dist/taskInstruction.d.ts +0 -37
  158. package/dist/taskInstruction.js +0 -57
  159. package/dist/usermessage.d.ts +0 -70
  160. package/dist/usermessage.js +0 -123
@@ -1,18 +1,215 @@
1
1
  /**
2
2
  * Conversation Compactor Modifier
3
3
  * Post-Tool Call processor for compacting conversation history to reduce context size
4
+ *
5
+ * Inspired by gemini-cli's ChatCompressionService approach:
6
+ * - Truncates large tool outputs
7
+ * - Summarizes old conversation history using LLM
8
+ * - Preserves recent context for continuity
4
9
  */
5
10
  import { BasePostToolCallProcessor } from '../base/basePostToolCallProcessor';
6
11
  import { PostToolCallProcessorInput, PostToolCallProcessorOutput } from '@codebolt/types/agent';
12
+ import { MessageObject } from '@codebolt/types/sdk';
13
+ /**
14
+ * Compression Status Enum - tracks the result of compression attempts
15
+ */
16
+ export declare enum CompressionStatus {
17
+ /** Compression was successful */
18
+ COMPRESSED = "COMPRESSED",
19
+ /** Compression not needed - under threshold */
20
+ NOOP = "NOOP",
21
+ /** Compression failed - summary larger than original */
22
+ FAILED_INFLATED_TOKEN_COUNT = "FAILED_INFLATED_TOKEN_COUNT",
23
+ /** Compression failed - token counting error */
24
+ FAILED_TOKEN_COUNT_ERROR = "FAILED_TOKEN_COUNT_ERROR",
25
+ /** Compression failed - LLM summarization error */
26
+ FAILED_SUMMARIZATION_ERROR = "FAILED_SUMMARIZATION_ERROR",
27
+ /** Tool output truncation was applied (without full compression) */
28
+ TOOL_OUTPUT_TRUNCATED = "TOOL_OUTPUT_TRUNCATED"
29
+ }
30
+ /**
31
+ * Compression metadata - tracks compression state and statistics
32
+ */
33
+ export interface CompressionMetadata {
34
+ /** Status of the compression attempt */
35
+ status: CompressionStatus;
36
+ /** Original token count before compression */
37
+ originalTokenCount: number;
38
+ /** Token count after compression */
39
+ newTokenCount: number;
40
+ /** Number of messages that were compressed/removed */
41
+ messagesCompressed: number;
42
+ /** Number of messages preserved */
43
+ messagesPreserved: number;
44
+ /** Whether tool outputs were truncated */
45
+ toolOutputsTruncated: boolean;
46
+ /** Number of failed compression attempts in this session */
47
+ failedAttempts: number;
48
+ /** Timestamp of compression */
49
+ timestamp: string;
50
+ /** Compression strategy used */
51
+ strategy: 'simple' | 'smart' | 'summarize';
52
+ }
53
+ /**
54
+ * Configuration options for ConversationCompactorModifier
55
+ * Based on gemini-cli thresholds with codebolt adaptations
56
+ */
7
57
  export interface ConversationCompactorOptions {
8
- maxMessages?: number;
9
- preserveSystemMessages?: boolean;
10
- preserveLastUserMessages?: number;
11
- preserveLastToolResults?: number;
58
+ /**
59
+ * Token threshold as fraction of model limit (0.0 - 1.0)
60
+ * Compression triggers when tokens exceed this fraction of the limit
61
+ * @default 0.5 (compress at 50% of limit, same as gemini-cli)
62
+ */
63
+ compressionTokenThreshold?: number;
64
+ /**
65
+ * Fraction of recent history to preserve after compression (0.0 - 1.0)
66
+ * @default 0.3 (keep last 30% of history, same as gemini-cli)
67
+ */
68
+ preserveThreshold?: number;
69
+ /**
70
+ * Maximum token budget for tool response content
71
+ * Older tool outputs exceeding this budget will be truncated
72
+ * @default 50000 (same as gemini-cli COMPRESSION_FUNCTION_RESPONSE_TOKEN_BUDGET)
73
+ */
74
+ toolResponseTokenBudget?: number;
75
+ /**
76
+ * Maximum lines to keep when truncating tool outputs
77
+ * @default 30 (same as gemini-cli COMPRESSION_TRUNCATE_LINES)
78
+ */
79
+ truncateLines?: number;
80
+ /**
81
+ * Compression strategy
82
+ * - 'simple': Just truncate old messages
83
+ * - 'smart': Truncate tool outputs + remove old messages intelligently
84
+ * - 'summarize': Use LLM to generate state_snapshot summary
85
+ * @default 'smart'
86
+ */
12
87
  compactStrategy?: 'simple' | 'smart' | 'summarize';
88
+ /**
89
+ * Whether to preserve system messages during compression
90
+ * @default true
91
+ */
92
+ preserveSystemMessages?: boolean;
93
+ /**
94
+ * Minimum number of user messages to always preserve
95
+ * @default 3
96
+ */
97
+ minPreservedUserMessages?: number;
98
+ /**
99
+ * Whether to enable LLM verification pass for summarization
100
+ * Adds a second LLM call to verify summary accuracy
101
+ * @default false (for performance)
102
+ */
103
+ enableVerificationPass?: boolean;
104
+ /**
105
+ * Model token limit (auto-detected if not specified)
106
+ * @default 128000
107
+ */
108
+ modelTokenLimit?: number;
109
+ /**
110
+ * LLM role for summarization calls
111
+ * @default 'summarizer'
112
+ */
113
+ llmRole?: string;
114
+ /**
115
+ * Enable debug logging
116
+ * @default false
117
+ */
118
+ enableLogging?: boolean;
13
119
  }
14
120
  export declare class ConversationCompactorModifier extends BasePostToolCallProcessor {
15
- private options;
121
+ private readonly options;
122
+ private failedCompressionAttempts;
123
+ private hasFailedCompression;
16
124
  constructor(options?: ConversationCompactorOptions);
125
+ /**
126
+ * Estimates token count for a string
127
+ * Uses the ~4 characters per token approximation
128
+ */
129
+ private estimateTokens;
130
+ /**
131
+ * Counts tokens for an array of messages
132
+ */
133
+ private countMessageTokens;
134
+ /**
135
+ * Gets content length from a message (handles string and array content)
136
+ */
137
+ private getMessageContentLength;
138
+ /**
139
+ * Extracts text content from a message
140
+ */
141
+ private getMessageContent;
142
+ /**
143
+ * Checks if a message is a function/tool response
144
+ */
145
+ private isToolResponseMessage;
146
+ /**
147
+ * Truncates content to a specified number of lines
148
+ * Keeps first half and last half of allowed lines for context
149
+ */
150
+ private truncateToLines;
151
+ /**
152
+ * Truncates large tool output messages to reduce token count
153
+ * Iterates backwards (prioritizing recent messages) following gemini-cli approach
154
+ */
155
+ private truncateLargeToolOutputs;
156
+ /**
157
+ * Adjusts split index to the start of the next turn (user message)
158
+ * Ensures we don't split in the middle of a conversation turn
159
+ */
160
+ private adjustToTurnBoundary;
161
+ /**
162
+ * Maps filtered array index back to original messages array
163
+ */
164
+ private mapToOriginalIndex;
165
+ /**
166
+ * Finds the index to split history for compression
167
+ * Returns the index after which messages should be preserved
168
+ */
169
+ private findCompressionSplitIndex;
170
+ /**
171
+ * Generates the compression prompt with state_snapshot XML format
172
+ * Based on gemini-cli's approach
173
+ */
174
+ private getCompressionPrompt;
175
+ /**
176
+ * Generates a state snapshot summary using LLM
177
+ */
178
+ private generateStateSummary;
179
+ /**
180
+ * Optional verification pass - asks LLM to verify and correct the summary
181
+ */
182
+ private verifySummary;
183
+ /**
184
+ * Simple compression strategy - just removes old messages
185
+ */
186
+ private compressSimple;
187
+ /**
188
+ * Smart compression strategy - truncates tool outputs + intelligent message removal
189
+ */
190
+ private compressSmart;
191
+ /**
192
+ * Summarize compression strategy - uses LLM to create state snapshot
193
+ */
194
+ private compressSummarize;
17
195
  modify(input: PostToolCallProcessorInput): Promise<PostToolCallProcessorOutput>;
196
+ /**
197
+ * Resets the compression state (useful for new conversations)
198
+ */
199
+ resetCompressionState(): void;
200
+ /**
201
+ * Gets the current compression statistics
202
+ */
203
+ getCompressionStats(): {
204
+ failedAttempts: number;
205
+ hasFailedCompression: boolean;
206
+ options: Required<ConversationCompactorOptions>;
207
+ };
208
+ /**
209
+ * Forces compression regardless of threshold (for testing or manual trigger)
210
+ */
211
+ forceCompress(messages: MessageObject[]): Promise<{
212
+ messages: MessageObject[];
213
+ metadata: Partial<CompressionMetadata>;
214
+ }>;
18
215
  }