Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/kimi_cli/tools/file/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions tests/test_write_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down