axio-tools-local 0.1.0__py3-none-any.whl

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,6 @@
1
+ from typing import Any
2
+
3
+
4
+ def _short(value: Any, limit: int = 60) -> str:
5
+ s = str(value)
6
+ return s if len(s) <= limit else s[:limit] + "..."
@@ -0,0 +1,36 @@
1
+ import asyncio
2
+ import os
3
+ import stat as stat_module
4
+ from datetime import datetime
5
+ from pathlib import Path
6
+
7
+ from axio.tool import ToolHandler
8
+
9
+
10
+ class ListFiles(ToolHandler):
11
+ """List files and directories. Shows permissions, size, modification time,
12
+ and name for each entry. Directories are listed first and marked with
13
+ a trailing slash. Use this to explore the project structure before
14
+ reading or editing files."""
15
+
16
+ directory: str = "."
17
+
18
+ def __repr__(self) -> str:
19
+ return f"ListFiles(directory={self.directory!r})"
20
+
21
+ def _blocking(self) -> str:
22
+ path = Path(os.getcwd()) / self.directory
23
+ if not path.is_dir():
24
+ raise FileNotFoundError(f"{self.directory} is not a valid directory")
25
+ lines: list[str] = []
26
+ for fpath in sorted(path.glob("*"), key=lambda p: (not p.is_dir(), p.name)):
27
+ st = fpath.stat()
28
+ mode = stat_module.filemode(st.st_mode)
29
+ size = st.st_size
30
+ mtime = datetime.fromtimestamp(st.st_mtime).strftime("%b %d %H:%M")
31
+ name = fpath.name + ("/" if fpath.is_dir() else "")
32
+ lines.append(f"{mode} {size:>8} {mtime} {name}")
33
+ return "\n".join(lines) or "(empty directory)"
34
+
35
+ async def __call__(self) -> str:
36
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,46 @@
1
+ import asyncio
2
+ import os
3
+ from pathlib import Path
4
+
5
+ from axio.tool import ToolHandler
6
+
7
+
8
+ class PatchFile(ToolHandler):
9
+ """Replace a range of lines in an existing file. Lines are 0-indexed:
10
+ from_line is inclusive, to_line is exclusive. The content string replaces
11
+ lines[from_line:to_line]. Always read the file first to get correct
12
+ line numbers. Use this for surgical edits instead of rewriting the
13
+ whole file with write_file."""
14
+
15
+ file_path: str
16
+ mode: int = 0o644
17
+ from_line: int
18
+ to_line: int
19
+ content: str
20
+
21
+ def __repr__(self) -> str:
22
+ return (
23
+ f"PatchFile(file_path={self.file_path!r},"
24
+ f" lines={self.from_line}:{self.to_line}, content=<{len(self.content)} chars>)"
25
+ )
26
+
27
+ def _blocking(self) -> str:
28
+ path = Path(os.getcwd()) / self.file_path
29
+ if not path.is_file():
30
+ raise FileNotFoundError(f"{self.file_path} is not a valid file")
31
+
32
+ # read all lines
33
+ with path.open("r") as f:
34
+ lines = f.readlines()
35
+
36
+ # content lines
37
+ content = self.content.splitlines()
38
+
39
+ # patch lines
40
+ new_lines = lines[: self.from_line] + content + lines[self.to_line :]
41
+ with path.open("w") as f:
42
+ f.writelines(new_lines)
43
+ return f"{f.tell()} bytes written to {self.file_path}"
44
+
45
+ async def __call__(self) -> str:
46
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,41 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+
7
+ class ReadFile(ToolHandler):
8
+ """Read file contents. Returns text for text files, hex for binaries.
9
+ Use start_line/end_line to read a specific range of lines (0-indexed).
10
+ Large files are truncated to max_chars. Always read the file before
11
+ editing it with write_file or patch_file."""
12
+
13
+ filename: str
14
+ max_chars: int = 32768
15
+ binary_as_hex: bool = True
16
+ start_line: int | None = None
17
+ end_line: int | None = None
18
+
19
+ def __repr__(self) -> str:
20
+ return f"ReadFile(filename={self.filename!r})"
21
+
22
+ def _blocking(self) -> str:
23
+ path = os.path.join(os.getcwd(), self.filename)
24
+ if self.start_line is None and self.end_line is None:
25
+ with open(path, "rb") as f:
26
+ result = f.read(self.max_chars)
27
+ try:
28
+ return result.decode()
29
+ except UnicodeDecodeError:
30
+ if self.binary_as_hex:
31
+ return "Encoded binary data HEX: " + result.hex()
32
+ raise
33
+ with open(path) as f:
34
+ lines = f.readlines()[self.start_line : self.end_line]
35
+ content = "".join(lines)
36
+ if len(content) > self.max_chars:
37
+ return content[: self.max_chars] + "\n...[truncated]"
38
+ return content.strip()
39
+
40
+ async def __call__(self) -> str:
41
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,56 @@
1
+ import asyncio
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ import tempfile
6
+
7
+ from axio.tool import ToolHandler
8
+
9
+ from . import _short
10
+
11
+
12
+ class RunPython(ToolHandler):
13
+ """Run a Python code snippet in a subprocess and return stdout/stderr.
14
+ The code is written to a temp file and executed with the current
15
+ interpreter. Use for calculations, data processing, or testing
16
+ small scripts. Optionally pass stdin data. Non-zero exit codes
17
+ and tracebacks are returned as-is."""
18
+
19
+ code: str
20
+ cwd: str = "."
21
+ timeout: int = 5
22
+ stdin: str | None = None
23
+
24
+ def __repr__(self) -> str:
25
+ return f"RunPython(code={_short(self.code)!r}, cwd={self.cwd!r})"
26
+
27
+ def _blocking(self) -> str:
28
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
29
+ f.write(self.code)
30
+ f.flush()
31
+
32
+ path = f.name
33
+
34
+ try:
35
+ result = subprocess.run(
36
+ [sys.executable, path],
37
+ capture_output=True,
38
+ text=True,
39
+ timeout=self.timeout,
40
+ cwd=self.cwd,
41
+ input=self.stdin if self.stdin is not None else None,
42
+ stdin=subprocess.DEVNULL if self.stdin is None else None,
43
+ )
44
+ output = ""
45
+ if result.stdout:
46
+ output += result.stdout
47
+ if result.stderr:
48
+ output += f"\n[stderr]\n{result.stderr}"
49
+ if result.returncode != 0:
50
+ output += f"\n[exit code: {result.returncode}]"
51
+ return output.strip() or "(no output)"
52
+ finally:
53
+ os.unlink(path)
54
+
55
+ async def __call__(self) -> str:
56
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,44 @@
1
+ import asyncio
2
+ import subprocess
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+ from . import _short
7
+
8
+
9
+ class Shell(ToolHandler):
10
+ """Run a shell command and return combined stdout/stderr. Use for git,
11
+ build tools, grep, tests, or any CLI operation. Non-zero exit codes
12
+ are reported. Optionally pass stdin data for commands that read from
13
+ standard input. Prefer short timeouts and avoid interactive commands."""
14
+
15
+ command: str
16
+ timeout: int = 5
17
+ cwd: str = "."
18
+ stdin: str | None = None
19
+
20
+ def __repr__(self) -> str:
21
+ return f"Shell(command={_short(self.command)!r}, cwd={self.cwd!r})"
22
+
23
+ def _blocking(self) -> str:
24
+ result = subprocess.run(
25
+ self.command,
26
+ shell=True,
27
+ capture_output=True,
28
+ text=True,
29
+ timeout=self.timeout,
30
+ cwd=self.cwd,
31
+ input=self.stdin if self.stdin is not None else None,
32
+ stdin=subprocess.DEVNULL if self.stdin is None else None,
33
+ )
34
+ output = ""
35
+ if result.stdout:
36
+ output += result.stdout
37
+ if result.stderr:
38
+ output += f"\n[stderr]\n{result.stderr}"
39
+ if result.returncode != 0:
40
+ output += f"\n[exit code: {result.returncode}]"
41
+ return output.strip() or "(no output)"
42
+
43
+ async def __call__(self) -> str:
44
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,28 @@
1
+ import asyncio
2
+ import os
3
+
4
+ from axio.tool import ToolHandler
5
+
6
+
7
+ class WriteFile(ToolHandler):
8
+ """Create or overwrite a file with the given content. Parent directories
9
+ are created automatically. Use this for new files or full rewrites.
10
+ For partial edits prefer patch_file instead."""
11
+
12
+ file_path: str
13
+ content: str
14
+ mode: int = 0o644
15
+
16
+ def __repr__(self) -> str:
17
+ return f"WriteFile(file_path={self.file_path!r}, content=<{len(self.content)} chars>)"
18
+
19
+ def _blocking(self) -> str:
20
+ path = os.path.join(os.getcwd(), self.file_path)
21
+ os.makedirs(os.path.dirname(path), exist_ok=True)
22
+ with open(path, "w") as f:
23
+ f.write(self.content)
24
+ os.chmod(path, mode=self.mode)
25
+ return f"Wrote {len(self.content)} bytes to {self.file_path}"
26
+
27
+ async def __call__(self) -> str:
28
+ return await asyncio.to_thread(self._blocking)
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: axio-tools-local
3
+ Version: 0.1.0
4
+ Summary: Core filesystem and execution tools for Axio
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: axio
@@ -0,0 +1,12 @@
1
+ axio_tools_local/__init__.py,sha256=RqCgDU1C7_KlwEACwF_f2aFMopGcvh-uBp6VZVBL9_I,147
2
+ axio_tools_local/list_files.py,sha256=L6edDkJmsogw7fzFDcNGrf9Scu3iqtkmuPGhvzoGVBA,1322
3
+ axio_tools_local/patch_file.py,sha256=wsG4XvDgZfAlUQ-qC4908IKR7ZuEjCqgiWdujDJKkh0,1433
4
+ axio_tools_local/read_file.py,sha256=81qi1wequ_n-AJj7jfPSheNjaYyQ7YEByw7mufaFcfQ,1434
5
+ axio_tools_local/run_python.py,sha256=EJRJnrIvJIA3IBZlndPFyBI901FM5Ztlgow5SYonrHw,1787
6
+ axio_tools_local/shell.py,sha256=2XD8UaoUebO8ourbXXf9SjFbLPqT5WsYi1_MhkI42Lw,1384
7
+ axio_tools_local/write_file.py,sha256=dEEJ68AviTPsjsfajTKrZ7Z2CfmO9W1c_r1tgasg5_U,898
8
+ axio_tools_local-0.1.0.dist-info/METADATA,sha256=r4nszt9GDu6d0YPubbw61Qscs0cUBkTMjOlRTaOjQBs,193
9
+ axio_tools_local-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
10
+ axio_tools_local-0.1.0.dist-info/entry_points.txt,sha256=WnS5AeRJ53M_cOaY1bDFsXO025EvUQz49mAAL3veYUs,302
11
+ axio_tools_local-0.1.0.dist-info/licenses/LICENSE,sha256=ddOkAXgIM2QzvUDPydeis3tJXfhHxt1wKnmGjbwPPxQ,1074
12
+ axio_tools_local-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,7 @@
1
+ [axio.tools]
2
+ list_files = axio_tools_local.list_files:ListFiles
3
+ patch_file = axio_tools_local.patch_file:PatchFile
4
+ read_file = axio_tools_local.read_file:ReadFile
5
+ run_python = axio_tools_local.run_python:RunPython
6
+ shell = axio_tools_local.shell:Shell
7
+ write_file = axio_tools_local.write_file:WriteFile
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Axio contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.