write-to-file-tool 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: write_to_file_tool
3
+ Version: 0.1.0
4
+ Summary: Create a new file and write the given content to it.
5
+ Requires-Python: >=3.13
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: openchadpy>=0.1.23
File without changes
@@ -0,0 +1,9 @@
1
+ [project]
2
+ name = "write_to_file_tool"
3
+ version = "0.1.0"
4
+ description = "Create a new file and write the given content to it."
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "openchadpy>=0.1.23",
9
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,89 @@
1
+ """
2
+ write_to_file Tool
3
+ ==================
4
+ Create a new file and write content to it.
5
+ Parent directories are created automatically when they don't exist.
6
+
7
+ Parameters:
8
+ path - Absolute path of the file to create (required).
9
+ content - Full text content to write to the file (required).
10
+ overwrite - If true, an existing file will be replaced entirely.
11
+ Defaults to false; will error if the file already exists.
12
+ """
13
+
14
+ import logging
15
+ import os
16
+ from typing import Any, Dict
17
+
18
+ from openchadpy.tool_base import ToolBase
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+
23
+ class Tool(ToolBase):
24
+ name = "write_to_file"
25
+ description = (
26
+ "Create a new file and write the given content to it. "
27
+ "Parent directories are created automatically. "
28
+ "Set overwrite=true to replace an existing file."
29
+ )
30
+ input_schema = {
31
+ "type": "object",
32
+ "properties": {
33
+ "path": {
34
+ "type": "string",
35
+ "description": "Absolute path of the file to create.",
36
+ },
37
+ "content": {
38
+ "type": "string",
39
+ "description": "Full text content to write to the file.",
40
+ },
41
+ "overwrite": {
42
+ "type": "boolean",
43
+ "description": (
44
+ "When true, an existing file is replaced entirely. "
45
+ "When false (default), returns an error if the file already exists."
46
+ ),
47
+ },
48
+ },
49
+ "required": ["path", "content"],
50
+ }
51
+ allowed_callers = ["direct", "code_execution"]
52
+
53
+ async def execute(self, **kwargs) -> Dict[str, Any]:
54
+ path: str = kwargs.get("path", "").strip()
55
+ content: str = kwargs.get("content", "")
56
+ overwrite: bool = bool(kwargs.get("overwrite", False))
57
+
58
+ if not path:
59
+ return {"error": "path is required and must not be empty."}
60
+
61
+ if os.path.exists(path) and not overwrite:
62
+ return {
63
+ "error": (
64
+ f"File already exists: {path!r}. "
65
+ "Set overwrite=true to replace it."
66
+ )
67
+ }
68
+
69
+ try:
70
+ parent_dir = os.path.dirname(path)
71
+ if parent_dir:
72
+ os.makedirs(parent_dir, exist_ok=True)
73
+
74
+ with open(path, "w", encoding="utf-8") as f:
75
+ f.write(content)
76
+
77
+ size_bytes = os.path.getsize(path)
78
+ line_count = content.count("\n") + (1 if content and not content.endswith("\n") else 0)
79
+
80
+ logger.info(f"[write_to_file] wrote {size_bytes} bytes to {path!r}")
81
+ return {
82
+ "path": path,
83
+ "size_bytes": size_bytes,
84
+ "lines_written": line_count,
85
+ "overwritten": os.path.exists(path) and overwrite,
86
+ }
87
+ except Exception as e:
88
+ logger.error(f"[write_to_file] failed to write {path!r}: {e}")
89
+ return {"error": f"Failed to write file: {e}"}
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: write_to_file_tool
3
+ Version: 0.1.0
4
+ Summary: Create a new file and write the given content to it.
5
+ Requires-Python: >=3.13
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: openchadpy>=0.1.23
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ write_to_file_tool/__init__.py
4
+ write_to_file_tool/main.py
5
+ write_to_file_tool.egg-info/PKG-INFO
6
+ write_to_file_tool.egg-info/SOURCES.txt
7
+ write_to_file_tool.egg-info/dependency_links.txt
8
+ write_to_file_tool.egg-info/requires.txt
9
+ write_to_file_tool.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ openchadpy>=0.1.23
@@ -0,0 +1 @@
1
+ write_to_file_tool