Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cobolt-backend/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function main() {
});

console.log("Chat with AI (type 'exit' to quit)");
console.log("Available modes: chat, contextaware");
console.log("Available modes: chat, contextaware, conductor");
console.log("Usage: /mode <mode> to switch modes (e.g. /mode contextaware)");

const askQuestion = (): Promise<string> => {
Expand All @@ -21,7 +21,7 @@ async function main() {
});
};

let currentMode: 'CHAT' | 'CONTEXT_AWARE' = 'CHAT';
let currentMode: 'CHAT' | 'CONTEXT_AWARE' | 'CONDUCTOR' = 'CONDUCTOR';
const chatHistory = new ChatHistory();

try {
Expand All @@ -36,12 +36,12 @@ async function main() {

if (userInput.startsWith('/mode ')) {
const mode = userInput.slice(6).toUpperCase();
if (['CHAT', 'CONTEXT_AWARE'].includes(mode)) {
currentMode = mode as 'CHAT' | 'CONTEXT_AWARE';
if (['CHAT', 'CONTEXT_AWARE', 'CONDUCTOR'].includes(mode)) {
currentMode = mode as 'CHAT' | 'CONTEXT_AWARE' | 'CONDUCTOR';
console.log(`Switched to ${currentMode} mode`);
continue;
} else {
console.log("Invalid mode. Available modes: chat, contextaware");
console.log("Invalid mode. Available modes: chat, contextaware, conductor");
continue;
}
}
Expand Down
33 changes: 31 additions & 2 deletions src/cobolt-backend/chat_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,44 @@ class ChatHistory {

/**
* Convert chat history to format used by Ollama LLM
* @returns Array of Message objects in Ollama format
* Removes execution event metadata from AI context
* @returns Array of Message objects in Ollama format with clean content
*/
toOllamaMessages(): Message[] {
return this.messages.map(message => ({
role: message.role,
content: message.content
content: this.cleanContentForAI(message.content)
}));
}

/**
* Clean content for AI context - removes ALL execution metadata
* This prevents AI from learning how to fake execution patterns
*/
private cleanContentForAI(content: string): string {
let cleaned = content;

// AGGRESSIVE CLEANING: Remove ALL XML-like tags that start with these patterns
cleaned = cleaned.replace(/<execution_event\b[^>]*>.*?<\/execution_event>/gs, '');
cleaned = cleaned.replace(/<tool_call_position\b[^>]*>/g, '');
cleaned = cleaned.replace(/<tool_calls_update\b[^>]*>.*?<\/tool_calls_update>/gs, '');
cleaned = cleaned.replace(/<tool_calls_complete\b[^>]*>.*?<\/tool_calls_complete>/gs, '');
cleaned = cleaned.replace(/<tool_calls\b[^>]*>.*?<\/tool_calls>/gs, '');

// Remove standalone closing tags that might be left behind
cleaned = cleaned.replace(/<\/(?:execution_event|tool_calls_update|tool_calls_complete|tool_calls|tool_call_position)>/g, '');

// Remove any remaining XML-like execution metadata
cleaned = cleaned.replace(/<[^>]*(?:execution|tool_call|metadata|event)[^>]*>.*?<\/[^>]+>/gs, '');

// Clean up any excessive whitespace left behind
cleaned = cleaned.replace(/\n\s*\n\s*\n/g, '\n\n');
cleaned = cleaned.replace(/^\s+|\s+$/gm, ''); // Trim each line
cleaned = cleaned.trim();

return cleaned;
}

/**
* Clear the chat history
*/
Expand Down
9 changes: 9 additions & 0 deletions src/cobolt-backend/data_models/app_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Store from 'electron-store';
type AppMetadataSchema = {
setupComplete: boolean;
memoryEnabled: boolean;
conductorEnabled: boolean;
};

interface TypedStore<T extends Record<string, any>> extends Store<T> {
Expand All @@ -16,6 +17,7 @@ const store = new Store<AppMetadataSchema>({
defaults: {
setupComplete: false,
memoryEnabled: false,
conductorEnabled: true,
},
}) as TypedStore<AppMetadataSchema>;

Expand All @@ -40,6 +42,13 @@ const appMetadata = {
setMemoryEnabled: (enabled: boolean) => {
store.set('memoryEnabled', enabled);
},
getConductorEnabled: (): boolean => {
return store.get('conductorEnabled');
},

setConductorEnabled: (enabled: boolean) => {
store.set('conductorEnabled', enabled);
},
};

export default appMetadata;
Loading