@codebolt/agent 6.1.20 → 6.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +11 -15
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +0 -1
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +16 -33
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +8 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +150 -27
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +3 -3
- package/dist/processor-pieces/messageModifiers/contextAssemblyModifier.js +18 -12
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +15 -15
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +48 -2
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +9 -15
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +17 -20
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.js +57 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +8 -19
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +28 -20
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +3 -3
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +2 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +3 -3
- package/dist/types/libFunctionTypes.d.ts +139 -7
- package/dist/unified/agent/agent.d.ts +13 -0
- package/dist/unified/agent/agent.js +180 -19
- package/dist/unified/agent/tools.d.ts +14 -0
- package/dist/unified/agent/tools.js +82 -51
- package/dist/unified/base/agentStep.d.ts +2 -1
- package/dist/unified/base/agentStep.js +47 -16
- package/dist/unified/base/initialPromptGenerator.d.ts +2 -0
- package/dist/unified/base/initialPromptGenerator.js +42 -19
- package/dist/unified/base/promptContext.d.ts +3 -0
- package/dist/unified/base/promptContext.js +193 -15
- package/dist/unified/base/responseExecutor.d.ts +6 -0
- package/dist/unified/base/responseExecutor.js +256 -69
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +3 -1
- package/dist/unified/services/CompressionCoordinator.js +9 -9
- package/dist/unified/services/compaction/autoCompact.d.ts +2 -1
- package/dist/unified/services/compaction/autoCompact.js +19 -11
- package/dist/unified/services/compaction/compactionOrchestrator.d.ts +1 -0
- package/dist/unified/services/compaction/compactionOrchestrator.js +8 -0
- package/dist/unified/services/compaction/contextCollapse.d.ts +2 -1
- package/dist/unified/services/compaction/contextCollapse.js +17 -9
- package/dist/unified/services/compaction/reactiveCompact.d.ts +3 -0
- package/dist/unified/services/compaction/reactiveCompact.js +17 -8
- package/dist/unified/types/libTypes.d.ts +189 -10
- package/dist/unified/utils/agentToolLoader.d.ts +17 -1
- package/dist/unified/utils/agentToolLoader.js +182 -31
- package/package.json +5 -1
|
@@ -102,6 +102,7 @@ Effective project directory for this task: ${currentDir}
|
|
|
102
102
|
${baseProjectPath ? `CodeBolt base project directory: ${baseProjectPath}
|
|
103
103
|
CodeBolt app-level configuration, providers, plugins, and .codebolt data are loaded from the base project directory. Code changes for the task should still target the effective project directory unless the user explicitly says otherwise.` : ''}
|
|
104
104
|
${directoryListing}
|
|
105
|
+
Async task policy: long-running commands and child threads are tracked as async tasks with execution_mode foreground_scoped, auto_scoped, background_scoped, or background_detached. Scoped tasks are owned by the current agent run and are stopped if the user force-stops the agent. Before completing, use async_task_list to inspect unresolved scoped work and async_task_control to wait, stop, or explicitly detach each running task. background_detached tasks survive user force-stop and natural completion, so detach only intentional background services such as dev servers.
|
|
105
106
|
`.trim();
|
|
106
107
|
// Prepare context parts (same as gemini-cli)
|
|
107
108
|
const contextParts = [environmentContext];
|
|
@@ -119,6 +120,10 @@ ${directoryListing}
|
|
|
119
120
|
if (mentionedEnvironmentContext) {
|
|
120
121
|
contextParts.push(mentionedEnvironmentContext);
|
|
121
122
|
}
|
|
123
|
+
const asyncTaskContext = await this.formatPendingAsyncTasks();
|
|
124
|
+
if (asyncTaskContext) {
|
|
125
|
+
contextParts.push(asyncTaskContext);
|
|
126
|
+
}
|
|
122
127
|
// Add full file context if enabled (just like gemini-cli does)
|
|
123
128
|
if (this.options.enableFullContext) {
|
|
124
129
|
try {
|
|
@@ -137,10 +142,11 @@ ${directoryListing}
|
|
|
137
142
|
role: 'user',
|
|
138
143
|
content: finalContent
|
|
139
144
|
};
|
|
145
|
+
const updatedMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, contextMessage);
|
|
140
146
|
return Promise.resolve({
|
|
141
|
-
...
|
|
147
|
+
...updatedMessage,
|
|
142
148
|
metadata: {
|
|
143
|
-
...
|
|
149
|
+
...updatedMessage.metadata,
|
|
144
150
|
environmentContextAdded: true,
|
|
145
151
|
projectAgentMdContextAdded: Boolean(agentMdContext),
|
|
146
152
|
fullContextAdded: this.options.enableFullContext,
|
|
@@ -187,6 +193,7 @@ ${directoryListing}
|
|
|
187
193
|
'The user explicitly mentioned these environments with #. Treat them as routing context, not as an automatic active-environment selection.',
|
|
188
194
|
'If the user asks to run, start, delegate, create, or continue work in one of these environments, first inspect this mentioned environment list and choose the matching environment.',
|
|
189
195
|
'Use the thread tool `thread_create_background` to create a background thread in the selected remote environment. Pass the selected environment object in `environment`, set `isRemoteTask: true`, and put the requested work in `userMessage` or `task`.',
|
|
196
|
+
'If the next step depends on that child thread finishing, use `async_task_control` with taskId `thread:<threadId>` and action `wait` before continuing.',
|
|
190
197
|
'If `thread_create_background` is not available in the current tool list, first use the tool search capability, such as `tool_search`, to find the thread/background-thread creation tool and then use the matching tool.',
|
|
191
198
|
'If multiple mentioned environments could match and the user did not specify which one, ask a brief clarification before creating the background thread.',
|
|
192
199
|
'Do not call environment management tools or change the active environment just because an environment was mentioned.',
|
|
@@ -194,6 +201,45 @@ ${directoryListing}
|
|
|
194
201
|
'</mentioned-environments>',
|
|
195
202
|
].join('\n');
|
|
196
203
|
}
|
|
204
|
+
async formatPendingAsyncTasks() {
|
|
205
|
+
try {
|
|
206
|
+
const response = await codeboltjs_1.default.asyncTask.listTasks({
|
|
207
|
+
scope: 'thread',
|
|
208
|
+
});
|
|
209
|
+
const tasks = Array.isArray(response === null || response === void 0 ? void 0 : response.tasks) ? response.tasks : [];
|
|
210
|
+
const unresolvedTasks = tasks.filter((task) => task &&
|
|
211
|
+
task.executionMode !== 'background_detached' &&
|
|
212
|
+
!['completed', 'failed', 'stopped'].includes(task.status));
|
|
213
|
+
const detachedTasks = tasks.filter((task) => task &&
|
|
214
|
+
task.executionMode === 'background_detached' &&
|
|
215
|
+
!['completed', 'failed', 'stopped'].includes(task.status));
|
|
216
|
+
if (unresolvedTasks.length === 0 && detachedTasks.length === 0) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const sections = [];
|
|
220
|
+
if (unresolvedTasks.length > 0) {
|
|
221
|
+
sections.push([
|
|
222
|
+
'<pending_async_tasks>',
|
|
223
|
+
'These scoped async tasks are still unresolved for this thread. Before completing, choose wait, stop, or detach for each task using async_task_control. Detach only intentional background services that should survive agent stop.',
|
|
224
|
+
JSON.stringify(unresolvedTasks, null, 2),
|
|
225
|
+
'</pending_async_tasks>',
|
|
226
|
+
].join('\n'));
|
|
227
|
+
}
|
|
228
|
+
if (detachedTasks.length > 0) {
|
|
229
|
+
sections.push([
|
|
230
|
+
'<detached_async_tasks>',
|
|
231
|
+
'These background_detached async tasks are still running in the background for this thread. They do not block completion and survive user force-stop. Stop them with async_task_control if they are no longer needed.',
|
|
232
|
+
JSON.stringify(detachedTasks, null, 2),
|
|
233
|
+
'</detached_async_tasks>',
|
|
234
|
+
].join('\n'));
|
|
235
|
+
}
|
|
236
|
+
return sections.join('\n\n');
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
console.error('Error reading pending async tasks:', error);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
197
243
|
async readProjectAgentMd(basePath, title = 'Project Agent Instructions') {
|
|
198
244
|
const instructionFiles = [
|
|
199
245
|
path.join(basePath, '.codebolt', 'agent.md'),
|
|
@@ -34,10 +34,11 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
34
34
|
this.lastSentIdeContext = newIdeContext;
|
|
35
35
|
}
|
|
36
36
|
this.forceFullContext = false;
|
|
37
|
+
const updatedMessage = (0, promptContext_1.appendSystemContextMessage)(createdMessage, ideContextMessage);
|
|
37
38
|
return Promise.resolve({
|
|
38
|
-
...
|
|
39
|
+
...updatedMessage,
|
|
39
40
|
metadata: {
|
|
40
|
-
...
|
|
41
|
+
...updatedMessage.metadata,
|
|
41
42
|
ideContextAdded: true,
|
|
42
43
|
ideContextType: this.forceFullContext ? 'full' : 'incremental'
|
|
43
44
|
}
|
|
@@ -8,6 +8,7 @@ export { ArgumentProcessorModifier, type ArgumentProcessorOptions } from './argu
|
|
|
8
8
|
export { MemoryImportModifier, type MemoryImportOptions } from './memoryImportModifier';
|
|
9
9
|
export { LoopDetectionModifier, type LoopDetectionOptions } from '../postInferenceProcessors/loopDetectionModifier';
|
|
10
10
|
export { ToolInjectionModifier, type ToolInjectionOptions } from './toolInjectionModifier';
|
|
11
|
+
export { ToolManifestPromptModifier, type ToolManifestPromptModifierOptions } from './toolManifestPromptModifier';
|
|
11
12
|
export { ChatRecordingModifier, type ChatRecordingOptions } from './chatRecordingModifier';
|
|
12
13
|
export { ChatHistoryMessageModifier, type ChatHistoryMessageModifierOptions } from './chatHistoryMessageModifier';
|
|
13
14
|
export { ContextAssemblyModifier, type ContextAssemblyModifierOptions } from './contextAssemblyModifier';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryTypeContextModifier = exports.RuleBasedContextModifier = exports.ContextAssemblyModifier = exports.ChatHistoryMessageModifier = exports.ChatRecordingModifier = exports.ToolInjectionModifier = exports.LoopDetectionModifier = exports.MemoryImportModifier = exports.ArgumentProcessorModifier = exports.CapabilityContextModifier = exports.AtFileProcessorModifier = exports.IdeContextModifier = exports.DirectoryContextModifier = exports.CoreSystemPromptModifier = exports.EnvironmentContextModifier = void 0;
|
|
3
|
+
exports.MemoryTypeContextModifier = exports.RuleBasedContextModifier = exports.ContextAssemblyModifier = exports.ChatHistoryMessageModifier = exports.ChatRecordingModifier = exports.ToolManifestPromptModifier = exports.ToolInjectionModifier = exports.LoopDetectionModifier = exports.MemoryImportModifier = exports.ArgumentProcessorModifier = exports.CapabilityContextModifier = exports.AtFileProcessorModifier = exports.IdeContextModifier = exports.DirectoryContextModifier = exports.CoreSystemPromptModifier = exports.EnvironmentContextModifier = void 0;
|
|
4
4
|
// Gemini-CLI equivalent modifiers
|
|
5
5
|
var environmentContextModifier_1 = require("./environmentContextModifier");
|
|
6
6
|
Object.defineProperty(exports, "EnvironmentContextModifier", { enumerable: true, get: function () { return environmentContextModifier_1.EnvironmentContextModifier; } });
|
|
@@ -22,6 +22,8 @@ var loopDetectionModifier_1 = require("../postInferenceProcessors/loopDetectionM
|
|
|
22
22
|
Object.defineProperty(exports, "LoopDetectionModifier", { enumerable: true, get: function () { return loopDetectionModifier_1.LoopDetectionModifier; } });
|
|
23
23
|
var toolInjectionModifier_1 = require("./toolInjectionModifier");
|
|
24
24
|
Object.defineProperty(exports, "ToolInjectionModifier", { enumerable: true, get: function () { return toolInjectionModifier_1.ToolInjectionModifier; } });
|
|
25
|
+
var toolManifestPromptModifier_1 = require("./toolManifestPromptModifier");
|
|
26
|
+
Object.defineProperty(exports, "ToolManifestPromptModifier", { enumerable: true, get: function () { return toolManifestPromptModifier_1.ToolManifestPromptModifier; } });
|
|
25
27
|
var chatRecordingModifier_1 = require("./chatRecordingModifier");
|
|
26
28
|
Object.defineProperty(exports, "ChatRecordingModifier", { enumerable: true, get: function () { return chatRecordingModifier_1.ChatRecordingModifier; } });
|
|
27
29
|
var chatHistoryMessageModifier_1 = require("./chatHistoryMessageModifier");
|
|
@@ -37,6 +37,7 @@ exports.MemoryImportModifier = void 0;
|
|
|
37
37
|
const base_1 = require("../base");
|
|
38
38
|
const fs = __importStar(require("fs"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
40
41
|
class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
41
42
|
constructor(options = {}) {
|
|
42
43
|
super();
|
|
@@ -54,8 +55,7 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
54
55
|
if (!this.options.enableMemoryImport) {
|
|
55
56
|
return createdMessage;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
const userMessage = createdMessage.message.messages.find(msg => msg.role === 'user');
|
|
58
|
+
const userMessage = (0, promptContext_1.getCurrentUserMessage)(createdMessage);
|
|
59
59
|
if (!userMessage || typeof userMessage.content !== 'string') {
|
|
60
60
|
return createdMessage;
|
|
61
61
|
}
|
|
@@ -105,23 +105,17 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
105
105
|
if (processedImports.length === 0) {
|
|
106
106
|
return createdMessage;
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...msg,
|
|
113
|
-
content
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return msg;
|
|
117
|
-
});
|
|
108
|
+
const updatedMessage = (0, promptContext_1.updateCurrentUserMessage)(createdMessage, (message) => ({
|
|
109
|
+
...message,
|
|
110
|
+
content,
|
|
111
|
+
}));
|
|
118
112
|
return Promise.resolve({
|
|
113
|
+
...updatedMessage,
|
|
119
114
|
message: {
|
|
120
|
-
...
|
|
121
|
-
messages
|
|
115
|
+
...updatedMessage.message,
|
|
122
116
|
},
|
|
123
117
|
metadata: {
|
|
124
|
-
...
|
|
118
|
+
...updatedMessage.metadata,
|
|
125
119
|
memoryImportsProcessed: true,
|
|
126
120
|
importedFiles: processedImports,
|
|
127
121
|
totalImports: processedImports.length
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ToolInjectionModifier = void 0;
|
|
4
4
|
const base_1 = require("../base");
|
|
5
5
|
const agentToolLoader_1 = require("../../unified/utils/agentToolLoader");
|
|
6
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
6
7
|
class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
7
8
|
constructor(options = {}) {
|
|
8
9
|
super();
|
|
@@ -19,7 +20,7 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
19
20
|
}
|
|
20
21
|
async modify(originalRequest, createdMessage) {
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
+
const mentionedMCPs = originalRequest.mentionedMCPs || [];
|
|
23
24
|
let tools = await (0, agentToolLoader_1.listAgentAvailableTools)(Array.isArray(mentionedMCPs) ? mentionedMCPs : []);
|
|
24
25
|
// Filter tools if allowedTools is specified
|
|
25
26
|
if (this.options.allowedTools && this.options.allowedTools.length > 0) {
|
|
@@ -30,17 +31,12 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
30
31
|
}
|
|
31
32
|
switch (this.options.toolsLocation) {
|
|
32
33
|
case 'InsidePrompt':
|
|
33
|
-
//@ts-ignore
|
|
34
34
|
return this.addToolsInsidePrompt(createdMessage, tools);
|
|
35
|
-
//@ts-ignore
|
|
36
35
|
case 'SystemMessage':
|
|
37
|
-
//@ts-ignore
|
|
38
36
|
return this.addToolsAsSystemMessage(createdMessage, tools);
|
|
39
37
|
case 'Tool':
|
|
40
|
-
//@ts-ignore
|
|
41
38
|
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
42
39
|
default:
|
|
43
|
-
//@ts-ignore
|
|
44
40
|
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
45
41
|
}
|
|
46
42
|
}
|
|
@@ -51,23 +47,24 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
51
47
|
}
|
|
52
48
|
addToolsInsidePrompt(createdMessage, tools) {
|
|
53
49
|
const toolsInfo = this.generateToolsInfo(tools);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const updatedMessage = (0, promptContext_1.updateCurrentUserMessage)(createdMessage, (message) => ({
|
|
51
|
+
...message,
|
|
52
|
+
content: typeof message.content === 'string'
|
|
53
|
+
? `${message.content}\n\n--- Available Tools ---\n${toolsInfo}`
|
|
54
|
+
: [
|
|
55
|
+
...(Array.isArray(message.content)
|
|
56
|
+
? message.content
|
|
57
|
+
: [{ type: 'text', text: String(message.content) }]),
|
|
58
|
+
{ type: 'text', text: `--- Available Tools ---\n${toolsInfo}` },
|
|
59
|
+
],
|
|
60
|
+
}));
|
|
64
61
|
return {
|
|
62
|
+
...updatedMessage,
|
|
65
63
|
message: {
|
|
66
|
-
...
|
|
67
|
-
messages: modifiedMessages
|
|
64
|
+
...updatedMessage.message,
|
|
68
65
|
},
|
|
69
66
|
metadata: {
|
|
70
|
-
...
|
|
67
|
+
...updatedMessage.metadata,
|
|
71
68
|
toolsInjected: true,
|
|
72
69
|
toolsLocation: 'InsidePrompt',
|
|
73
70
|
toolsCount: tools.length
|
|
@@ -83,7 +80,7 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
83
80
|
return {
|
|
84
81
|
message: {
|
|
85
82
|
...createdMessage.message,
|
|
86
|
-
|
|
83
|
+
input: [toolsMessage, ...createdMessage.message.input]
|
|
87
84
|
},
|
|
88
85
|
metadata: {
|
|
89
86
|
...createdMessage.metadata,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface ToolManifestPromptModifierOptions {
|
|
5
|
+
mode?: "categories" | "list";
|
|
6
|
+
category?: string;
|
|
7
|
+
pattern?: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
includeDescriptions?: boolean;
|
|
10
|
+
includeResources?: boolean;
|
|
11
|
+
runtimeToolSetId?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ToolManifestPromptModifier extends BaseMessageModifier {
|
|
15
|
+
private readonly options;
|
|
16
|
+
constructor(options?: ToolManifestPromptModifierOptions);
|
|
17
|
+
modify(_originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolManifestPromptModifier = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
6
|
+
class ToolManifestPromptModifier extends base_1.BaseMessageModifier {
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
super();
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
async modify(_originalRequest, createdMessage) {
|
|
12
|
+
const codeboltjs = await import("@codebolt/codeboltjs");
|
|
13
|
+
const codeboltTools = codeboltjs.tools;
|
|
14
|
+
if (!(codeboltTools === null || codeboltTools === void 0 ? void 0 : codeboltTools.getAvailableToolsManifest) && !(codeboltTools === null || codeboltTools === void 0 ? void 0 : codeboltTools.getAvailableToolsManifestAsync)) {
|
|
15
|
+
return createdMessage;
|
|
16
|
+
}
|
|
17
|
+
const manifestOptions = {
|
|
18
|
+
mode: this.options.mode || "categories",
|
|
19
|
+
};
|
|
20
|
+
if (this.options.category !== undefined) {
|
|
21
|
+
manifestOptions.category = this.options.category;
|
|
22
|
+
}
|
|
23
|
+
if (this.options.pattern !== undefined) {
|
|
24
|
+
manifestOptions.pattern = this.options.pattern;
|
|
25
|
+
}
|
|
26
|
+
if (this.options.limit !== undefined) {
|
|
27
|
+
manifestOptions.limit = this.options.limit;
|
|
28
|
+
}
|
|
29
|
+
if (this.options.includeDescriptions !== undefined) {
|
|
30
|
+
manifestOptions.includeDescriptions = this.options.includeDescriptions;
|
|
31
|
+
}
|
|
32
|
+
if (this.options.includeResources !== undefined) {
|
|
33
|
+
manifestOptions.includeResources = this.options.includeResources;
|
|
34
|
+
}
|
|
35
|
+
if (this.options.runtimeToolSetId !== undefined) {
|
|
36
|
+
manifestOptions.runtimeToolSetId = this.options.runtimeToolSetId;
|
|
37
|
+
}
|
|
38
|
+
const manifest = codeboltTools.getAvailableToolsManifestAsync
|
|
39
|
+
? await codeboltTools.getAvailableToolsManifestAsync(manifestOptions)
|
|
40
|
+
: codeboltTools.getAvailableToolsManifest(manifestOptions);
|
|
41
|
+
const contextMessage = {
|
|
42
|
+
role: "user",
|
|
43
|
+
content: `<tool_capability_catalogue title="${this.options.title || "Available CodeBolt tool areas"}">\n${manifest.text}\n</tool_capability_catalogue>`,
|
|
44
|
+
};
|
|
45
|
+
const updatedMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, contextMessage);
|
|
46
|
+
return {
|
|
47
|
+
...updatedMessage,
|
|
48
|
+
metadata: {
|
|
49
|
+
...updatedMessage.metadata,
|
|
50
|
+
toolManifestInjected: true,
|
|
51
|
+
toolManifestMode: manifest.mode,
|
|
52
|
+
toolManifestTotalMatches: manifest.totalMatches,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ToolManifestPromptModifier = ToolManifestPromptModifier;
|
|
@@ -21,32 +21,21 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
21
21
|
}
|
|
22
22
|
const currentTime = Date.now();
|
|
23
23
|
// Add LLM response to history
|
|
24
|
-
|
|
24
|
+
const responseContent = llmResponseMessage.output_text || llmResponseMessage.content;
|
|
25
|
+
if (responseContent) {
|
|
25
26
|
this.messageHistory.push({
|
|
26
|
-
content:
|
|
27
|
+
content: typeof responseContent === 'string' ? responseContent : JSON.stringify(responseContent),
|
|
27
28
|
timestamp: currentTime,
|
|
28
|
-
role: llmResponseMessage.role
|
|
29
|
+
role: llmResponseMessage.role || 'assistant'
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
// Add any choice messages from LLM response to history
|
|
32
|
-
if (llmResponseMessage.choices) {
|
|
33
|
-
for (const choice of llmResponseMessage.choices) {
|
|
34
|
-
if (choice.message && choice.message.content) {
|
|
35
|
-
this.messageHistory.push({
|
|
36
|
-
content: choice.message.content,
|
|
37
|
-
timestamp: currentTime,
|
|
38
|
-
role: choice.message.role
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
32
|
// Add the original sent message to history if it exists
|
|
44
|
-
for (const message of llmMessageSent.message.
|
|
33
|
+
for (const message of llmMessageSent.message.input) {
|
|
45
34
|
if (typeof message.content === 'string') {
|
|
46
35
|
this.messageHistory.push({
|
|
47
36
|
content: message.content,
|
|
48
37
|
timestamp: currentTime,
|
|
49
|
-
role: message.role
|
|
38
|
+
role: message.role || 'user'
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
41
|
}
|
|
@@ -61,11 +50,11 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
61
50
|
role: 'system',
|
|
62
51
|
content: `[Loop Detection Warning] Similar messages detected in recent conversation. This may indicate a conversational loop. Consider rephrasing your request or providing more specific information.`
|
|
63
52
|
};
|
|
64
|
-
const updatedMessages = [...nextPrompt.message.
|
|
53
|
+
const updatedMessages = [...nextPrompt.message.input, warningMessage];
|
|
65
54
|
return Promise.resolve({
|
|
66
55
|
message: {
|
|
67
56
|
...nextPrompt.message,
|
|
68
|
-
|
|
57
|
+
input: updatedMessages
|
|
69
58
|
},
|
|
70
59
|
metadata: {
|
|
71
60
|
...nextPrompt.metadata,
|
|
@@ -238,7 +238,7 @@ export declare class ConversationCompactorModifier extends BasePostToolCallProce
|
|
|
238
238
|
* Forces compression regardless of threshold (for testing or manual trigger)
|
|
239
239
|
*/
|
|
240
240
|
forceCompress(messages: MessageObject[]): Promise<{
|
|
241
|
-
|
|
241
|
+
input: MessageObject[];
|
|
242
242
|
metadata: Partial<CompressionMetadata>;
|
|
243
243
|
}>;
|
|
244
244
|
}
|
|
@@ -304,7 +304,7 @@ class ConversationCompactorModifier extends basePostToolCallProcessor_1.BasePost
|
|
|
304
304
|
}
|
|
305
305
|
// If under budget, no truncation needed
|
|
306
306
|
if (toolResponseTokens <= this.options.toolResponseTokenBudget) {
|
|
307
|
-
return {
|
|
307
|
+
return { input: result, truncated: false, tokensSaved: 0 };
|
|
308
308
|
}
|
|
309
309
|
// Iterate from oldest to newest tool messages for truncation
|
|
310
310
|
// (We truncate older tool outputs first to preserve recent context)
|
|
@@ -344,7 +344,7 @@ class ConversationCompactorModifier extends basePostToolCallProcessor_1.BasePost
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
return {
|
|
347
|
+
return { input: result, truncated, tokensSaved };
|
|
348
348
|
}
|
|
349
349
|
// ========================================================================
|
|
350
350
|
// History Split Point Calculation (Phase 2)
|
|
@@ -517,12 +517,16 @@ CRITICAL RULES:
|
|
|
517
517
|
var _a;
|
|
518
518
|
try {
|
|
519
519
|
const prompt = this.getCompressionPrompt(historyToCompress);
|
|
520
|
-
const
|
|
521
|
-
|
|
520
|
+
const inferencePayload = {
|
|
521
|
+
formatVersion: 'codebolt.llm.v2',
|
|
522
|
+
input: [
|
|
522
523
|
{ role: 'system', content: 'You are a precise conversation compression assistant.' },
|
|
523
524
|
{ role: 'user', content: prompt }
|
|
524
525
|
],
|
|
525
|
-
|
|
526
|
+
llmrole: this.options.llmRole,
|
|
527
|
+
};
|
|
528
|
+
console.log('[ConversationCompactor] llm.inference payload:', inferencePayload);
|
|
529
|
+
const response = await codeboltjs_1.default.llm.inference(inferencePayload);
|
|
526
530
|
const summary = ((_a = response.completion) === null || _a === void 0 ? void 0 : _a.content) || '';
|
|
527
531
|
if (this.options.enableLogging) {
|
|
528
532
|
console.log(`[ConversationCompactor] Generated summary (${summary.length} chars)`);
|
|
@@ -553,12 +557,16 @@ ORIGINAL MESSAGES COUNT: ${originalHistory.length}
|
|
|
553
557
|
If the snapshot is accurate and complete, respond with just the original snapshot.
|
|
554
558
|
If there are inaccuracies or missing critical information, provide a corrected version.
|
|
555
559
|
Keep the same XML format.`;
|
|
556
|
-
const
|
|
557
|
-
|
|
560
|
+
const inferencePayload = {
|
|
561
|
+
formatVersion: 'codebolt.llm.v2',
|
|
562
|
+
input: [
|
|
558
563
|
{ role: 'system', content: 'You are verifying a conversation compression for accuracy.' },
|
|
559
564
|
{ role: 'user', content: verificationPrompt }
|
|
560
|
-
]
|
|
561
|
-
|
|
565
|
+
],
|
|
566
|
+
llmrole: this.options.llmRole,
|
|
567
|
+
};
|
|
568
|
+
console.log('[ConversationCompactor] llm.inference verification payload:', inferencePayload);
|
|
569
|
+
const response = await codeboltjs_1.default.llm.inference(inferencePayload);
|
|
562
570
|
return ((_a = response.completion) === null || _a === void 0 ? void 0 : _a.content) || summary;
|
|
563
571
|
}
|
|
564
572
|
catch (error) {
|
|
@@ -680,7 +688,7 @@ Keep the same XML format.`;
|
|
|
680
688
|
if (this.options.enableLogging && deduplicatedCount > 0) {
|
|
681
689
|
console.log(`[ConversationCompactor] Deduplicated ${deduplicatedCount} file reads`);
|
|
682
690
|
}
|
|
683
|
-
return {
|
|
691
|
+
return { input: result, deduplicatedCount };
|
|
684
692
|
}
|
|
685
693
|
// ========================================================================
|
|
686
694
|
// Compression Strategies
|
|
@@ -732,7 +740,7 @@ Keep the same XML format.`;
|
|
|
732
740
|
*/
|
|
733
741
|
async compressSmart(messages) {
|
|
734
742
|
// Phase 1: Truncate large tool outputs
|
|
735
|
-
const {
|
|
743
|
+
const { input: truncatedMessages, truncated } = this.truncateLargeToolOutputs(messages);
|
|
736
744
|
// Check if truncation alone was sufficient
|
|
737
745
|
const tokensAfterTruncation = this.countMessageTokens(truncatedMessages);
|
|
738
746
|
const threshold = this.options.modelTokenLimit * this.options.compressionTokenThreshold;
|
|
@@ -789,7 +797,7 @@ Keep the same XML format.`;
|
|
|
789
797
|
*/
|
|
790
798
|
async compressSummarize(messages) {
|
|
791
799
|
// Phase 1: Truncate large tool outputs
|
|
792
|
-
const {
|
|
800
|
+
const { input: truncatedMessages, truncated } = this.truncateLargeToolOutputs(messages);
|
|
793
801
|
// Phase 2: Find split point
|
|
794
802
|
const splitIndex = this.findCompressionSplitIndex(truncatedMessages);
|
|
795
803
|
if (splitIndex === 0) {
|
|
@@ -869,7 +877,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
869
877
|
const { nextPrompt, rawLLMResponseMessage, tokenLimit } = input;
|
|
870
878
|
try {
|
|
871
879
|
// Safety check: ensure messages array exists
|
|
872
|
-
if (!((_a = nextPrompt === null || nextPrompt === void 0 ? void 0 : nextPrompt.message) === null || _a === void 0 ? void 0 : _a.
|
|
880
|
+
if (!((_a = nextPrompt === null || nextPrompt === void 0 ? void 0 : nextPrompt.message) === null || _a === void 0 ? void 0 : _a.input) || !Array.isArray(nextPrompt.message.input)) {
|
|
873
881
|
if (this.options.enableLogging) {
|
|
874
882
|
console.warn('[ConversationCompactor] No messages array found, skipping compression');
|
|
875
883
|
}
|
|
@@ -878,7 +886,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
878
886
|
shouldExit: false
|
|
879
887
|
};
|
|
880
888
|
}
|
|
881
|
-
const messages = nextPrompt.message.
|
|
889
|
+
const messages = nextPrompt.message.input;
|
|
882
890
|
// Get model token limit: prefer tokenLimit from LLM response, then lookup by model name, then fallback to config
|
|
883
891
|
const modelName = rawLLMResponseMessage === null || rawLLMResponseMessage === void 0 ? void 0 : rawLLMResponseMessage.model;
|
|
884
892
|
const modelTokenLimit = tokenLimit !== null && tokenLimit !== void 0 ? tokenLimit : (modelName ? getModelTokenLimit(modelName) : this.options.modelTokenLimit);
|
|
@@ -981,7 +989,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
981
989
|
};
|
|
982
990
|
}
|
|
983
991
|
// Pre-compression: deduplicate file reads to reduce token waste
|
|
984
|
-
const {
|
|
992
|
+
const { input: dedupedMessages } = this.deduplicateFileReads(messages);
|
|
985
993
|
// Apply compression based on strategy
|
|
986
994
|
let result;
|
|
987
995
|
switch (this.options.compactStrategy) {
|
|
@@ -1056,7 +1064,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1056
1064
|
nextPrompt: {
|
|
1057
1065
|
message: {
|
|
1058
1066
|
...nextPrompt.message,
|
|
1059
|
-
|
|
1067
|
+
input: result.compressedMessages
|
|
1060
1068
|
},
|
|
1061
1069
|
metadata: {
|
|
1062
1070
|
...nextPrompt.metadata,
|
|
@@ -1079,10 +1087,10 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1079
1087
|
...nextPrompt.metadata,
|
|
1080
1088
|
compression: {
|
|
1081
1089
|
status: CompressionStatus.FAILED_SUMMARIZATION_ERROR,
|
|
1082
|
-
originalTokenCount: this.countMessageTokens(nextPrompt.message.
|
|
1083
|
-
newTokenCount: this.countMessageTokens(nextPrompt.message.
|
|
1090
|
+
originalTokenCount: this.countMessageTokens(nextPrompt.message.input),
|
|
1091
|
+
newTokenCount: this.countMessageTokens(nextPrompt.message.input),
|
|
1084
1092
|
messagesCompressed: 0,
|
|
1085
|
-
messagesPreserved: nextPrompt.message.
|
|
1093
|
+
messagesPreserved: nextPrompt.message.input.length,
|
|
1086
1094
|
toolOutputsTruncated: false,
|
|
1087
1095
|
failedAttempts: this.failedCompressionAttempts,
|
|
1088
1096
|
timestamp: new Date().toISOString(),
|
|
@@ -1125,7 +1133,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1125
1133
|
? this.compressSummarize(messages)
|
|
1126
1134
|
: this.compressSmart(messages));
|
|
1127
1135
|
return {
|
|
1128
|
-
|
|
1136
|
+
input: result.compressedMessages,
|
|
1129
1137
|
metadata: result.metadata
|
|
1130
1138
|
};
|
|
1131
1139
|
}
|
|
@@ -42,7 +42,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
42
42
|
// Also process any shell injections in the next prompt messages
|
|
43
43
|
const updatedMessages = [];
|
|
44
44
|
let contentModified = false;
|
|
45
|
-
for (const message of processedNextPrompt.message.
|
|
45
|
+
for (const message of processedNextPrompt.message.input) {
|
|
46
46
|
if (typeof message.content === 'string') {
|
|
47
47
|
let processedContent = message.content;
|
|
48
48
|
// Replace {{args}} placeholders if metadata has args
|
|
@@ -69,7 +69,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
69
69
|
processedNextPrompt = {
|
|
70
70
|
message: {
|
|
71
71
|
...processedNextPrompt.message,
|
|
72
|
-
|
|
72
|
+
input: updatedMessages
|
|
73
73
|
},
|
|
74
74
|
metadata: {
|
|
75
75
|
...processedNextPrompt.metadata,
|
|
@@ -109,7 +109,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
109
109
|
processedPrompt = {
|
|
110
110
|
message: {
|
|
111
111
|
...processedPrompt.message,
|
|
112
|
-
|
|
112
|
+
input: [...processedPrompt.message.input, systemMessage]
|
|
113
113
|
},
|
|
114
114
|
metadata: {
|
|
115
115
|
...processedPrompt.metadata,
|
|
@@ -104,12 +104,12 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
const compressionResult = await this.tryCompressChat(createdMessage.message.
|
|
107
|
+
const compressionResult = await this.tryCompressChat(createdMessage.message.input, this.options.force || false);
|
|
108
108
|
if (compressionResult.compressionStatus === CompressionStatus.COMPRESSED) {
|
|
109
109
|
return {
|
|
110
110
|
message: {
|
|
111
111
|
...createdMessage.message,
|
|
112
|
-
|
|
112
|
+
input: compressionResult.compressedMessages || createdMessage.message.input
|
|
113
113
|
},
|
|
114
114
|
metadata: {
|
|
115
115
|
...createdMessage.metadata,
|
|
@@ -7,7 +7,7 @@ const mergeMessages = (existing, additional) => {
|
|
|
7
7
|
message: {
|
|
8
8
|
...existing.message,
|
|
9
9
|
...additional.message,
|
|
10
|
-
|
|
10
|
+
input: [...existing.message.input, ...additional.message.input],
|
|
11
11
|
},
|
|
12
12
|
metadata: {
|
|
13
13
|
...existing.metadata,
|
|
@@ -31,7 +31,7 @@ const addSystemMessage = (message, systemContent) => {
|
|
|
31
31
|
return {
|
|
32
32
|
message: {
|
|
33
33
|
...message.message,
|
|
34
|
-
|
|
34
|
+
input: [systemMessage, ...message.message.input]
|
|
35
35
|
},
|
|
36
36
|
metadata: {
|
|
37
37
|
...message.metadata,
|
|
@@ -50,7 +50,7 @@ const addUserContext = (message, contextKey, contextValue) => {
|
|
|
50
50
|
return {
|
|
51
51
|
message: {
|
|
52
52
|
...message.message,
|
|
53
|
-
|
|
53
|
+
input: [...message.message.input, contextMessage]
|
|
54
54
|
},
|
|
55
55
|
metadata: {
|
|
56
56
|
...message.metadata,
|