@codebolt/agent 5.0.2 → 5.0.7
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/agent.d.ts +86 -0
- package/dist/agent.js +324 -0
- package/dist/builderpattern/agent.js +2 -2
- package/dist/builderpattern/followupquestionbuilder.js +1 -1
- package/dist/builderpattern/llmoutputhandler.js +7 -7
- package/dist/builderpattern/usermessage.d.ts +1 -6
- package/dist/composablepattern/document.js +35 -2
- package/dist/followupquestionbuilder.d.ts +75 -0
- package/dist/followupquestionbuilder.js +197 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/dist/llmoutputhandler.d.ts +102 -0
- package/dist/llmoutputhandler.js +452 -0
- package/dist/processor/types/interfaces.d.ts +21 -44
- package/dist/processor-pieces/index.d.ts +3 -0
- package/dist/processor-pieces/index.js +3 -0
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +5 -14
- package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +40 -41
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +13 -5
- package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +58 -50
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +8 -6
- package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +22 -66
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +2 -3
- package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +2 -1
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +4 -1
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +2 -18
- package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +93 -291
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +18 -0
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +41 -0
- package/dist/processor-pieces/postToolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/postToolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/preInferenceProcessors/index.d.ts +1 -1
- package/dist/processor-pieces/preInferenceProcessors/index.js +3 -0
- package/dist/processor-pieces/pretoolCallProcessors/index.d.ts +2 -1
- package/dist/processor-pieces/pretoolCallProcessors/index.js +5 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.d.ts +21 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolParameterModifier.js +32 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.d.ts +16 -0
- package/dist/processor-pieces/pretoolCallProcessors/toolValidationModifier.js +37 -0
- package/dist/promptbuilder.d.ts +382 -0
- package/dist/promptbuilder.js +805 -0
- package/dist/systemprompt.d.ts +20 -0
- package/dist/systemprompt.js +48 -0
- package/dist/taskInstruction.d.ts +37 -0
- package/dist/taskInstruction.js +57 -0
- package/dist/types/libFunctionTypes.d.ts +13 -19
- package/dist/types/libFunctionTypes.js +3 -0
- package/dist/types/processorTypes.d.ts +8 -8
- package/dist/types/processorTypes.js +6 -23
- package/dist/unified/agent/agent.js +2 -2
- package/dist/unified/agent/codeboltAgent.d.ts +122 -0
- package/dist/unified/agent/codeboltAgent.js +210 -0
- package/dist/unified/base/initialPromptGenerator.js +18 -4
- package/dist/unified/base/responseExecutor.d.ts +3 -2
- package/dist/unified/base/responseExecutor.js +109 -56
- package/dist/unified/index.d.ts +4 -0
- package/dist/unified/index.js +12 -1
- package/dist/usermessage.d.ts +70 -0
- package/dist/usermessage.js +123 -0
- package/package.json +11 -6
- package/dist/local-tools/fileTools.d.ts +0 -26
- package/dist/local-tools/fileTools.js +0 -162
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.d.ts +0 -13
- package/dist/processor-pieces/additionalModifiers/argumentProcessorModifier.js +0 -68
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/atFileProcessorModifier.js +0 -212
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/additionalModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.d.ts +0 -23
- package/dist/processor-pieces/additionalModifiers/chatRecordingModifier.js +0 -173
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.d.ts +0 -14
- package/dist/processor-pieces/additionalModifiers/coreSystemPromptModifier.js +0 -93
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.d.ts +0 -30
- package/dist/processor-pieces/additionalModifiers/directoryContextModifier.js +0 -330
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.d.ts +0 -26
- package/dist/processor-pieces/additionalModifiers/environmentContextModifier.js +0 -269
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.d.ts +0 -38
- package/dist/processor-pieces/additionalModifiers/fallbackHandlerModifier.js +0 -217
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.d.ts +0 -34
- package/dist/processor-pieces/additionalModifiers/ideContextModifier.js +0 -147
- package/dist/processor-pieces/additionalModifiers/index.d.ts +0 -12
- package/dist/processor-pieces/additionalModifiers/index.js +0 -28
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.d.ts +0 -29
- package/dist/processor-pieces/additionalModifiers/loopDetectionModifier.js +0 -155
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.d.ts +0 -15
- package/dist/processor-pieces/additionalModifiers/memoryImportModifier.js +0 -129
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.d.ts +0 -25
- package/dist/processor-pieces/additionalModifiers/shellProcessorModifier.js +0 -169
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.d.ts +0 -20
- package/dist/processor-pieces/additionalModifiers/toolInjectionModifier.js +0 -152
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/addCurrentDirectoryRootFilesModifier.js +0 -93
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.d.ts +0 -9
- package/dist/processor-pieces/messageModifiers/advancedSystemInstructionMessageModifier.js +0 -77
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.d.ts +0 -19
- package/dist/processor-pieces/messageModifiers/chatCompressionModifier.js +0 -110
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.d.ts +0 -20
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.example.js +0 -124
- package/dist/processor-pieces/messageModifiers/environmentContext.d.ts +0 -41
- package/dist/processor-pieces/messageModifiers/environmentContext.js +0 -355
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.d.ts +0 -23
- package/dist/processor-pieces/messageModifiers/mentionedFilesModifier.js +0 -207
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.d.ts +0 -7
- package/dist/processor-pieces/messageModifiers/simpleMessageModifier.js +0 -26
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.d.ts +0 -1
- package/dist/processor-pieces/postInference/llmOutputValidityProcessor.js +0 -2
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.d.ts +0 -7
- package/dist/processor-pieces/postInferenceProcessors/checkForNoToolCall.js +0 -24
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.d.ts +0 -41
- package/dist/processor-pieces/postToolCall/advancedLoopDetectionProcessor.js +0 -197
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.d.ts +0 -26
- package/dist/processor-pieces/postToolCall/chatCompressionProcessor.js +0 -90
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.d.ts +0 -81
- package/dist/processor-pieces/postToolCall/chatRecordingProcessor.js +0 -329
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.d.ts +0 -40
- package/dist/processor-pieces/postToolCall/contextManagementProcessor.js +0 -272
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationCompactorProcessor.js +0 -291
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/postToolCall/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.d.ts +0 -47
- package/dist/processor-pieces/postToolCall/followUpConversationProcessor.js +0 -249
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/loopDetectionProcessor.js +0 -137
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.d.ts +0 -30
- package/dist/processor-pieces/postToolCall/responseValidationProcessor.js +0 -228
- package/dist/processor-pieces/postToolCall/telemetryProcessor.d.ts +0 -99
- package/dist/processor-pieces/postToolCall/telemetryProcessor.js +0 -278
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.d.ts +0 -37
- package/dist/processor-pieces/postToolCall/tokenManagementProcessor.js +0 -178
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.d.ts +0 -43
- package/dist/processor-pieces/postToolCall/toolExecutionProcessor.js +0 -207
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.d.ts +0 -52
- package/dist/processor-pieces/preInference/conversationCompactorProcessor.js +0 -264
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.d.ts +0 -49
- package/dist/processor-pieces/preInference/conversationContinuityProcessor.js +0 -293
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.d.ts +0 -7
- package/dist/processor-pieces/preInferenceProcessors/conversationCompaction.js +0 -31
- package/dist/processor-pieces/preToolCall/index.d.ts +0 -9
- package/dist/processor-pieces/preToolCall/index.js +0 -18
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/localToolInterceptorProcessor.js +0 -444
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.d.ts +0 -44
- package/dist/processor-pieces/preToolCall/toolParameterModifierProcessor.js +0 -367
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.d.ts +0 -58
- package/dist/processor-pieces/preToolCall/toolValidationProcessor.js +0 -391
- package/dist/unified/agent/tool.d.ts +0 -99
- package/dist/unified/agent/tool.js +0 -440
- package/dist/unified/examples/agentExample.d.ts +0 -46
- package/dist/unified/examples/agentExample.js +0 -464
- package/dist/unified/examples/documentationPatternExample.d.ts +0 -10
- package/dist/unified/examples/documentationPatternExample.js +0 -385
- package/dist/unified/examples/followUpProcessorsExample.d.ts +0 -45
- package/dist/unified/examples/followUpProcessorsExample.js +0 -311
- package/dist/unified/examples/orchestratorExample.d.ts +0 -16
- package/dist/unified/examples/orchestratorExample.js +0 -415
- package/dist/unified/examples/preToolCallProcessorsExample.d.ts +0 -36
- package/dist/unified/examples/preToolCallProcessorsExample.js +0 -458
- package/dist/unified/examples/workflowExample.d.ts +0 -12
- package/dist/unified/examples/workflowExample.js +0 -497
- package/dist/unified/orchestrator/orchestrator.d.ts +0 -260
- package/dist/unified/orchestrator/orchestrator.js +0 -519
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ChatRecordingModifier = void 0;
|
|
37
|
-
const base_1 = require("../base");
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
class ChatRecordingModifier extends base_1.BaseMessageModifier {
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
super();
|
|
43
|
-
this.options = {
|
|
44
|
-
enableRecording: options.enableRecording || false,
|
|
45
|
-
recordingPath: options.recordingPath || path.join(process.cwd(), '.chat-recordings'),
|
|
46
|
-
maxRecordingSize: options.maxRecordingSize || 10 * 1024 * 1024, // 10MB
|
|
47
|
-
includeMetadata: options.includeMetadata !== false,
|
|
48
|
-
recordingFormat: options.recordingFormat || 'json'
|
|
49
|
-
};
|
|
50
|
-
if (this.options.enableRecording) {
|
|
51
|
-
this.initializeRecording();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async modify(originalRequest, createdMessage) {
|
|
55
|
-
try {
|
|
56
|
-
if (!this.options.enableRecording || !this.recordingFile) {
|
|
57
|
-
return createdMessage;
|
|
58
|
-
}
|
|
59
|
-
// Record the conversation
|
|
60
|
-
await this.recordMessages(createdMessage, originalRequest);
|
|
61
|
-
return Promise.resolve({
|
|
62
|
-
...createdMessage,
|
|
63
|
-
metadata: {
|
|
64
|
-
...createdMessage.metadata,
|
|
65
|
-
chatRecorded: true,
|
|
66
|
-
recordingFile: this.recordingFile
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error('Error in ChatRecordingModifier:', error);
|
|
72
|
-
return createdMessage;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
initializeRecording() {
|
|
76
|
-
try {
|
|
77
|
-
// Ensure recording directory exists
|
|
78
|
-
if (!fs.existsSync(this.options.recordingPath)) {
|
|
79
|
-
fs.mkdirSync(this.options.recordingPath, { recursive: true });
|
|
80
|
-
}
|
|
81
|
-
// Create recording file with timestamp
|
|
82
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
83
|
-
const extension = this.options.recordingFormat === 'markdown' ? 'md' : 'jsonl';
|
|
84
|
-
this.recordingFile = path.join(this.options.recordingPath, `chat-${timestamp}.${extension}`);
|
|
85
|
-
// Initialize file with header
|
|
86
|
-
if (this.options.recordingFormat === 'markdown') {
|
|
87
|
-
fs.writeFileSync(this.recordingFile, `# Chat Recording\n\nStarted: ${new Date().toISOString()}\n\n---\n\n`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.error('Failed to initialize chat recording:', error);
|
|
92
|
-
this.recordingFile = undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async recordMessages(createdMessage, originalRequest) {
|
|
96
|
-
var _a, _b;
|
|
97
|
-
if (!this.recordingFile)
|
|
98
|
-
return;
|
|
99
|
-
try {
|
|
100
|
-
// Check file size before writing
|
|
101
|
-
if (fs.existsSync(this.recordingFile)) {
|
|
102
|
-
const stats = fs.statSync(this.recordingFile);
|
|
103
|
-
if (stats.size > this.options.maxRecordingSize) {
|
|
104
|
-
console.warn(`Chat recording file ${this.recordingFile} exceeds maximum size. Stopping recording.`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const timestamp = new Date().toISOString();
|
|
109
|
-
// Record each message
|
|
110
|
-
for (const message of createdMessage.message.messages) {
|
|
111
|
-
const record = {
|
|
112
|
-
timestamp,
|
|
113
|
-
messageId: (_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a.messageId,
|
|
114
|
-
threadId: (_b = createdMessage.metadata) === null || _b === void 0 ? void 0 : _b.threadId,
|
|
115
|
-
role: message.role,
|
|
116
|
-
content: typeof message.content === 'string' ? message.content : JSON.stringify(message.content)
|
|
117
|
-
};
|
|
118
|
-
if (this.options.includeMetadata) {
|
|
119
|
-
record.metadata = {
|
|
120
|
-
originalRequest: {
|
|
121
|
-
userMessage: originalRequest.userMessage,
|
|
122
|
-
messageId: originalRequest.messageId,
|
|
123
|
-
threadId: originalRequest.threadId
|
|
124
|
-
},
|
|
125
|
-
processedMetadata: createdMessage.metadata
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
await this.writeRecord(record);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error('Error recording chat messages:', error);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
async writeRecord(record) {
|
|
136
|
-
if (!this.recordingFile)
|
|
137
|
-
return;
|
|
138
|
-
try {
|
|
139
|
-
if (this.options.recordingFormat === 'markdown') {
|
|
140
|
-
const content = `## ${record.role.toUpperCase()} - ${record.timestamp}\n\n${record.content}\n\n---\n\n`;
|
|
141
|
-
fs.appendFileSync(this.recordingFile, content);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const jsonLine = JSON.stringify(record) + '\n';
|
|
145
|
-
fs.appendFileSync(this.recordingFile, jsonLine);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
console.error('Error writing chat record:', error);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
startRecording(customPath) {
|
|
153
|
-
this.options.enableRecording = true;
|
|
154
|
-
if (customPath) {
|
|
155
|
-
this.options.recordingPath = customPath;
|
|
156
|
-
}
|
|
157
|
-
this.initializeRecording();
|
|
158
|
-
}
|
|
159
|
-
stopRecording() {
|
|
160
|
-
this.options.enableRecording = false;
|
|
161
|
-
if (this.recordingFile && this.options.recordingFormat === 'markdown') {
|
|
162
|
-
fs.appendFileSync(this.recordingFile, `\n---\n\nRecording ended: ${new Date().toISOString()}\n`);
|
|
163
|
-
}
|
|
164
|
-
this.recordingFile = undefined;
|
|
165
|
-
}
|
|
166
|
-
getRecordingFile() {
|
|
167
|
-
return this.recordingFile;
|
|
168
|
-
}
|
|
169
|
-
isRecording() {
|
|
170
|
-
return (this.options.enableRecording || false) && !!this.recordingFile;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.ChatRecordingModifier = ChatRecordingModifier;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
-
import { BaseMessageModifier } from "../base";
|
|
3
|
-
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
-
export interface CoreSystemPromptOptions {
|
|
5
|
-
customSystemPrompt?: string;
|
|
6
|
-
userMemory?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class CoreSystemPromptModifier extends BaseMessageModifier {
|
|
9
|
-
private readonly options;
|
|
10
|
-
constructor(options?: CoreSystemPromptOptions);
|
|
11
|
-
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
12
|
-
private getCoreSystemPrompt;
|
|
13
|
-
private getDefaultSystemPrompt;
|
|
14
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CoreSystemPromptModifier = void 0;
|
|
4
|
-
const base_1 = require("../base");
|
|
5
|
-
class CoreSystemPromptModifier extends base_1.BaseMessageModifier {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
super();
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
modify(originalRequest, createdMessage) {
|
|
11
|
-
var _a;
|
|
12
|
-
// Get user memory from metadata or options
|
|
13
|
-
const userMemory = ((_a = createdMessage.metadata) === null || _a === void 0 ? void 0 : _a.userMemory) || this.options.userMemory;
|
|
14
|
-
const systemPrompt = this.options.customSystemPrompt || this.getCoreSystemPrompt(userMemory);
|
|
15
|
-
const systemMessage = {
|
|
16
|
-
role: 'system',
|
|
17
|
-
content: systemPrompt
|
|
18
|
-
};
|
|
19
|
-
// Find existing system message or add new one
|
|
20
|
-
const messages = [...createdMessage.message.messages];
|
|
21
|
-
const systemMessageIndex = messages.findIndex(msg => msg.role === 'system');
|
|
22
|
-
if (systemMessageIndex !== -1) {
|
|
23
|
-
// Replace existing system message
|
|
24
|
-
messages[systemMessageIndex] = systemMessage;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// Add new system message at the beginning
|
|
28
|
-
messages.unshift(systemMessage);
|
|
29
|
-
}
|
|
30
|
-
return Promise.resolve({
|
|
31
|
-
message: {
|
|
32
|
-
...createdMessage.message,
|
|
33
|
-
messages
|
|
34
|
-
},
|
|
35
|
-
metadata: {
|
|
36
|
-
...createdMessage.metadata,
|
|
37
|
-
coreSystemPromptAdded: true,
|
|
38
|
-
systemPromptSource: this.options.customSystemPrompt ? 'custom' : 'default',
|
|
39
|
-
hasUserMemory: !!userMemory
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
getCoreSystemPrompt(userMemory) {
|
|
44
|
-
const basePrompt = this.getDefaultSystemPrompt();
|
|
45
|
-
// Add user memory with separator if provided (exactly like gemini-cli)
|
|
46
|
-
const memorySuffix = userMemory && userMemory.trim().length > 0
|
|
47
|
-
? `\n\n---\n\n${userMemory.trim()}`
|
|
48
|
-
: '';
|
|
49
|
-
return `${basePrompt}${memorySuffix}`;
|
|
50
|
-
}
|
|
51
|
-
getDefaultSystemPrompt() {
|
|
52
|
-
return `
|
|
53
|
-
You are an interactive AI agent specializing in software engineering tasks. Your primary goal is to help users safely and efficiently, adhering strictly to the following instructions and utilizing your available tools.
|
|
54
|
-
|
|
55
|
-
# Core Mandates
|
|
56
|
-
|
|
57
|
-
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
|
|
58
|
-
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project before employing it.
|
|
59
|
-
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
|
|
60
|
-
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
|
|
61
|
-
- **Comments:** Add code comments sparingly. Focus on *why* something is done, especially for complex logic, rather than *what* is done.
|
|
62
|
-
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
|
|
63
|
-
- **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user.
|
|
64
|
-
- **Explaining Changes:** After completing a code modification or file operation *do not* provide summaries unless asked.
|
|
65
|
-
|
|
66
|
-
# Primary Workflows
|
|
67
|
-
|
|
68
|
-
## Software Engineering Tasks
|
|
69
|
-
When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
|
|
70
|
-
1. **Understand:** Think about the user's request and the relevant codebase context. Use search tools extensively to understand file structures, existing code patterns, and conventions.
|
|
71
|
-
2. **Plan:** Build a coherent and grounded plan for how you intend to resolve the user's task. Share a concise yet clear plan with the user if it would help.
|
|
72
|
-
3. **Implement:** Use the available tools to act on the plan, strictly adhering to the project's established conventions.
|
|
73
|
-
4. **Verify:** If applicable and feasible, verify the changes using the project's testing procedures and build/lint commands.
|
|
74
|
-
|
|
75
|
-
# Operational Guidelines
|
|
76
|
-
|
|
77
|
-
## Tone and Style
|
|
78
|
-
- **Concise & Direct:** Adopt a professional, direct, and concise tone.
|
|
79
|
-
- **Minimal Output:** Aim for fewer than 3 lines of text output per response whenever practical.
|
|
80
|
-
- **Clarity over Brevity:** While conciseness is key, prioritize clarity for essential explanations.
|
|
81
|
-
- **No Chitchat:** Avoid conversational filler. Get straight to the action or answer.
|
|
82
|
-
- **Formatting:** Use GitHub-flavored Markdown.
|
|
83
|
-
|
|
84
|
-
## Security and Safety Rules
|
|
85
|
-
- **Security First:** Always apply security best practices. Never introduce code that exposes, logs, or commits secrets, API keys, or other sensitive information.
|
|
86
|
-
- **File Operations:** Always use absolute paths when referring to files with tools.
|
|
87
|
-
|
|
88
|
-
# Final Reminder
|
|
89
|
-
Your core function is efficient and safe assistance. Balance extreme conciseness with the crucial need for clarity, especially regarding safety and potential system modifications. Always prioritize user control and project conventions.
|
|
90
|
-
`.trim();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.CoreSystemPromptModifier = CoreSystemPromptModifier;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
-
import { BaseMessageModifier } from "../base";
|
|
3
|
-
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
-
export interface DirectoryContextOptions {
|
|
5
|
-
workspaceDirectories?: string[];
|
|
6
|
-
}
|
|
7
|
-
export declare class DirectoryContextModifier extends BaseMessageModifier {
|
|
8
|
-
private readonly options;
|
|
9
|
-
constructor(options?: DirectoryContextOptions);
|
|
10
|
-
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
11
|
-
/**
|
|
12
|
-
* Generates a string representation of a directory's structure,
|
|
13
|
-
* limiting the number of items displayed. Ignored folders are shown
|
|
14
|
-
* followed by '...' instead of their contents.
|
|
15
|
-
*
|
|
16
|
-
* @param directory The absolute or relative path to the directory.
|
|
17
|
-
* @param options Optional configuration settings.
|
|
18
|
-
* @returns A promise resolving to the formatted folder structure string.
|
|
19
|
-
*/
|
|
20
|
-
private getFolderStructure;
|
|
21
|
-
private readFullStructure;
|
|
22
|
-
/**
|
|
23
|
-
* Reads the directory structure using BFS, respecting maxItems.
|
|
24
|
-
* @param node The current node in the reduced structure.
|
|
25
|
-
* @param indent The current indentation string.
|
|
26
|
-
* @param isLast Sibling indicator.
|
|
27
|
-
* @param builder Array to build the string lines.
|
|
28
|
-
*/
|
|
29
|
-
private formatStructure;
|
|
30
|
-
}
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.DirectoryContextModifier = void 0;
|
|
40
|
-
const base_1 = require("../base");
|
|
41
|
-
const fs = __importStar(require("node:fs/promises"));
|
|
42
|
-
const path = __importStar(require("node:path"));
|
|
43
|
-
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
44
|
-
const MAX_ITEMS = 200;
|
|
45
|
-
const TRUNCATION_INDICATOR = '...';
|
|
46
|
-
const DEFAULT_IGNORED_FOLDERS = new Set(['node_modules', '.git', 'dist']);
|
|
47
|
-
// Error handling utility (simplified version of gemini-cli's getErrorMessage)
|
|
48
|
-
function getErrorMessage(error) {
|
|
49
|
-
if (error instanceof Error) {
|
|
50
|
-
return error.message;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
return String(error);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return 'Failed to get error details';
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Node error type guard
|
|
60
|
-
function isNodeError(error) {
|
|
61
|
-
return error instanceof Error && 'code' in error;
|
|
62
|
-
}
|
|
63
|
-
class DirectoryContextModifier extends base_1.BaseMessageModifier {
|
|
64
|
-
constructor(options = {}) {
|
|
65
|
-
super();
|
|
66
|
-
this.options = {
|
|
67
|
-
workspaceDirectories: options.workspaceDirectories || []
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
async modify(originalRequest, createdMessage) {
|
|
71
|
-
try {
|
|
72
|
-
// Get workspace directories from codebolt or use provided options
|
|
73
|
-
let workspaceDirectories = this.options.workspaceDirectories;
|
|
74
|
-
if (!workspaceDirectories || workspaceDirectories.length === 0) {
|
|
75
|
-
const { projectPath } = await codeboltjs_1.default.project.getProjectPath();
|
|
76
|
-
workspaceDirectories = projectPath ? [projectPath] : [];
|
|
77
|
-
}
|
|
78
|
-
if (workspaceDirectories.length === 0) {
|
|
79
|
-
return createdMessage;
|
|
80
|
-
}
|
|
81
|
-
const folderStructures = await Promise.all(workspaceDirectories.map((dir) => this.getFolderStructure(dir)));
|
|
82
|
-
const folderStructure = folderStructures.join('\n');
|
|
83
|
-
let workingDirPreamble;
|
|
84
|
-
if (workspaceDirectories.length === 1) {
|
|
85
|
-
workingDirPreamble = `I'm currently working in the directory: ${workspaceDirectories[0]}`;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const dirList = workspaceDirectories.map((dir) => ` - ${dir}`).join('\n');
|
|
89
|
-
workingDirPreamble = `I'm currently working in the following directories:\n${dirList}`;
|
|
90
|
-
}
|
|
91
|
-
const directoryContext = `${workingDirPreamble}
|
|
92
|
-
Here is the folder structure of the current working directories:
|
|
93
|
-
|
|
94
|
-
${folderStructure}`;
|
|
95
|
-
const contextMessage = {
|
|
96
|
-
role: 'user', // Note: gemini-cli adds this as user message, not system
|
|
97
|
-
content: directoryContext
|
|
98
|
-
};
|
|
99
|
-
// Add as user message (like gemini-cli does)
|
|
100
|
-
const messages = [...createdMessage.message.messages, contextMessage];
|
|
101
|
-
return Promise.resolve({
|
|
102
|
-
message: {
|
|
103
|
-
...createdMessage.message,
|
|
104
|
-
messages
|
|
105
|
-
},
|
|
106
|
-
metadata: {
|
|
107
|
-
...createdMessage.metadata,
|
|
108
|
-
directoryContextAdded: true,
|
|
109
|
-
workspaceDirectories
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
console.error('Error in DirectoryContextModifier:', error);
|
|
115
|
-
return createdMessage;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Generates a string representation of a directory's structure,
|
|
120
|
-
* limiting the number of items displayed. Ignored folders are shown
|
|
121
|
-
* followed by '...' instead of their contents.
|
|
122
|
-
*
|
|
123
|
-
* @param directory The absolute or relative path to the directory.
|
|
124
|
-
* @param options Optional configuration settings.
|
|
125
|
-
* @returns A promise resolving to the formatted folder structure string.
|
|
126
|
-
*/
|
|
127
|
-
async getFolderStructure(directory, options) {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
const resolvedPath = path.resolve(directory);
|
|
130
|
-
const mergedOptions = {
|
|
131
|
-
maxItems: (_a = options === null || options === void 0 ? void 0 : options.maxItems) !== null && _a !== void 0 ? _a : MAX_ITEMS,
|
|
132
|
-
ignoredFolders: (_b = options === null || options === void 0 ? void 0 : options.ignoredFolders) !== null && _b !== void 0 ? _b : DEFAULT_IGNORED_FOLDERS,
|
|
133
|
-
fileIncludePattern: options === null || options === void 0 ? void 0 : options.fileIncludePattern,
|
|
134
|
-
};
|
|
135
|
-
try {
|
|
136
|
-
// 1. Read the structure using BFS, respecting maxItems
|
|
137
|
-
const structureRoot = await this.readFullStructure(resolvedPath, mergedOptions);
|
|
138
|
-
if (!structureRoot) {
|
|
139
|
-
return `Error: Could not read directory "${resolvedPath}". Check path and permissions.`;
|
|
140
|
-
}
|
|
141
|
-
// 2. Format the structure into a string
|
|
142
|
-
const structureLines = [];
|
|
143
|
-
// Pass true for isRoot for the initial call
|
|
144
|
-
this.formatStructure(structureRoot, '', true, true, structureLines);
|
|
145
|
-
// 3. Build the final output string
|
|
146
|
-
function isTruncated(node) {
|
|
147
|
-
if (node.hasMoreFiles || node.hasMoreSubfolders || node.isIgnored) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
for (const sub of node.subFolders) {
|
|
151
|
-
if (isTruncated(sub)) {
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
let summary = `Showing up to ${mergedOptions.maxItems} items (files + folders).`;
|
|
158
|
-
if (isTruncated(structureRoot)) {
|
|
159
|
-
summary += ` Folders or files indicated with ${TRUNCATION_INDICATOR} contain more items not shown, were ignored, or the display limit (${mergedOptions.maxItems} items) was reached.`;
|
|
160
|
-
}
|
|
161
|
-
return `${summary}\n\n${resolvedPath}${path.sep}\n${structureLines.join('\n')}`;
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
console.error(`Error getting folder structure for ${resolvedPath}:`, error);
|
|
165
|
-
return `Error processing directory "${resolvedPath}": ${getErrorMessage(error)}`;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async readFullStructure(rootPath, options) {
|
|
169
|
-
const rootName = path.basename(rootPath);
|
|
170
|
-
const rootNode = {
|
|
171
|
-
name: rootName,
|
|
172
|
-
path: rootPath,
|
|
173
|
-
files: [],
|
|
174
|
-
subFolders: [],
|
|
175
|
-
totalChildren: 0,
|
|
176
|
-
totalFiles: 0,
|
|
177
|
-
};
|
|
178
|
-
const queue = [
|
|
179
|
-
{ folderInfo: rootNode, currentPath: rootPath },
|
|
180
|
-
];
|
|
181
|
-
let currentItemCount = 0;
|
|
182
|
-
// Count the root node itself as one item if we are not just listing its content
|
|
183
|
-
const processedPaths = new Set(); // To avoid processing same path if symlinks create loops
|
|
184
|
-
while (queue.length > 0) {
|
|
185
|
-
const { folderInfo, currentPath } = queue.shift();
|
|
186
|
-
if (processedPaths.has(currentPath)) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
processedPaths.add(currentPath);
|
|
190
|
-
if (currentItemCount >= options.maxItems) {
|
|
191
|
-
// If the root itself caused us to exceed, we can't really show anything.
|
|
192
|
-
// Otherwise, this folder won't be processed further.
|
|
193
|
-
// The parent that queued this would have set its own hasMoreSubfolders flag.
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
let entries;
|
|
197
|
-
try {
|
|
198
|
-
const rawEntries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
199
|
-
// Sort entries alphabetically by name for consistent processing order
|
|
200
|
-
entries = rawEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
if (isNodeError(error) &&
|
|
204
|
-
(error.code === 'EACCES' || error.code === 'ENOENT')) {
|
|
205
|
-
console.warn(`Warning: Could not read directory ${currentPath}: ${error.message}`);
|
|
206
|
-
if (currentPath === rootPath && error.code === 'ENOENT') {
|
|
207
|
-
return null; // Root directory itself not found
|
|
208
|
-
}
|
|
209
|
-
// For other EACCES/ENOENT on subdirectories, just skip them.
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
const filesInCurrentDir = [];
|
|
215
|
-
const subFoldersInCurrentDir = [];
|
|
216
|
-
// Process files first in the current directory
|
|
217
|
-
for (const entry of entries) {
|
|
218
|
-
if (entry.isFile()) {
|
|
219
|
-
if (currentItemCount >= options.maxItems) {
|
|
220
|
-
folderInfo.hasMoreFiles = true;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
const fileName = entry.name;
|
|
224
|
-
if (!options.fileIncludePattern ||
|
|
225
|
-
options.fileIncludePattern.test(fileName)) {
|
|
226
|
-
filesInCurrentDir.push(fileName);
|
|
227
|
-
currentItemCount++;
|
|
228
|
-
folderInfo.totalFiles++;
|
|
229
|
-
folderInfo.totalChildren++;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
folderInfo.files = filesInCurrentDir;
|
|
234
|
-
// Then process directories and queue them
|
|
235
|
-
for (const entry of entries) {
|
|
236
|
-
if (entry.isDirectory()) {
|
|
237
|
-
// Check if adding this directory ITSELF would meet or exceed maxItems
|
|
238
|
-
// (currentItemCount refers to items *already* added before this one)
|
|
239
|
-
if (currentItemCount >= options.maxItems) {
|
|
240
|
-
folderInfo.hasMoreSubfolders = true;
|
|
241
|
-
break; // Already at limit, cannot add this folder or any more
|
|
242
|
-
}
|
|
243
|
-
// If adding THIS folder makes us hit the limit exactly, and it might have children,
|
|
244
|
-
// it's better to show '...' for the parent, unless this is the very last item slot.
|
|
245
|
-
// This logic is tricky. Let's try a simpler: if we can't add this item, mark and break.
|
|
246
|
-
const subFolderName = entry.name;
|
|
247
|
-
const subFolderPath = path.join(currentPath, subFolderName);
|
|
248
|
-
if (options.ignoredFolders.has(subFolderName)) {
|
|
249
|
-
const ignoredSubFolder = {
|
|
250
|
-
name: subFolderName,
|
|
251
|
-
path: subFolderPath,
|
|
252
|
-
files: [],
|
|
253
|
-
subFolders: [],
|
|
254
|
-
totalChildren: 0,
|
|
255
|
-
totalFiles: 0,
|
|
256
|
-
isIgnored: true,
|
|
257
|
-
};
|
|
258
|
-
subFoldersInCurrentDir.push(ignoredSubFolder);
|
|
259
|
-
currentItemCount++; // Count the ignored folder itself
|
|
260
|
-
folderInfo.totalChildren++; // Also counts towards parent's children
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
const subFolderNode = {
|
|
264
|
-
name: subFolderName,
|
|
265
|
-
path: subFolderPath,
|
|
266
|
-
files: [],
|
|
267
|
-
subFolders: [],
|
|
268
|
-
totalChildren: 0,
|
|
269
|
-
totalFiles: 0,
|
|
270
|
-
};
|
|
271
|
-
subFoldersInCurrentDir.push(subFolderNode);
|
|
272
|
-
currentItemCount++;
|
|
273
|
-
folderInfo.totalChildren++; // Counts towards parent's children
|
|
274
|
-
// Add to queue for processing its children later
|
|
275
|
-
queue.push({ folderInfo: subFolderNode, currentPath: subFolderPath });
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
folderInfo.subFolders = subFoldersInCurrentDir;
|
|
279
|
-
}
|
|
280
|
-
return rootNode;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Reads the directory structure using BFS, respecting maxItems.
|
|
284
|
-
* @param node The current node in the reduced structure.
|
|
285
|
-
* @param indent The current indentation string.
|
|
286
|
-
* @param isLast Sibling indicator.
|
|
287
|
-
* @param builder Array to build the string lines.
|
|
288
|
-
*/
|
|
289
|
-
formatStructure(node, currentIndent, isLastChildOfParent, isProcessingRootNode, builder) {
|
|
290
|
-
const connector = isLastChildOfParent ? '└───' : '├───';
|
|
291
|
-
// The root node of the structure (the one passed initially to getFolderStructure)
|
|
292
|
-
// is not printed with a connector line itself, only its name as a header.
|
|
293
|
-
// Its children are printed relative to that conceptual root.
|
|
294
|
-
// Ignored root nodes ARE printed with a connector.
|
|
295
|
-
if (!isProcessingRootNode || node.isIgnored) {
|
|
296
|
-
builder.push(`${currentIndent}${connector}${node.name}${path.sep}${node.isIgnored ? TRUNCATION_INDICATOR : ''}`);
|
|
297
|
-
}
|
|
298
|
-
// Determine the indent for the children of *this* node.
|
|
299
|
-
// If *this* node was the root of the whole structure, its children start with no indent before their connectors.
|
|
300
|
-
// Otherwise, children's indent extends from the current node's indent.
|
|
301
|
-
const indentForChildren = isProcessingRootNode
|
|
302
|
-
? ''
|
|
303
|
-
: currentIndent + (isLastChildOfParent ? ' ' : '│ ');
|
|
304
|
-
// Render files of the current node
|
|
305
|
-
const fileCount = node.files.length;
|
|
306
|
-
for (let i = 0; i < fileCount; i++) {
|
|
307
|
-
const isLastFileAmongSiblings = i === fileCount - 1 &&
|
|
308
|
-
node.subFolders.length === 0 &&
|
|
309
|
-
!node.hasMoreSubfolders;
|
|
310
|
-
const fileConnector = isLastFileAmongSiblings ? '└───' : '├───';
|
|
311
|
-
builder.push(`${indentForChildren}${fileConnector}${node.files[i]}`);
|
|
312
|
-
}
|
|
313
|
-
if (node.hasMoreFiles) {
|
|
314
|
-
const isLastIndicatorAmongSiblings = node.subFolders.length === 0 && !node.hasMoreSubfolders;
|
|
315
|
-
const fileConnector = isLastIndicatorAmongSiblings ? '└───' : '├───';
|
|
316
|
-
builder.push(`${indentForChildren}${fileConnector}${TRUNCATION_INDICATOR}`);
|
|
317
|
-
}
|
|
318
|
-
// Render subfolders of the current node
|
|
319
|
-
const subFolderCount = node.subFolders.length;
|
|
320
|
-
for (let i = 0; i < subFolderCount; i++) {
|
|
321
|
-
const isLastSubfolderAmongSiblings = i === subFolderCount - 1 && !node.hasMoreSubfolders;
|
|
322
|
-
// Children are never the root node being processed initially.
|
|
323
|
-
this.formatStructure(node.subFolders[i], indentForChildren, isLastSubfolderAmongSiblings, false, builder);
|
|
324
|
-
}
|
|
325
|
-
if (node.hasMoreSubfolders) {
|
|
326
|
-
builder.push(`${indentForChildren}└───${TRUNCATION_INDICATOR}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
exports.DirectoryContextModifier = DirectoryContextModifier;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ProcessedMessage } from "@codebolt/types/agent";
|
|
2
|
-
import { BaseMessageModifier } from "../base";
|
|
3
|
-
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
4
|
-
export interface EnvironmentContextOptions {
|
|
5
|
-
enableFullContext?: boolean;
|
|
6
|
-
maxFiles?: number;
|
|
7
|
-
maxFileSize?: number;
|
|
8
|
-
includePatterns?: string[];
|
|
9
|
-
excludePatterns?: string[];
|
|
10
|
-
}
|
|
11
|
-
export declare class EnvironmentContextModifier extends BaseMessageModifier {
|
|
12
|
-
private readonly options;
|
|
13
|
-
private readonly defaultExcludePatterns;
|
|
14
|
-
constructor(options?: EnvironmentContextOptions);
|
|
15
|
-
modify(originalRequest: FlatUserMessage, createdMessage: ProcessedMessage): Promise<ProcessedMessage>;
|
|
16
|
-
private generateFullContext;
|
|
17
|
-
private findRelevantFiles;
|
|
18
|
-
private walkDirectory;
|
|
19
|
-
private isExcluded;
|
|
20
|
-
private isIncluded;
|
|
21
|
-
private matchesPattern;
|
|
22
|
-
private countContextFiles;
|
|
23
|
-
enableFullContext(): void;
|
|
24
|
-
disableFullContext(): void;
|
|
25
|
-
isFullContextEnabled(): boolean;
|
|
26
|
-
}
|