planFileMove
Plan file moves or renames while automatically updating all TypeScript import paths. Returns an edit plan and move suggestions without making any changes to the filesystem, enabling safe preview of refactoring operations.
Instructions
Plan file move/rename with import path updates. Returns edit plans and file move suggestions without modifying the filesystem.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectRoot | No | Optional base directory for resolving relative paths and limiting tsconfig discovery | |
| workspaceRoot | No | Optional monorepo root used to search multiple tsconfig.json files | |
| tsconfigPath | No | Optional explicit tsconfig.json path for the primary project | |
| oldPath | Yes | Absolute path or path relative to projectRoot/workspaceRoot of the file to move | |
| newPath | Yes | Absolute path or path relative to projectRoot/workspaceRoot of the destination |
Implementation Reference
- src/tools/planFileMove.ts:20-62 (handler)Core handler that resolves paths, collects TypeScript services, runs getEditsForFileRename across projects, and returns edit plans with file move suggestions.
export function planFileMove(params: PlanFileMoveParams): PlanFileMoveResult { const baseDir = path.resolve( params.workspaceRoot ?? params.projectRoot ?? process.cwd() ); // 1. oldPath / newPath を絶対パスに正規化 const oldAbs = resolveInputPath(params.oldPath, baseDir); const newAbs = resolveInputPath(params.newPath, baseDir); const candidateContexts = collectWorkspaceTsServices([oldAbs, newAbs], { projectRoot: params.projectRoot, workspaceRoot: params.workspaceRoot, tsconfigPath: params.tsconfigPath, primaryFilePath: oldAbs, }); const editBucket = createEditBucket(); // 2. 各 TS プロジェクトで getEditsForFileRename を実行し、結果をマージ for (const context of candidateContexts) { const fileTextChanges = context.service.getEditsForFileRename( oldAbs, newAbs, {}, {} ); addFileTextChanges(editBucket, context.tsModule, fileTextChanges); } const edits = toFileTextEdits(editBucket); // 3. fsMoves として 1 件追加 const fsMoves = [ { from: oldAbs, to: newAbs, }, ]; // 7. 結果を返す return { edits, fsMoves, }; } - src/types.ts:77-83 (schema)Input parameter type for planFileMove: workspace/project roots, optional tsconfig path, oldPath and newPath for the file move.
export type PlanFileMoveParams = { projectRoot?: string; // 旧互換: 相対パスの解決基準 / ワークスペース境界 workspaceRoot?: string; // monorepo 全体を探索するためのルート tsconfigPath?: string; // 移動元ファイルの所属 tsconfig を明示したい場合 oldPath: string; // 元ファイルパス newPath: string; // 移動先ファイルパス }; - src/types.ts:88-91 (schema)Output result type: list of text edits to update imports, and fsMoves for actual file system moves.
export type PlanFileMoveResult = { edits: FileTextEdits[]; fsMoves: FsMove[]; // 通常は 1 件だけ }; - src/index.ts:79-111 (registration)Tool registration in the TOOLS array with name 'planFileMove' and its input schema definition.
{ name: "planFileMove", description: "Plan file move/rename with import path updates. Returns edit plans and file move suggestions without modifying the filesystem.", inputSchema: { type: "object", properties: { projectRoot: { type: "string", description: "Optional base directory for resolving relative paths and limiting tsconfig discovery", }, workspaceRoot: { type: "string", description: "Optional monorepo root used to search multiple tsconfig.json files", }, tsconfigPath: { type: "string", description: "Optional explicit tsconfig.json path for the primary project", }, oldPath: { type: "string", description: "Absolute path or path relative to projectRoot/workspaceRoot of the file to move", }, newPath: { type: "string", description: "Absolute path or path relative to projectRoot/workspaceRoot of the destination", }, }, required: ["oldPath", "newPath"], }, - src/index.ts:192-203 (registration)Call handler in the switch statement: dispatches to planFileMove when the tool name matches.
case "planFileMove": { const params = args as unknown as PlanFileMoveParams; const result = planFileMove(params); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }