@codebolt/agent 6.1.16 → 6.1.17
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/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +3 -1
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +58 -5
- package/dist/types/InternalTypes.d.ts +2 -0
- package/dist/types/commonTypes.d.ts +12 -0
- package/dist/types/libFunctionTypes.d.ts +37 -0
- package/dist/types/socketMessageTypes.d.ts +12 -0
- package/dist/unified/agent/codeboltAgent.js +1 -0
- package/dist/unified/base/initialPromptGenerator.js +28 -0
- package/dist/unified/base/responseExecutor.d.ts +2 -0
- package/dist/unified/base/responseExecutor.js +33 -1
- package/dist/unified/types/libTypes.d.ts +12 -0
- package/package.json +1 -1
|
@@ -12,8 +12,10 @@ export declare class EnvironmentContextModifier extends BaseMessageModifier {
|
|
|
12
12
|
private readonly options;
|
|
13
13
|
private readonly defaultExcludePatterns;
|
|
14
14
|
constructor(options?: EnvironmentContextOptions);
|
|
15
|
-
modify(
|
|
15
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
16
|
+
private formatMentionedEnvironments;
|
|
16
17
|
private readProjectAgentMd;
|
|
18
|
+
private readAgentInstructionFile;
|
|
17
19
|
private generateFullContext;
|
|
18
20
|
private findRelevantFiles;
|
|
19
21
|
private walkDirectory;
|
|
@@ -67,7 +67,7 @@ class EnvironmentContextModifier extends base_1.BaseMessageModifier {
|
|
|
67
67
|
excludePatterns: [...this.defaultExcludePatterns, ...(options.excludePatterns || [])]
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
async modify(
|
|
70
|
+
async modify(originalRequest, createdMessage) {
|
|
71
71
|
try {
|
|
72
72
|
// Get current date formatted to user's locale
|
|
73
73
|
const today = new Date().toLocaleDateString(undefined, {
|
|
@@ -115,6 +115,10 @@ ${directoryListing}
|
|
|
115
115
|
contextParts.push(baseAgentMdContext);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
+
const mentionedEnvironmentContext = this.formatMentionedEnvironments(originalRequest.mentionedEnvironments);
|
|
119
|
+
if (mentionedEnvironmentContext) {
|
|
120
|
+
contextParts.push(mentionedEnvironmentContext);
|
|
121
|
+
}
|
|
118
122
|
// Add full file context if enabled (just like gemini-cli does)
|
|
119
123
|
if (this.options.enableFullContext) {
|
|
120
124
|
try {
|
|
@@ -155,18 +159,67 @@ ${directoryListing}
|
|
|
155
159
|
return createdMessage;
|
|
156
160
|
}
|
|
157
161
|
}
|
|
162
|
+
formatMentionedEnvironments(mentionedEnvironments) {
|
|
163
|
+
if (!(mentionedEnvironments === null || mentionedEnvironments === void 0 ? void 0 : mentionedEnvironments.length)) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const environments = mentionedEnvironments
|
|
167
|
+
.map((mention) => {
|
|
168
|
+
const environment = (mention === null || mention === void 0 ? void 0 : mention.environmentData) || mention;
|
|
169
|
+
const provider = (environment === null || environment === void 0 ? void 0 : environment.provider) || (environment === null || environment === void 0 ? void 0 : environment.remoteProvider) || {};
|
|
170
|
+
const config = (environment === null || environment === void 0 ? void 0 : environment.config) || {};
|
|
171
|
+
return {
|
|
172
|
+
id: (mention === null || mention === void 0 ? void 0 : mention.id) || (environment === null || environment === void 0 ? void 0 : environment.id) || (environment === null || environment === void 0 ? void 0 : environment.environmentId) || (environment === null || environment === void 0 ? void 0 : environment.environment_id),
|
|
173
|
+
name: (mention === null || mention === void 0 ? void 0 : mention.title) || (environment === null || environment === void 0 ? void 0 : environment.name) || (environment === null || environment === void 0 ? void 0 : environment.title),
|
|
174
|
+
description: (mention === null || mention === void 0 ? void 0 : mention.description) || (environment === null || environment === void 0 ? void 0 : environment.description),
|
|
175
|
+
state: (environment === null || environment === void 0 ? void 0 : environment.state) || (environment === null || environment === void 0 ? void 0 : environment.status),
|
|
176
|
+
provider: (provider === null || provider === void 0 ? void 0 : provider.name) || (provider === null || provider === void 0 ? void 0 : provider.title) || (provider === null || provider === void 0 ? void 0 : provider.id) || (provider === null || provider === void 0 ? void 0 : provider.providerId),
|
|
177
|
+
executionMode: (config === null || config === void 0 ? void 0 : config.executionMode) || (environment === null || environment === void 0 ? void 0 : environment.executionMode) || (environment === null || environment === void 0 ? void 0 : environment.type),
|
|
178
|
+
environment,
|
|
179
|
+
};
|
|
180
|
+
})
|
|
181
|
+
.filter((environment) => environment.id || environment.name);
|
|
182
|
+
if (!environments.length) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return [
|
|
186
|
+
'<mentioned-environments>',
|
|
187
|
+
'The user explicitly mentioned these environments with #. Treat them as routing context, not as an automatic active-environment selection.',
|
|
188
|
+
'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
|
+
'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`.',
|
|
190
|
+
'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
|
+
'If multiple mentioned environments could match and the user did not specify which one, ask a brief clarification before creating the background thread.',
|
|
192
|
+
'Do not call environment management tools or change the active environment just because an environment was mentioned.',
|
|
193
|
+
JSON.stringify(environments, null, 2),
|
|
194
|
+
'</mentioned-environments>',
|
|
195
|
+
].join('\n');
|
|
196
|
+
}
|
|
158
197
|
async readProjectAgentMd(basePath, title = 'Project Agent Instructions') {
|
|
159
|
-
const
|
|
160
|
-
|
|
198
|
+
const instructionFiles = [
|
|
199
|
+
path.join(basePath, '.codebolt', 'agent.md'),
|
|
200
|
+
path.join(basePath, 'agent.md'),
|
|
201
|
+
path.join(basePath, 'AGENTS.md'),
|
|
202
|
+
];
|
|
203
|
+
const sections = [];
|
|
204
|
+
for (const instructionFile of instructionFiles) {
|
|
205
|
+
const section = await this.readAgentInstructionFile(basePath, instructionFile, title);
|
|
206
|
+
if (section) {
|
|
207
|
+
sections.push(section);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return sections.join('\n\n');
|
|
211
|
+
}
|
|
212
|
+
async readAgentInstructionFile(basePath, filePath, title) {
|
|
213
|
+
const relativePath = path.relative(basePath, filePath);
|
|
161
214
|
try {
|
|
162
|
-
const stats = await fs.promises.stat(
|
|
215
|
+
const stats = await fs.promises.stat(filePath);
|
|
163
216
|
if (!stats.isFile()) {
|
|
164
217
|
return '';
|
|
165
218
|
}
|
|
166
219
|
if (stats.size > this.options.maxFileSize) {
|
|
167
220
|
return `--- ${title} (${relativePath}) ---\n[File too large: ${stats.size} bytes]`;
|
|
168
221
|
}
|
|
169
|
-
const content = await fs.promises.readFile(
|
|
222
|
+
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
170
223
|
if (!content.trim()) {
|
|
171
224
|
return '';
|
|
172
225
|
}
|
|
@@ -332,6 +332,12 @@ export interface Agent {
|
|
|
332
332
|
/** Detailed description of the agent and its capabilities */
|
|
333
333
|
longDescription?: string;
|
|
334
334
|
}
|
|
335
|
+
export interface FlagContext {
|
|
336
|
+
user: string[];
|
|
337
|
+
project: string[];
|
|
338
|
+
thread: string[];
|
|
339
|
+
effective: string[];
|
|
340
|
+
}
|
|
335
341
|
/**
|
|
336
342
|
* Interface for initial user message structure
|
|
337
343
|
*/
|
|
@@ -346,6 +352,12 @@ export interface InitialUserMessage {
|
|
|
346
352
|
mentionedMCPs?: MCPTool[];
|
|
347
353
|
/** List of mentioned agents */
|
|
348
354
|
mentionedAgents?: Agent[];
|
|
355
|
+
/** List of mentioned environments */
|
|
356
|
+
mentionedEnvironments?: any[];
|
|
357
|
+
/** Flags mentioned in the initial message context */
|
|
358
|
+
mentionedFlags?: string[];
|
|
359
|
+
/** Flags enabled for the initial message context */
|
|
360
|
+
flags?: FlagContext;
|
|
349
361
|
}
|
|
350
362
|
/**
|
|
351
363
|
* Type definition for an AST node.
|
|
@@ -160,6 +160,12 @@ export interface UserMessageContent {
|
|
|
160
160
|
/** The text content */
|
|
161
161
|
text: string;
|
|
162
162
|
}
|
|
163
|
+
export interface FlagContext {
|
|
164
|
+
user: string[];
|
|
165
|
+
project: string[];
|
|
166
|
+
thread: string[];
|
|
167
|
+
effective: string[];
|
|
168
|
+
}
|
|
163
169
|
/**
|
|
164
170
|
* User message received from the Codebolt platform
|
|
165
171
|
* This is a simplified, user-friendly version of the internal message format
|
|
@@ -193,6 +199,30 @@ export interface UserMessage {
|
|
|
193
199
|
selection?: any;
|
|
194
200
|
remixPrompt?: string;
|
|
195
201
|
mentionedAgents?: [];
|
|
202
|
+
mentionedEnvironments?: any[];
|
|
203
|
+
mentionedFlags?: string[];
|
|
204
|
+
flags?: FlagContext;
|
|
205
|
+
}
|
|
206
|
+
export interface DynamicAgentEvent {
|
|
207
|
+
id: string;
|
|
208
|
+
type: 'agent:dynamic:event';
|
|
209
|
+
timestamp: string;
|
|
210
|
+
source: Record<string, any>;
|
|
211
|
+
payload: {
|
|
212
|
+
name: string;
|
|
213
|
+
data?: Record<string, any>;
|
|
214
|
+
emittedAt: string;
|
|
215
|
+
};
|
|
216
|
+
metadata?: Record<string, any>;
|
|
217
|
+
}
|
|
218
|
+
export interface EmitAgentEventResponse {
|
|
219
|
+
success: boolean;
|
|
220
|
+
type: string;
|
|
221
|
+
requestId?: string;
|
|
222
|
+
data?: {
|
|
223
|
+
event: DynamicAgentEvent;
|
|
224
|
+
};
|
|
225
|
+
error?: string;
|
|
196
226
|
}
|
|
197
227
|
/**
|
|
198
228
|
* Interface for codebolt API functionality
|
|
@@ -224,6 +254,11 @@ export interface CodeboltAPI {
|
|
|
224
254
|
chat: {
|
|
225
255
|
sendMessage: (message: string, metadata: any) => Promise<void>;
|
|
226
256
|
};
|
|
257
|
+
agentEvents: {
|
|
258
|
+
emit: (name: string, data?: Record<string, any>, options?: {
|
|
259
|
+
metadata?: Record<string, any>;
|
|
260
|
+
}) => Promise<EmitAgentEventResponse>;
|
|
261
|
+
};
|
|
227
262
|
}
|
|
228
263
|
export interface ReadFileOptions {
|
|
229
264
|
/** File path to read */
|
|
@@ -565,6 +600,8 @@ export interface ChatSendOptions {
|
|
|
565
600
|
mentionedFiles?: string[];
|
|
566
601
|
/** Mentioned agents */
|
|
567
602
|
mentionedAgents?: string[];
|
|
603
|
+
/** Mentioned environments */
|
|
604
|
+
mentionedEnvironments?: any[];
|
|
568
605
|
}
|
|
569
606
|
export interface ChatHistoryOptions {
|
|
570
607
|
/** Conversation ID */
|
|
@@ -22,6 +22,12 @@ export interface BaseExecuteToolResponse extends BaseWebSocketResponse {
|
|
|
22
22
|
result?: any;
|
|
23
23
|
status?: 'pending' | 'executing' | 'success' | 'error' | 'rejected';
|
|
24
24
|
}
|
|
25
|
+
export interface FlagContext {
|
|
26
|
+
user: string[];
|
|
27
|
+
project: string[];
|
|
28
|
+
thread: string[];
|
|
29
|
+
effective: string[];
|
|
30
|
+
}
|
|
25
31
|
export interface UserMessage {
|
|
26
32
|
type: "messageResponse";
|
|
27
33
|
message: {
|
|
@@ -42,6 +48,7 @@ export interface UserMessage {
|
|
|
42
48
|
actions: any[];
|
|
43
49
|
mentionedAgents: any[];
|
|
44
50
|
mentionedDocs: any[];
|
|
51
|
+
mentionedEnvironments?: any[];
|
|
45
52
|
links: any[];
|
|
46
53
|
universalAgentLastMessage: string;
|
|
47
54
|
selection: any | null;
|
|
@@ -53,6 +60,8 @@ export interface UserMessage {
|
|
|
53
60
|
templateType: string;
|
|
54
61
|
processId: string;
|
|
55
62
|
shadowGitHash: string;
|
|
63
|
+
mentionedFlags?: string[];
|
|
64
|
+
flags?: FlagContext;
|
|
56
65
|
};
|
|
57
66
|
sender: {
|
|
58
67
|
senderType: string;
|
|
@@ -84,6 +93,7 @@ export interface ChatMessageFromUser {
|
|
|
84
93
|
actions: any[];
|
|
85
94
|
mentionedAgents: any[];
|
|
86
95
|
mentionedDocs: any[];
|
|
96
|
+
mentionedEnvironments?: any[];
|
|
87
97
|
links: any[];
|
|
88
98
|
universalAgentLastMessage: string;
|
|
89
99
|
selection: any | null;
|
|
@@ -95,6 +105,8 @@ export interface ChatMessageFromUser {
|
|
|
95
105
|
templateType: string;
|
|
96
106
|
processId: string;
|
|
97
107
|
shadowGitHash: string;
|
|
108
|
+
mentionedFlags?: string[];
|
|
109
|
+
flags?: FlagContext;
|
|
98
110
|
}
|
|
99
111
|
export interface ChatMessage extends BaseWebSocketResponse {
|
|
100
112
|
id: string;
|
|
@@ -8,6 +8,27 @@ exports.createUnifiedMessageProcessor = createUnifiedMessageProcessor;
|
|
|
8
8
|
const types_1 = require("../types/types");
|
|
9
9
|
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
10
10
|
const promptContext_1 = require("./promptContext");
|
|
11
|
+
const formatFlagList = (flags) => flags && flags.length > 0 ? flags.join(', ') : 'none';
|
|
12
|
+
const normalizeFlagList = (flags) => Array.from(new Set((flags || [])
|
|
13
|
+
.map(flag => String(flag || '').trim().toLowerCase().replace(/\s+/g, '-').replace(/^-+|-+$/g, ''))
|
|
14
|
+
.filter(Boolean))).sort();
|
|
15
|
+
const mergeFlagLists = (existing, mentioned) => {
|
|
16
|
+
const merged = [...(existing || []), ...normalizeFlagList(mentioned)];
|
|
17
|
+
return Array.from(new Set(merged.filter(Boolean)));
|
|
18
|
+
};
|
|
19
|
+
const formatFlagContext = (flags, mentionedFlags) => {
|
|
20
|
+
const normalizedMentionedFlags = normalizeFlagList(mentionedFlags);
|
|
21
|
+
if (!flags && normalizedMentionedFlags.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
return [
|
|
24
|
+
'<flags>',
|
|
25
|
+
`user: ${formatFlagList(flags === null || flags === void 0 ? void 0 : flags.user)}`,
|
|
26
|
+
`project: ${formatFlagList(flags === null || flags === void 0 ? void 0 : flags.project)}`,
|
|
27
|
+
`thread: ${formatFlagList(mergeFlagLists(flags === null || flags === void 0 ? void 0 : flags.thread, normalizedMentionedFlags))}`,
|
|
28
|
+
`effective: ${formatFlagList(mergeFlagLists(flags === null || flags === void 0 ? void 0 : flags.effective, normalizedMentionedFlags))}`,
|
|
29
|
+
'</flags>',
|
|
30
|
+
].join('\n');
|
|
31
|
+
};
|
|
11
32
|
/**
|
|
12
33
|
* Initial prompt generator that combines message modifiers with unified processing
|
|
13
34
|
*/
|
|
@@ -49,6 +70,13 @@ class InitialPromptGenerator {
|
|
|
49
70
|
role: 'user',
|
|
50
71
|
content: input.userMessage.trim(),
|
|
51
72
|
});
|
|
73
|
+
const flagContext = formatFlagContext(input.flags, input.mentionedFlags);
|
|
74
|
+
if (flagContext) {
|
|
75
|
+
createdMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, {
|
|
76
|
+
role: 'user',
|
|
77
|
+
content: flagContext,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
52
80
|
for (const messageModifier of this.processors) {
|
|
53
81
|
try {
|
|
54
82
|
createdMessage = await messageModifier.modify(input, createdMessage);
|
|
@@ -19,6 +19,8 @@ export declare class ResponseExecutor implements AgentResponseExecutor {
|
|
|
19
19
|
private runRequiredCompaction;
|
|
20
20
|
private executeTools;
|
|
21
21
|
private sendFinalMessageToChat;
|
|
22
|
+
private extractCompletionMessage;
|
|
23
|
+
private formatCompletionValue;
|
|
22
24
|
private executeSingleToolCall;
|
|
23
25
|
private executeTool;
|
|
24
26
|
private parseToolResult;
|
|
@@ -176,6 +176,7 @@ class ResponseExecutor {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
async executeTools(llmResponse) {
|
|
179
|
+
var _a;
|
|
179
180
|
const lastMessageContent = this.extractLastMessageContent(llmResponse);
|
|
180
181
|
const toolCalls = this.getToolCalls(llmResponse);
|
|
181
182
|
if (toolCalls.length === 0) {
|
|
@@ -228,8 +229,9 @@ class ResponseExecutor {
|
|
|
228
229
|
const completionToolCall = completionToolCalls.at(-1);
|
|
229
230
|
if (completionToolCall) {
|
|
230
231
|
const completionArguments = completionToolCall.toolInput;
|
|
231
|
-
this.finalMessage = JSON.stringify(completionArguments);
|
|
232
232
|
const [, completionResult] = await this.executeTool(completionToolCall.toolName, completionArguments);
|
|
233
|
+
this.finalMessage = (_a = this.extractCompletionMessage(completionArguments)) !== null && _a !== void 0 ? _a : lastMessageContent;
|
|
234
|
+
await this.sendFinalMessageToChat(this.finalMessage);
|
|
233
235
|
const parsedCompletionResult = this.parseToolResult(completionToolCall.toolUseId, completionResult === '' ? 'The user is satisfied with the result.' : completionResult);
|
|
234
236
|
toolResults.push(parsedCompletionResult);
|
|
235
237
|
}
|
|
@@ -253,6 +255,36 @@ class ResponseExecutor {
|
|
|
253
255
|
console.error('[ResponseExecutor] Failed to send final chat message:', error);
|
|
254
256
|
}
|
|
255
257
|
}
|
|
258
|
+
extractCompletionMessage(toolInput) {
|
|
259
|
+
if ('result' in toolInput) {
|
|
260
|
+
return this.formatCompletionValue(toolInput['result']);
|
|
261
|
+
}
|
|
262
|
+
return this.formatCompletionValue(toolInput);
|
|
263
|
+
}
|
|
264
|
+
formatCompletionValue(value) {
|
|
265
|
+
if (typeof value === 'string') {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
if (value === undefined || value === null) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
if (typeof value !== 'object') {
|
|
272
|
+
return String(value);
|
|
273
|
+
}
|
|
274
|
+
const valueRecord = value;
|
|
275
|
+
for (const key of ['answer', 'message', 'content', 'text', 'output', 'result']) {
|
|
276
|
+
const nestedValue = valueRecord[key];
|
|
277
|
+
if (typeof nestedValue === 'string' && nestedValue.trim().length > 0) {
|
|
278
|
+
return nestedValue;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
return JSON.stringify(value, null, 2);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return String(value);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
256
288
|
async executeSingleToolCall(toolCall) {
|
|
257
289
|
try {
|
|
258
290
|
let resultTuple;
|
|
@@ -206,6 +206,18 @@ export interface CodeboltAPI {
|
|
|
206
206
|
/** List available agents */
|
|
207
207
|
listAgents(): Promise<string[]>;
|
|
208
208
|
};
|
|
209
|
+
/** Dynamic agent events */
|
|
210
|
+
agentEvents?: {
|
|
211
|
+
emit(name: string, data?: Record<string, unknown>, options?: {
|
|
212
|
+
metadata?: Record<string, unknown>;
|
|
213
|
+
}): Promise<{
|
|
214
|
+
success: boolean;
|
|
215
|
+
type: string;
|
|
216
|
+
requestId?: string;
|
|
217
|
+
data?: unknown;
|
|
218
|
+
error?: string;
|
|
219
|
+
}>;
|
|
220
|
+
};
|
|
209
221
|
}
|
|
210
222
|
/**
|
|
211
223
|
* LLM configuration
|