import { z } from 'zod';
import { simctl } from '../executor/simctl.js';
import { resolveDevice } from '../utils/device-resolver.js';
export const bootSchema = z.object({
device: z
.string()
.describe('Device UDID or name to boot'),
});
export type BootInput = z.infer<typeof bootSchema>;
export const bootTool = {
name: 'simctl_boot',
description: 'Boot a simulator device',
inputSchema: bootSchema,
handler: async (input: BootInput) => {
const udid = resolveDevice(input.device);
const result = simctl('boot', [udid]);
if (result.exitCode !== 0) {
// "Unable to boot device in current state: Booted" is not an error
if (result.stderr.includes('current state: Booted')) {
return {
content: [
{
type: 'text' as const,
text: `Device ${input.device} is already booted`,
},
],
};
}
throw new Error(`Failed to boot device: ${result.stderr || result.stdout}`);
}
return {
content: [
{
type: 'text' as const,
text: `Successfully booted device ${input.device}`,
},
],
};
},
};