import { z } from 'zod';
import { simctl } from '../executor/simctl.js';
import { resolveDevice } from '../utils/device-resolver.js';
export const terminateSchema = z.object({
device: z
.string()
.describe('Device UDID, name, or "booted"'),
bundle_id: z
.string()
.describe('Bundle identifier of the app to terminate'),
});
export type TerminateInput = z.infer<typeof terminateSchema>;
export const terminateTool = {
name: 'simctl_terminate',
description: 'Terminate a running app on a simulator without shutting down the simulator',
inputSchema: terminateSchema,
handler: async (input: TerminateInput) => {
const udid = resolveDevice(input.device);
const result = simctl('terminate', [udid, input.bundle_id]);
if (result.exitCode !== 0) {
throw new Error(`Failed to terminate app: ${result.stderr || result.stdout}`);
}
return {
content: [
{
type: 'text' as const,
text: `Successfully terminated ${input.bundle_id} on device ${input.device}`,
},
],
};
},
};