// =============================================================================
// save_memory tool registration. Logic lives in ./memory-api.ts.
// In-process: appends to ctx.memoryUpdates so the supervisor loop can persist
// at end-of-turn. MCP server path uses memory-api's internal store.
// =============================================================================

import { registerTool } from './registry';
import * as api from './memory-api';

registerTool({
    name: 'save_memory',
    description: 'Persist an important fact about this project to long-term memory. Use this to save decisions, tech stack choices, feature descriptions, constraints, or goals so they are remembered across conversations.',
    parameters: {
        type: 'object',
        properties: {
            key: { type: 'string', description: 'Short unique label (e.g. "primary_language", "auth_strategy", "deploy_target")' },
            type: {
                type: 'string',
                enum: ['tech_stack', 'decision', 'feature', 'goal', 'constraint', 'note'],
                description: 'Category of the memory item'
            },
            value: { type: 'string', description: 'The fact to remember (1-3 sentences)' }
        },
        required: ['key', 'type', 'value']
    },
    async handler(args, ctx) {
        const entry = api.toEntry({
            key: String(args.key),
            type: String(args.type),
            value: String(args.value),
        });
        ctx.memoryUpdates.push(entry);
        return { saved: true, key: entry.key, type: entry.type };
    }
});
