import { z } from 'zod';
import * as fileSystem from '../core/fileSystem';
import * as search from '../core/search';
import * as commands from '../core/commands';
import * as apps from '../core/apps';
import * as clipboard from '../core/clipboard';
import * as kv from '../core/kv';
import { createErrorResponse, ErrorCodes } from '../utils/errors';
/**
* File system tools
*/
export const ListFilesInputSchema = z.object({
path: z.string(),
recursive: z.boolean().optional().default(false),
});
export async function listFilesTool(input: z.infer<typeof ListFilesInputSchema>) {
try {
const items = await fileSystem.listDirectory(input.path, input.recursive);
return {
content: [
{
type: 'text',
text: JSON.stringify({ success: true, items }, null, 2),
},
],
};
} catch (error) {
return {
content: [createErrorResponse(ErrorCodes.INTERNAL_ERROR, String(error))],
};
}
}
export const ReadFileInputSchema = z.object({
path: z.string(),
});
export async function readFileTool(input: z.infer<typeof ReadFileInputSchema>) {
try {
const content = await fileSystem.readFileContents(input.path);
return {
content: [
{
type: 'text',
text: JSON.stringify({ success: true, content, size: content.length }, null, 2),
},
],
};
} catch (error) {
return {
content: [createErrorResponse(ErrorCodes.FILE_NOT_FOUND, String(error))],
};
}
}
export const WriteFileInputSchema = z.object({
path: z.string(),
content: z.string(),
});
export async function writeFileTool(input: z.infer<typeof WriteFileInputSchema>) {
try {
await fileSystem.writeFileContents(input.path, input.content);
return {
content: [
{
type: 'text',
text: JSON.stringify({ success: true, message: `File written: ${input.path}` }),
},
],
};
} catch (error) {
return {
content: [createErrorResponse(ErrorCodes.INTERNAL_ERROR, String(error))],
};
}
}
export const DeleteFileInputSchema = z.object({
path: z.string(),
recursive: z.boolean().optional().default(false),
});
export async function deleteFileTool(input: z.infer<typeof DeleteFileInputSchema>) {
try {
await fileSystem.deleteFileOrDirectory(input.path, input.recursive);
return {
content: [
{
type: 'text',
text: JSON.stringify({ success: true, message: `Deleted: ${input.path}` }),
},
],
};
} catch (error) {
return {
content: [createErrorResponse(ErrorCodes.INTERNAL_ERROR, String(error))],
};
}
}
export const MoveFileInputSchema = z.object({
sourcePath: z.string(),
destPath: z.string(),
});
export async function moveFileTool(input: z.infer<typeof MoveFileInputSchema>) {
try {
await fileSystem.moveFile(input.sourcePath, input.destPath);
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
message: `Moved: ${input.sourcePath} → ${input.destPath}`,
}),
},
],
};
} catch (error) {
return {
content: [createErrorResponse(ErrorCodes.INTERNAL_ERROR, String(error))],
};
}
}