/**
 * Process Tool Adapters
 *
 * ITool-compliant adapter for ProcessTool operations.
 * Follows the docker-tools.ts pattern for the FormalToolRegistry.
 */
import { getProcessTool } from '../process-tool.js';
// ============================================================================
// ProcessOperationTool
// ============================================================================
export class ProcessOperationTool {
    name = 'process';
    description = 'Manage system processes: list, poll, log, write stdin, kill, clear logs, remove tracking';
    async execute(input) {
        const action = input.action;
        const args = input.args || {};
        const tool = getProcessTool();
        switch (action) {
            case 'list':
                return await tool.list(args.filter);
            case 'poll':
                return await tool.poll(args.pid);
            case 'log':
                return await tool.log(args.pid, {
                    lines: args.lines,
                    stderr: args.stderr,
                });
            case 'write':
                return await tool.write(args.pid, args.input);
            case 'kill':
                return await tool.kill(args.pid, args.signal);
            case 'clear':
                return await tool.clear(args.pid);
            case 'remove':
                return await tool.remove(args.pid);
            default:
                return {
                    success: false,
                    error: `Unknown process action: ${action}`,
                };
        }
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    action: {
                        type: 'string',
                        description: 'Process action to perform',
                        enum: ['list', 'poll', 'log', 'write', 'kill', 'clear', 'remove'],
                    },
                    args: {
                        type: 'object',
                        description: 'Action-specific arguments',
                        properties: {
                            pid: {
                                type: 'number',
                                description: 'Process ID (required for poll, log, write, kill, clear, remove)',
                            },
                            filter: {
                                type: 'string',
                                description: 'Filter string for list action',
                            },
                            input: {
                                type: 'string',
                                description: 'Input to write to process stdin (for write action)',
                            },
                            signal: {
                                type: 'string',
                                description: 'Signal to send (for kill action, default: SIGTERM)',
                            },
                            lines: {
                                type: 'number',
                                description: 'Number of log lines to show (for log action, default: 100)',
                            },
                            stderr: {
                                type: 'boolean',
                                description: 'Show stderr instead of stdout (for log action)',
                            },
                        },
                    },
                },
                required: ['action'],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        const data = input;
        if (typeof data.action !== 'string' || data.action.trim() === '') {
            return { valid: false, errors: ['action must be a non-empty string'] };
        }
        const validActions = ['list', 'poll', 'log', 'write', 'kill', 'clear', 'remove'];
        if (!validActions.includes(data.action)) {
            return { valid: false, errors: [`Unknown action: ${data.action}`] };
        }
        // Validate pid is present for actions that require it
        const pidActions = ['poll', 'log', 'write', 'kill', 'clear', 'remove'];
        if (pidActions.includes(data.action)) {
            const args = data.args;
            if (!args || typeof args.pid !== 'number') {
                return { valid: false, errors: [`Action "${data.action}" requires args.pid (number)`] };
            }
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'system',
            keywords: ['process', 'pid', 'kill', 'stdin', 'log', 'managed'],
            priority: 5,
            requiresConfirmation: true,
            modifiesFiles: false,
            makesNetworkRequests: false,
        };
    }
    isAvailable() {
        return true;
    }
    dispose() {
        // No cleanup needed
    }
}
// ============================================================================
// Factory
// ============================================================================
export function createProcessTools() {
    return [new ProcessOperationTool()];
}
export async function resetProcessInstance() {
    const { resetProcessTool } = await import('../process-tool.js');
    resetProcessTool();
}
//# sourceMappingURL=process-tools.js.map