import { z } from 'zod';
import { processManager } from '../../lib/processManager.js';
import { errorResult, jsonResult, toErrorMessage } from '../shared.js';
export function registerProcessControlTools(server) {
    server.registerTool('stop_process', {
        title: 'Stop Process',
        description: 'Stop a previously started background process (a dev server from start_dev_server, or a backgrounded run_script call).',
        inputSchema: { processId: z.string() },
    }, async ({ processId }) => {
        try {
            return jsonResult(processManager.stop(processId));
        }
        catch (error) {
            return errorResult(toErrorMessage(error));
        }
    });
    server.registerTool('get_process_logs', {
        title: 'Get Process Logs',
        description: 'Fetch buffered stdout/stderr output and current status for a background process started by start_dev_server or run_script.',
        inputSchema: {
            processId: z.string(),
            tail: z.number().int().positive().optional().describe('Only return the last N log lines.'),
        },
    }, async ({ processId, tail }) => {
        try {
            const { info, logs } = processManager.getLogs(processId, tail);
            return jsonResult({ ...info, logs });
        }
        catch (error) {
            return errorResult(toErrorMessage(error));
        }
    });
    server.registerTool('list_processes', {
        title: 'List Processes',
        description: 'List every background process tracked by this server (dev servers, backgrounded scripts) with their current status.',
        inputSchema: {},
    }, async () => jsonResult({ processes: processManager.list() }));
}
//# sourceMappingURL=processControls.js.map