@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.
Files changed (52) 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/types/libFunctionTypes.d.ts +13 -19
  31. package/dist/types/libFunctionTypes.js +3 -0
  32. package/dist/types/processorTypes.d.ts +8 -8
  33. package/dist/types/processorTypes.js +6 -23
  34. package/dist/unified/agent/agent.js +1 -2
  35. package/dist/unified/agent/codeboltAgent.d.ts +23 -2
  36. package/dist/unified/agent/codeboltAgent.js +55 -12
  37. package/dist/unified/agent/tools.d.ts +7 -11
  38. package/dist/unified/agent/tools.js +12 -3
  39. package/dist/unified/agent/workflow.js +38 -20
  40. package/dist/unified/agent/workflowSteps.d.ts +1 -1
  41. package/dist/unified/agent/workflowSteps.js +58 -23
  42. package/dist/unified/base/agentStep.js +20 -1
  43. package/dist/unified/base/initialPromptGenerator.js +3 -1
  44. package/dist/unified/base/responseExecutor.d.ts +3 -0
  45. package/dist/unified/base/responseExecutor.js +41 -10
  46. package/dist/unified/index.d.ts +1 -0
  47. package/dist/unified/index.js +4 -1
  48. package/dist/unified/services/LoopDetectionService.d.ts +44 -0
  49. package/dist/unified/services/LoopDetectionService.js +79 -0
  50. package/dist/unified/utils/utils.d.ts +20 -1
  51. package/dist/unified/utils/utils.js +8 -4
  52. package/package.json +11 -6
@@ -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
  }