@codebolt/agent 6.1.6 → 6.1.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.
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +0 -1
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +6 -74
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.d.ts +14 -0
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +133 -0
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/package.json +1 -1
|
@@ -18,7 +18,6 @@ export declare class AtFileProcessorModifier extends BaseMessageModifier {
|
|
|
18
18
|
private findFiles;
|
|
19
19
|
private readManyFiles;
|
|
20
20
|
private readFileContent;
|
|
21
|
-
private getFilesInFolder;
|
|
22
21
|
private getFolderStructure;
|
|
23
22
|
private findLastUserMessage;
|
|
24
23
|
private getProjectPath;
|
|
@@ -182,40 +182,12 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
182
182
|
const resolvedPath = await this.resolvePath(folderPath, workspaceDirectories);
|
|
183
183
|
const structure = await this.getFolderStructure(resolvedPath);
|
|
184
184
|
filesRead.push(folderPath);
|
|
185
|
-
contextParts.push(`\
|
|
185
|
+
contextParts.push(`\nDirectory listing for @${folderPath}:\n`);
|
|
186
186
|
contextParts.push(structure);
|
|
187
|
-
// Also read files within the folder
|
|
188
|
-
const filesInFolder = await this.getFilesInFolder(resolvedPath);
|
|
189
|
-
// console.log(`Found ${filesInFolder.length} files in ${folderPath}:`, filesInFolder.map(f => path.basename(f)));
|
|
190
|
-
if (filesInFolder.length > 0) {
|
|
191
|
-
contextParts.push(`\n--- Files in ${folderPath} ---`);
|
|
192
|
-
for (const filePath of filesInFolder) {
|
|
193
|
-
try {
|
|
194
|
-
// console.log(`Attempting to read file: ${filePath}`);
|
|
195
|
-
const content = await this.readFileContent(filePath);
|
|
196
|
-
const relativePath = path.relative(resolvedPath, filePath);
|
|
197
|
-
const displayPath = `${folderPath}/${relativePath}`;
|
|
198
|
-
contextParts.push(`\nContent from @${displayPath}:\n`);
|
|
199
|
-
contextParts.push(content);
|
|
200
|
-
// console.log(`Successfully read file: ${displayPath} (${content.length} chars)`);
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
204
|
-
const relativePath = path.relative(resolvedPath, filePath);
|
|
205
|
-
const displayPath = `${folderPath}/${relativePath}`;
|
|
206
|
-
console.error(`Error reading file ${displayPath}:`, errorMessage);
|
|
207
|
-
contextParts.push(`\nContent from @${displayPath}:\n`);
|
|
208
|
-
contextParts.push(`[Error reading file: ${errorMessage}]`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
console.log(`No files found in ${folderPath} (resolved to ${resolvedPath})`);
|
|
214
|
-
}
|
|
215
187
|
}
|
|
216
188
|
catch (error) {
|
|
217
189
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
218
|
-
contextParts.push(`\
|
|
190
|
+
contextParts.push(`\nDirectory listing for @${folderPath}:\n`);
|
|
219
191
|
contextParts.push(`[Error reading folder ${folderPath}: ${errorMessage}]`);
|
|
220
192
|
}
|
|
221
193
|
}
|
|
@@ -360,26 +332,6 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
360
332
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
361
333
|
return content;
|
|
362
334
|
}
|
|
363
|
-
async getFilesInFolder(folderPath) {
|
|
364
|
-
try {
|
|
365
|
-
const entries = await fs.readdir(folderPath, { withFileTypes: true });
|
|
366
|
-
const files = [];
|
|
367
|
-
for (const entry of entries) {
|
|
368
|
-
if (entry.isFile() && !entry.name.startsWith('.')) {
|
|
369
|
-
const filePath = path.join(folderPath, entry.name);
|
|
370
|
-
if (await this.isReadableTextFile(filePath)) {
|
|
371
|
-
files.push(path.join(folderPath, entry.name));
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
// Limit number of files to avoid overwhelming output
|
|
376
|
-
return files.slice(0, 10);
|
|
377
|
-
}
|
|
378
|
-
catch (error) {
|
|
379
|
-
console.error('Error reading files in folder:', error);
|
|
380
|
-
return [];
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
335
|
async getFolderStructure(folderPath) {
|
|
384
336
|
// Check if folder exists and is readable
|
|
385
337
|
const stats = await fs.stat(folderPath);
|
|
@@ -388,30 +340,10 @@ class AtFileProcessorModifier extends base_1.BaseMessageModifier {
|
|
|
388
340
|
}
|
|
389
341
|
// Read directory structure
|
|
390
342
|
const entries = await fs.readdir(folderPath, { withFileTypes: true });
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return -1;
|
|
396
|
-
if (!a.isDirectory() && b.isDirectory())
|
|
397
|
-
return 1;
|
|
398
|
-
return a.name.localeCompare(b.name);
|
|
399
|
-
});
|
|
400
|
-
for (const entry of sortedEntries.slice(0, 50)) { // Limit to 50 entries
|
|
401
|
-
if (entry.name.startsWith('.'))
|
|
402
|
-
continue; // Skip hidden files
|
|
403
|
-
if (entry.isDirectory()) {
|
|
404
|
-
lines.push(`${path.basename(folderPath)}/${entry.name}/`);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
const filePath = path.join(folderPath, entry.name);
|
|
408
|
-
const fileStats = await fs.stat(filePath);
|
|
409
|
-
const size = fileStats.size < 1024 ? `${fileStats.size}B` : `${Math.round(fileStats.size / 1024)}KB`;
|
|
410
|
-
lines.push(`${path.basename(folderPath)}/${entry.name} (${size})`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (entries.length > 50) {
|
|
414
|
-
lines.push(`... and ${entries.length - 50} more items`);
|
|
343
|
+
const maxDirectoryEntries = 1000;
|
|
344
|
+
const lines = entries.slice(0, maxDirectoryEntries).map((entry) => entry.name);
|
|
345
|
+
if (entries.length > maxDirectoryEntries) {
|
|
346
|
+
lines.push(`\u2026 and ${entries.length - maxDirectoryEntries} more entries`);
|
|
415
347
|
}
|
|
416
348
|
return lines.join('\n');
|
|
417
349
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
+
import { BaseMessageModifier } from "../base";
|
|
3
|
+
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
+
export interface CapabilityContextModifierOptions {
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class CapabilityContextModifier extends BaseMessageModifier {
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(options?: CapabilityContextModifierOptions);
|
|
10
|
+
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
11
|
+
private normalizeCapabilities;
|
|
12
|
+
private resolveCapabilityContext;
|
|
13
|
+
private formatCapabilityContext;
|
|
14
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CapabilityContextModifier = void 0;
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
9
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
10
|
+
class CapabilityContextModifier extends base_1.BaseMessageModifier {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
async modify(originalRequest, createdMessage) {
|
|
16
|
+
const selectedCapabilities = this.normalizeCapabilities(originalRequest.selectedCapabilities);
|
|
17
|
+
if (selectedCapabilities.length === 0) {
|
|
18
|
+
return createdMessage;
|
|
19
|
+
}
|
|
20
|
+
const resolvedContexts = [];
|
|
21
|
+
const capabilityErrors = [];
|
|
22
|
+
for (const capabilityName of selectedCapabilities) {
|
|
23
|
+
const resolvedContext = await this.resolveCapabilityContext(capabilityName, originalRequest);
|
|
24
|
+
if (resolvedContext.context) {
|
|
25
|
+
resolvedContexts.push(resolvedContext.context);
|
|
26
|
+
}
|
|
27
|
+
if (resolvedContext.error) {
|
|
28
|
+
capabilityErrors.push(resolvedContext.error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (resolvedContexts.length === 0) {
|
|
32
|
+
return {
|
|
33
|
+
...createdMessage,
|
|
34
|
+
metadata: {
|
|
35
|
+
...createdMessage.metadata,
|
|
36
|
+
selectedCapabilities,
|
|
37
|
+
selectedCapabilityErrors: capabilityErrors,
|
|
38
|
+
selectedCapabilitiesProcessed: false,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const contextMessage = {
|
|
43
|
+
role: 'user',
|
|
44
|
+
content: this.formatCapabilityContext(resolvedContexts),
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
...(0, promptContext_1.appendUserContextMessage)(createdMessage, contextMessage),
|
|
48
|
+
metadata: {
|
|
49
|
+
...createdMessage.metadata,
|
|
50
|
+
selectedCapabilities,
|
|
51
|
+
selectedCapabilitiesProcessed: true,
|
|
52
|
+
selectedCapabilityNames: resolvedContexts.map((context) => context.name),
|
|
53
|
+
selectedCapabilityErrors: capabilityErrors,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
normalizeCapabilities(selectedCapabilities) {
|
|
58
|
+
if (!Array.isArray(selectedCapabilities)) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return Array.from(new Set(selectedCapabilities
|
|
62
|
+
.map((capabilityName) => capabilityName.trim())
|
|
63
|
+
.filter(Boolean)));
|
|
64
|
+
}
|
|
65
|
+
async resolveCapabilityContext(capabilityName, originalRequest) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
try {
|
|
68
|
+
const capabilityDetail = await codeboltjs_1.default.capability.getCapabilityDetail(capabilityName);
|
|
69
|
+
if (!(capabilityDetail === null || capabilityDetail === void 0 ? void 0 : capabilityDetail.success) || !((_a = capabilityDetail.capability) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
70
|
+
return {
|
|
71
|
+
error: {
|
|
72
|
+
name: capabilityName,
|
|
73
|
+
error: (capabilityDetail === null || capabilityDetail === void 0 ? void 0 : capabilityDetail.error) || 'Capability detail did not include a capability type',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const capabilityType = capabilityDetail.capability.type;
|
|
78
|
+
const response = await codeboltjs_1.default.capability.startCapability(capabilityName, capabilityType, {
|
|
79
|
+
arguments: originalRequest.userMessage,
|
|
80
|
+
input: originalRequest.userMessage,
|
|
81
|
+
task: originalRequest.userMessage,
|
|
82
|
+
}, this.options.timeout);
|
|
83
|
+
if (!(response === null || response === void 0 ? void 0 : response.success)) {
|
|
84
|
+
return {
|
|
85
|
+
error: {
|
|
86
|
+
name: capabilityName,
|
|
87
|
+
error: (response === null || response === void 0 ? void 0 : response.error) || 'Capability did not return a successful response',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const skillPrompt = ((_b = response.additionalContext) === null || _b === void 0 ? void 0 : _b['skillPrompt']) || response.result;
|
|
92
|
+
const prompt = typeof (skillPrompt === null || skillPrompt === void 0 ? void 0 : skillPrompt.prompt) === 'string' ? skillPrompt.prompt.trim() : '';
|
|
93
|
+
if (!prompt) {
|
|
94
|
+
return {
|
|
95
|
+
error: {
|
|
96
|
+
name: capabilityName,
|
|
97
|
+
error: 'Capability response did not include prompt context',
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
context: {
|
|
103
|
+
name: skillPrompt.skillName || capabilityName,
|
|
104
|
+
type: capabilityType,
|
|
105
|
+
prompt,
|
|
106
|
+
refs: skillPrompt.refs,
|
|
107
|
+
metadata: skillPrompt.metadata,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return {
|
|
113
|
+
error: {
|
|
114
|
+
name: capabilityName,
|
|
115
|
+
error: error instanceof Error ? error.message : String(error),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
formatCapabilityContext(resolvedContexts) {
|
|
121
|
+
const contextSections = resolvedContexts.map((context) => {
|
|
122
|
+
const refs = Array.isArray(context.refs) && context.refs.length > 0
|
|
123
|
+
? `\n\nCapability references:\n${context.refs.map((ref) => `- ${JSON.stringify(ref)}`).join('\n')}`
|
|
124
|
+
: '';
|
|
125
|
+
return `--- Selected capability: ${context.name} (${context.type}) ---\n${context.prompt}${refs}`;
|
|
126
|
+
});
|
|
127
|
+
return [
|
|
128
|
+
'The user selected the following capabilities for this turn. Use this capability context while answering the user.',
|
|
129
|
+
...contextSections,
|
|
130
|
+
].join('\n\n');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.CapabilityContextModifier = CapabilityContextModifier;
|
|
@@ -3,6 +3,7 @@ export { CoreSystemPromptModifier, type CoreSystemPromptOptions } from './coreSy
|
|
|
3
3
|
export { DirectoryContextModifier, type DirectoryContextOptions } from './directoryContextModifier';
|
|
4
4
|
export { IdeContextModifier, type IdeContextOptions, type FileInfo, type IdeContext } from './ideContextModifier';
|
|
5
5
|
export { AtFileProcessorModifier, type AtFileProcessorOptions } from './atFileProcessorModifier';
|
|
6
|
+
export { CapabilityContextModifier, type CapabilityContextModifierOptions } from './capabilityContextModifier';
|
|
6
7
|
export { ArgumentProcessorModifier, type ArgumentProcessorOptions } from './argumentProcessorModifier';
|
|
7
8
|
export { MemoryImportModifier, type MemoryImportOptions } from './memoryImportModifier';
|
|
8
9
|
export { LoopDetectionModifier, type LoopDetectionOptions } from '../postInferenceProcessors/loopDetectionModifier';
|
|
@@ -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.AtFileProcessorModifier = exports.IdeContextModifier = exports.DirectoryContextModifier = exports.CoreSystemPromptModifier = exports.EnvironmentContextModifier = void 0;
|
|
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;
|
|
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; } });
|
|
@@ -12,6 +12,8 @@ var ideContextModifier_1 = require("./ideContextModifier");
|
|
|
12
12
|
Object.defineProperty(exports, "IdeContextModifier", { enumerable: true, get: function () { return ideContextModifier_1.IdeContextModifier; } });
|
|
13
13
|
var atFileProcessorModifier_1 = require("./atFileProcessorModifier");
|
|
14
14
|
Object.defineProperty(exports, "AtFileProcessorModifier", { enumerable: true, get: function () { return atFileProcessorModifier_1.AtFileProcessorModifier; } });
|
|
15
|
+
var capabilityContextModifier_1 = require("./capabilityContextModifier");
|
|
16
|
+
Object.defineProperty(exports, "CapabilityContextModifier", { enumerable: true, get: function () { return capabilityContextModifier_1.CapabilityContextModifier; } });
|
|
15
17
|
var argumentProcessorModifier_1 = require("./argumentProcessorModifier");
|
|
16
18
|
Object.defineProperty(exports, "ArgumentProcessorModifier", { enumerable: true, get: function () { return argumentProcessorModifier_1.ArgumentProcessorModifier; } });
|
|
17
19
|
var memoryImportModifier_1 = require("./memoryImportModifier");
|