@@ -7,7 +7,7 @@ import { createTextContent, createErrorResult, createSuccessResult, formatError,
77import { resolvePath } from '../utils';
88import { loadPrompt } from '../../../Core/PromptLoader';
99
10- const logger = LoggerService.getLogger('Tools/FileSystem/operations/mv .ts');
10+ const logger = LoggerService.getLogger('Tools/FileSystem/operations/move .ts');
1111
1212function moveOne(src: string, dst: string): void {
1313 try {
@@ -23,23 +23,28 @@ function moveOne(src: string, dst: string): void {
2323 }
2424}
2525
26- /** Move or rename files/ directories, like bash mv */
27- export function createMvTool (): StructuredToolInterface {
26+ /** Move/rename or copy files and directories, like bash mv / cp. Supports multiple sources. */
27+ export function createMoveTool (): StructuredToolInterface {
2828 return new DynamicStructuredTool({
29- name: 'mv ',
30- description: loadPrompt('tools/fs/mv .txt'),
29+ name: 'move ',
30+ description: loadPrompt('tools/fs/move .txt'),
3131 schema: z.object({
3232 sources: z.array(z.string()).min(1).describe('One or more absolute source paths'),
3333 dest: z.string().describe('Absolute destination path (directory or new name)'),
34- noClobber: z.boolean().optional().default(false).describe('Do not overwrite existing files (-n), default false'),
34+ copy: z.boolean().optional().default(false).describe('Copy instead of move (cp). Default false (mv)'),
35+ recursive: z.boolean().optional().default(false).describe('Copy directories recursively (-r). Only meaningful with copy=true. Default false'),
36+ overwrite: z.boolean().optional().default(true).describe('Overwrite existing destination files. Default true (matches bash mv/cp)'),
3537 }) as any,
36- func: async ({ sources, dest, noClobber = false }: any): Promise<MCPToolResult> => {
38+ func: async ({ sources, dest, copy = false, recursive = false, overwrite = true }: any): Promise<MCPToolResult> => {
3739 try {
3840 const srcs = (sources as string[]).map(resolvePath);
3941 const dst = resolvePath(dest);
4042
4143 for (const src of srcs) {
4244 if (!fs.existsSync(src)) throw new Error(`Source path does not exist: ${src}`);
45+ if (copy && fs.statSync(src).isDirectory() && !recursive) {
46+ return createErrorResult(`${src} is a directory. Set recursive=true to copy directories`);
47+ }
4348 }
4449
4550 const dstExists = fs.existsSync(dst);
@@ -54,21 +59,25 @@ export function createMvTool(): StructuredToolInterface {
5459 for (const src of srcs) {
5560 const finalDst = dstIsDir ? path.join(dst, path.basename(src)) : dst;
5661
57- if (fs.existsSync(finalDst) && noClobber ) {
62+ if (fs.existsSync(finalDst) && !overwrite ) {
5863 results.push(`Skipped (destination already exists): ${finalDst}`);
5964 continue;
6065 }
6166
6267 const parentDir = path.dirname(finalDst);
6368 if (!fs.existsSync(parentDir)) fs.mkdirSync(parentDir, { recursive: true });
6469
65- moveOne(src, finalDst);
70+ if (copy) {
71+ fs.cpSync(src, finalDst, { recursive, force: overwrite });
72+ } else {
73+ moveOne(src, finalDst);
74+ }
6675 results.push(`${src} -> ${finalDst}`);
6776 }
6877
6978 return createSuccessResult(createTextContent(results.join('\n')));
7079 } catch (e: any) {
71- logger.error(`mv : ${formatError(e, true)}`);
80+ logger.error(`move : ${formatError(e, true)}`);
7281 return createErrorResult(formatError(e));
7382 }
7483 }
0 commit comments