diff --git a/src/kimi_cli/tools/file/write.py b/src/kimi_cli/tools/file/write.py index f6dd53229..eaaa2e9d2 100644 --- a/src/kimi_cli/tools/file/write.py +++ b/src/kimi_cli/tools/file/write.py @@ -61,14 +61,9 @@ async def __call__(self, params: Params) -> ToolReturnValue: try: p = KaosPath(params.path) + # Auto-resolve relative paths to working directory if not p.is_absolute(): - return ToolError( - message=( - f"`{params.path}` is not an absolute path. " - "You must provide an absolute path to write a file." - ), - brief="Invalid path", - ) + p = self._work_dir / params.path # Validate path safety path_error = await self._validate_path(p) diff --git a/tests/test_write_file.py b/tests/test_write_file.py index 95069af3f..8623bc235 100644 --- a/tests/test_write_file.py +++ b/tests/test_write_file.py @@ -96,12 +96,14 @@ async def test_write_multiline_content(write_file_tool: WriteFile, temp_work_dir assert await file_path.read_text() == content -async def test_write_with_relative_path(write_file_tool: WriteFile): - """Test writing with a relative path (should fail).""" - result = await write_file_tool(Params(path="relative/path/file.txt", content="content")) +async def test_write_with_relative_path(write_file_tool: WriteFile, temp_work_dir: KaosPath): + """Test writing with a relative path (should auto-resolve to work directory).""" + result = await write_file_tool(Params(path="test_relative.txt", content="content")) - assert result.is_error - assert "not an absolute path" in result.message + assert not result.is_error + created_file = temp_work_dir / "test_relative.txt" + assert await created_file.exists() + assert await created_file.read_text() == "content" async def test_write_outside_work_directory(write_file_tool: WriteFile, outside_file: Path):