"use strict";
// =============================================================================
// Pure Agent - Memory Tool
// Ported from Hermes tools/memory_tool.py
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerMemoryTool = registerMemoryTool;
const tool_registry_1 = require("./tool-registry");
const result_types_1 = require("./result-types");
const memory_store_1 = require("./memory-store");
// ---------------------------------------------------------------------------
// Memory tool handler
// ---------------------------------------------------------------------------
async function memoryHandler(args, _context) {
    const { action, target = 'memory', content, old_text } = args;
    if (!action)
        return (0, result_types_1.toolError)('Missing required parameter: action');
    const store = (0, memory_store_1.getMemoryStore)();
    switch (action) {
        case 'add': {
            if (!content)
                return (0, result_types_1.toolError)('Missing required parameter: content for add action');
            const result = store.add(target, content);
            return JSON.stringify(result);
        }
        case 'replace': {
            if (!old_text)
                return (0, result_types_1.toolError)('Missing required parameter: old_text for replace action');
            if (!content)
                return (0, result_types_1.toolError)('Missing required parameter: content for replace action');
            const result = store.replace(target, old_text, content);
            return JSON.stringify(result);
        }
        case 'remove': {
            if (!old_text)
                return (0, result_types_1.toolError)('Missing required parameter: old_text for remove action');
            const result = store.remove(target, old_text);
            return JSON.stringify(result);
        }
        default:
            return (0, result_types_1.toolError)(`Unknown action: ${action}. Valid actions: add, replace, remove`);
    }
}
// ---------------------------------------------------------------------------
// Registration
// ---------------------------------------------------------------------------
function registerMemoryTool() {
    tool_registry_1.registry.register({
        name: 'memory',
        toolset: 'memory',
        schema: {
            description: `Manage persistent memory across sessions. Two targets:
- "memory": General notes, facts, preferences, decisions (max 2200 chars)
- "user": User profile information (max 1375 chars)

Actions:
- add: Add a new entry (provide content)
- replace: Update an existing entry (provide old_text to match + new content)
- remove: Remove an entry (provide old_text to match)

Entries persist across sessions. Use for remembering user preferences, project context, decisions, and facts not obvious from code.`,
            parameters: {
                type: 'object',
                properties: {
                    action: {
                        type: 'string',
                        enum: ['add', 'replace', 'remove'],
                        description: 'The action to perform',
                    },
                    target: {
                        type: 'string',
                        enum: ['memory', 'user'],
                        description: 'Which memory store to operate on. Default: memory',
                        default: 'memory',
                    },
                    content: {
                        type: 'string',
                        description: 'The content to add or replace with',
                    },
                    old_text: {
                        type: 'string',
                        description: 'Text to match for replace/remove (substring match)',
                    },
                },
                required: ['action'],
            },
        },
        handler: memoryHandler,
        isAsync: true,
        description: 'Manage persistent memory',
        emoji: '🧠',
    });
}
// Auto-register
registerMemoryTool();
//# sourceMappingURL=memory-tool.js.map