toolplane-python-client 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.
Files changed (81) hide show
  1. toolplane/__init__.py +106 -0
  2. toolplane/common/__init__.py +93 -0
  3. toolplane/common/base_config.py +129 -0
  4. toolplane/common/base_connection_manager.py +171 -0
  5. toolplane/common/base_session_manager.py +321 -0
  6. toolplane/common/base_tool_manager.py +347 -0
  7. toolplane/common/constants.py +47 -0
  8. toolplane/common/utils.py +310 -0
  9. toolplane/core/__init__.py +67 -0
  10. toolplane/core/config.py +107 -0
  11. toolplane/core/connection.py +285 -0
  12. toolplane/core/errors.py +298 -0
  13. toolplane/core/machine.py +480 -0
  14. toolplane/core/request.py +775 -0
  15. toolplane/core/session.py +332 -0
  16. toolplane/core/session_context.py +514 -0
  17. toolplane/core/task.py +130 -0
  18. toolplane/core/tool.py +329 -0
  19. toolplane/http_core/__init__.py +37 -0
  20. toolplane/http_core/http_config.py +97 -0
  21. toolplane/http_core/http_connection.py +409 -0
  22. toolplane/http_core/http_machine.py +298 -0
  23. toolplane/http_core/http_request.py +748 -0
  24. toolplane/http_core/http_session.py +348 -0
  25. toolplane/http_core/http_session_context.py +491 -0
  26. toolplane/http_core/http_task.py +101 -0
  27. toolplane/http_core/http_tool.py +400 -0
  28. toolplane/interfaces/__init__.py +27 -0
  29. toolplane/interfaces/client_interface.py +122 -0
  30. toolplane/interfaces/connection_interface.py +193 -0
  31. toolplane/interfaces/event_interface.py +290 -0
  32. toolplane/interfaces/request_interface.py +439 -0
  33. toolplane/interfaces/session_interface.py +288 -0
  34. toolplane/interfaces/tool_interface.py +441 -0
  35. toolplane/proto/__init__.py +0 -0
  36. toolplane/proto/service_pb2.py +315 -0
  37. toolplane/proto/service_pb2_grpc.py +2240 -0
  38. toolplane/provider_cli.py +268 -0
  39. toolplane/provider_registry.py +77 -0
  40. toolplane/provider_runtime.py +302 -0
  41. toolplane/toolkits/__init__.py +0 -0
  42. toolplane/toolkits/standalone_tools/__init__.py +0 -0
  43. toolplane/toolkits/standalone_tools/create_directory.py +94 -0
  44. toolplane/toolkits/standalone_tools/create_file.py +124 -0
  45. toolplane/toolkits/standalone_tools/file_search.py +229 -0
  46. toolplane/toolkits/standalone_tools/grep_search.py +372 -0
  47. toolplane/toolkits/standalone_tools/launcher.py +146 -0
  48. toolplane/toolkits/standalone_tools/list_dir.py +395 -0
  49. toolplane/toolkits/standalone_tools/read_file.py +346 -0
  50. toolplane/toolkits/standalone_tools/replace_string_in_file.py +407 -0
  51. toolplane/toolkits/standalone_tools/run_tests.py +66 -0
  52. toolplane/toolkits/standalone_tools/semantic_search.py +485 -0
  53. toolplane/toolkits/standalone_tools/standalone_toolkit.py +979 -0
  54. toolplane/toolkits/standalone_tools/test_failure_analysis.py +618 -0
  55. toolplane/toolkits/standalone_tools/test_standalone_toolkit.py +517 -0
  56. toolplane/toolkits/swe/__init__.py +35 -0
  57. toolplane/toolkits/swe/create_directory.py +15 -0
  58. toolplane/toolkits/swe/create_file.py +15 -0
  59. toolplane/toolkits/swe/descriptions.py +273 -0
  60. toolplane/toolkits/swe/execute_bash.py +93 -0
  61. toolplane/toolkits/swe/file_editor.py +775 -0
  62. toolplane/toolkits/swe/file_search.py +16 -0
  63. toolplane/toolkits/swe/finish.py +50 -0
  64. toolplane/toolkits/swe/grep_search.py +19 -0
  65. toolplane/toolkits/swe/list_dir.py +407 -0
  66. toolplane/toolkits/swe/read_file.py +18 -0
  67. toolplane/toolkits/swe/replace_string_in_file.py +17 -0
  68. toolplane/toolkits/swe/search.py +260 -0
  69. toolplane/toolkits/swe/semantic_search.py +20 -0
  70. toolplane/toolkits/swe/str_replace_editor.py +647 -0
  71. toolplane/toolkits/swe/submit.py +29 -0
  72. toolplane/toolkits/swe/swe_toolkit.py +1296 -0
  73. toolplane/toolplane_client.py +686 -0
  74. toolplane/toolplane_http_client.py +681 -0
  75. toolplane/utils/__init__.py +3 -0
  76. toolplane/utils/schema.py +146 -0
  77. toolplane_python_client-0.1.0.dist-info/METADATA +543 -0
  78. toolplane_python_client-0.1.0.dist-info/RECORD +81 -0
  79. toolplane_python_client-0.1.0.dist-info/WHEEL +5 -0
  80. toolplane_python_client-0.1.0.dist-info/entry_points.txt +2 -0
  81. toolplane_python_client-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Description: Create a new directory structure with enhanced features.
4
+
5
+ This tool creates directories recursively (like mkdir -p) and provides
6
+ additional features like permission handling and validation.
7
+
8
+ Parameters:
9
+ dirPath (string, required): The absolute path to the directory to create.
10
+ mode (integer, optional): The permission mode for the directory (default: 0o755).
11
+ parents (boolean, optional): Create parent directories if they don't exist (default: True).
12
+ exist_ok (boolean, optional): Don't raise an error if the directory already exists (default: True).
13
+ """
14
+
15
+ import argparse
16
+ import os
17
+ import sys
18
+ from pathlib import Path
19
+
20
+
21
+ def create_directory(
22
+ dir_path: str, mode: int = 0o755, parents: bool = True, exist_ok: bool = True
23
+ ) -> bool:
24
+ """
25
+ Create a directory with the specified parameters.
26
+
27
+ Args:
28
+ dir_path: The absolute path to the directory to create
29
+ mode: Permission mode for the directory
30
+ parents: Create parent directories if they don't exist
31
+ exist_ok: Don't raise error if directory already exists
32
+
33
+ Returns:
34
+ bool: True if directory was created or already exists, False otherwise
35
+ """
36
+ try:
37
+ path = Path(dir_path)
38
+ path.mkdir(mode=mode, parents=parents, exist_ok=exist_ok)
39
+
40
+ if path.exists():
41
+ print(f"Directory created successfully: {dir_path}")
42
+ return True
43
+ else:
44
+ print(f"Failed to create directory: {dir_path}")
45
+ return False
46
+
47
+ except PermissionError:
48
+ print(f"Permission denied: Cannot create directory {dir_path}")
49
+ return False
50
+ except FileExistsError:
51
+ print(f"Directory already exists: {dir_path}")
52
+ return exist_ok
53
+ except Exception as e:
54
+ print(f"Error creating directory {dir_path}: {e}")
55
+ return False
56
+
57
+
58
+ def main():
59
+ parser = argparse.ArgumentParser(
60
+ description="Create a new directory structure with enhanced features."
61
+ )
62
+ parser.add_argument(
63
+ "dirPath", type=str, help="The absolute path to the directory to create."
64
+ )
65
+ parser.add_argument(
66
+ "--mode",
67
+ type=lambda x: int(x, 8), # Parse as octal
68
+ default=0o755,
69
+ help="Permission mode for the directory (octal, default: 755)",
70
+ )
71
+ parser.add_argument(
72
+ "--parents",
73
+ action="store_true",
74
+ default=True,
75
+ help="Create parent directories if they don't exist (default: True)",
76
+ )
77
+ parser.add_argument(
78
+ "--exist_ok",
79
+ action="store_true",
80
+ default=True,
81
+ help="Don't raise error if directory already exists (default: True)",
82
+ )
83
+
84
+ args = parser.parse_args()
85
+
86
+ success = create_directory(
87
+ args.dirPath, mode=args.mode, parents=args.parents, exist_ok=args.exist_ok
88
+ )
89
+
90
+ sys.exit(0 if success else 1)
91
+
92
+
93
+ if __name__ == "__main__":
94
+ main()
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Description: Create a new file with specified content and enhanced features.
4
+
5
+ This tool creates a new file with the given content and automatically creates
6
+ parent directories if they don't exist. It includes validation and error handling.
7
+
8
+ Parameters:
9
+ filePath (string, required): The absolute path to the file to create.
10
+ content (string, required): The content to write to the file.
11
+ encoding (string, optional): The encoding to use for the file (default: utf-8).
12
+ mode (string, optional): The file creation mode (default: 'w').
13
+ auto_create_dirs (boolean, optional): Create parent directories if they don't exist (default: True).
14
+ overwrite (boolean, optional): Overwrite the file if it already exists (default: False).
15
+ """
16
+
17
+ import argparse
18
+ import os
19
+ import sys
20
+ from pathlib import Path
21
+
22
+
23
+ def create_file(
24
+ file_path: str,
25
+ content: str,
26
+ encoding: str = "utf-8",
27
+ mode: str = "w",
28
+ auto_create_dirs: bool = True,
29
+ overwrite: bool = False,
30
+ ) -> bool:
31
+ """
32
+ Create a new file with the specified content.
33
+
34
+ Args:
35
+ file_path: The absolute path to the file to create
36
+ content: The content to write to the file
37
+ encoding: The encoding to use for the file
38
+ mode: The file creation mode
39
+ auto_create_dirs: Create parent directories if they don't exist
40
+ overwrite: Overwrite the file if it already exists
41
+
42
+ Returns:
43
+ bool: True if file was created successfully, False otherwise
44
+ """
45
+ try:
46
+ path = Path(file_path)
47
+
48
+ # Check if file already exists
49
+ if path.exists() and not overwrite:
50
+ print(f"File already exists: {file_path}")
51
+ print("Use --overwrite flag to overwrite existing files.")
52
+ return False
53
+
54
+ # Create parent directories if needed
55
+ if auto_create_dirs and not path.parent.exists():
56
+ path.parent.mkdir(parents=True, exist_ok=True)
57
+ print(f"Created parent directories for: {file_path}")
58
+
59
+ # Write the file
60
+ with open(path, mode, encoding=encoding) as f:
61
+ f.write(content)
62
+
63
+ print(f"File created successfully: {file_path}")
64
+ print(f"Content length: {len(content)} characters")
65
+ return True
66
+
67
+ except PermissionError:
68
+ print(f"Permission denied: Cannot create file {file_path}")
69
+ return False
70
+ except FileNotFoundError:
71
+ print(f"Directory does not exist: {path.parent}")
72
+ print("Use --auto_create_dirs flag to create parent directories.")
73
+ return False
74
+ except Exception as e:
75
+ print(f"Error creating file {file_path}: {e}")
76
+ return False
77
+
78
+
79
+ def main():
80
+ parser = argparse.ArgumentParser(
81
+ description="Create a new file with specified content and enhanced features."
82
+ )
83
+ parser.add_argument(
84
+ "filePath", type=str, help="The absolute path to the file to create."
85
+ )
86
+ parser.add_argument("content", type=str, help="The content to write to the file.")
87
+ parser.add_argument(
88
+ "--encoding",
89
+ type=str,
90
+ default="utf-8",
91
+ help="The encoding to use for the file (default: utf-8)",
92
+ )
93
+ parser.add_argument(
94
+ "--mode", type=str, default="w", help="The file creation mode (default: 'w')"
95
+ )
96
+ parser.add_argument(
97
+ "--auto_create_dirs",
98
+ action="store_true",
99
+ default=True,
100
+ help="Create parent directories if they don't exist (default: True)",
101
+ )
102
+ parser.add_argument(
103
+ "--overwrite",
104
+ action="store_true",
105
+ default=False,
106
+ help="Overwrite the file if it already exists (default: False)",
107
+ )
108
+
109
+ args = parser.parse_args()
110
+
111
+ success = create_file(
112
+ args.filePath,
113
+ args.content,
114
+ encoding=args.encoding,
115
+ mode=args.mode,
116
+ auto_create_dirs=args.auto_create_dirs,
117
+ overwrite=args.overwrite,
118
+ )
119
+
120
+ sys.exit(0 if success else 1)
121
+
122
+
123
+ if __name__ == "__main__":
124
+ main()
@@ -0,0 +1,229 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Description: Search for files in the workspace using glob patterns with advanced features.
4
+
5
+ This tool searches for files using glob patterns and provides additional
6
+ filtering and sorting options. It returns file paths matching the pattern.
7
+
8
+ Parameters:
9
+ query (string, required): Glob pattern to search for files.
10
+ max_results (integer, optional): Maximum number of results to return.
11
+ include_hidden (boolean, optional): Include hidden files in results (default: False).
12
+ sort_by (string, optional): Sort results by 'name', 'size', 'modified' (default: 'name').
13
+ reverse_sort (boolean, optional): Reverse the sort order (default: False).
14
+ show_details (boolean, optional): Show file details like size and modification time (default: False).
15
+ """
16
+
17
+ import argparse
18
+ import glob
19
+ import os
20
+ import sys
21
+ import time
22
+ from pathlib import Path
23
+ from typing import Any, Dict, List
24
+
25
+
26
+ def file_search(
27
+ query: str,
28
+ max_results: int = None,
29
+ include_hidden: bool = False,
30
+ sort_by: str = "name",
31
+ reverse_sort: bool = False,
32
+ show_details: bool = False,
33
+ base_path: str = None,
34
+ ) -> List[Dict[str, Any]]:
35
+ """
36
+ Search for files using glob patterns with advanced features.
37
+
38
+ Args:
39
+ query: Glob pattern to search for files
40
+ max_results: Maximum number of results to return
41
+ include_hidden: Include hidden files in results
42
+ sort_by: Sort results by 'name', 'size', 'modified'
43
+ reverse_sort: Reverse the sort order
44
+ show_details: Show file details like size and modification time
45
+ base_path: Base directory to search from (default: current directory)
46
+
47
+ Returns:
48
+ List of dictionaries containing file information
49
+ """
50
+ if base_path is None:
51
+ base_path = os.getcwd()
52
+
53
+ # Change to base directory for glob search
54
+ original_cwd = os.getcwd()
55
+ os.chdir(base_path)
56
+
57
+ try:
58
+ # Use glob to find matching files
59
+ matches = glob.glob(query, recursive=True)
60
+
61
+ results = []
62
+ for match in matches:
63
+ try:
64
+ path = Path(match)
65
+ absolute_path = path.resolve()
66
+
67
+ # Skip hidden files if not requested
68
+ if not include_hidden and any(
69
+ part.startswith(".") for part in path.parts
70
+ ):
71
+ continue
72
+
73
+ # Get file stats
74
+ stat = absolute_path.stat()
75
+
76
+ result = {
77
+ "path": str(absolute_path),
78
+ "relative_path": str(path),
79
+ "name": path.name,
80
+ "is_file": absolute_path.is_file(),
81
+ "is_dir": absolute_path.is_dir(),
82
+ "size": stat.st_size if absolute_path.is_file() else 0,
83
+ "modified": stat.st_mtime,
84
+ "modified_readable": time.strftime(
85
+ "%Y-%m-%d %H:%M:%S", time.localtime(stat.st_mtime)
86
+ ),
87
+ }
88
+
89
+ results.append(result)
90
+
91
+ except (OSError, PermissionError) as e:
92
+ # Skip files that can't be accessed
93
+ continue
94
+
95
+ # Sort results
96
+ if sort_by == "name":
97
+ results.sort(key=lambda x: x["name"].lower(), reverse=reverse_sort)
98
+ elif sort_by == "size":
99
+ results.sort(key=lambda x: x["size"], reverse=reverse_sort)
100
+ elif sort_by == "modified":
101
+ results.sort(key=lambda x: x["modified"], reverse=reverse_sort)
102
+
103
+ # Limit results if specified
104
+ if max_results and len(results) > max_results:
105
+ results = results[:max_results]
106
+
107
+ return results
108
+
109
+ finally:
110
+ # Restore original working directory
111
+ os.chdir(original_cwd)
112
+
113
+
114
+ def format_size(size_bytes: int) -> str:
115
+ """Format file size in human-readable format."""
116
+ if size_bytes == 0:
117
+ return "0 B"
118
+
119
+ units = ["B", "KB", "MB", "GB", "TB"]
120
+ i = 0
121
+ while size_bytes >= 1024 and i < len(units) - 1:
122
+ size_bytes /= 1024
123
+ i += 1
124
+
125
+ return f"{size_bytes:.1f} {units[i]}"
126
+
127
+
128
+ def main():
129
+ parser = argparse.ArgumentParser(
130
+ description="Search for files in the workspace using glob patterns with advanced features."
131
+ )
132
+ parser.add_argument(
133
+ "query",
134
+ type=str,
135
+ help="Glob pattern to search for files (e.g., '*.py', '**/*.txt', 'src/**/*.js')",
136
+ )
137
+ parser.add_argument(
138
+ "--max_results", type=int, help="Maximum number of results to return"
139
+ )
140
+ parser.add_argument(
141
+ "--include_hidden",
142
+ action="store_true",
143
+ default=False,
144
+ help="Include hidden files in results (default: False)",
145
+ )
146
+ parser.add_argument(
147
+ "--sort_by",
148
+ choices=["name", "size", "modified"],
149
+ default="name",
150
+ help="Sort results by 'name', 'size', or 'modified' (default: name)",
151
+ )
152
+ parser.add_argument(
153
+ "--reverse_sort",
154
+ action="store_true",
155
+ default=False,
156
+ help="Reverse the sort order (default: False)",
157
+ )
158
+ parser.add_argument(
159
+ "--show_details",
160
+ action="store_true",
161
+ default=False,
162
+ help="Show file details like size and modification time (default: False)",
163
+ )
164
+ parser.add_argument(
165
+ "--base_path",
166
+ type=str,
167
+ help="Base directory to search from (default: current directory)",
168
+ )
169
+ parser.add_argument(
170
+ "--output_format",
171
+ choices=["list", "table", "json"],
172
+ default="list",
173
+ help="Output format (default: list)",
174
+ )
175
+
176
+ args = parser.parse_args()
177
+
178
+ results = file_search(
179
+ args.query,
180
+ max_results=args.max_results,
181
+ include_hidden=args.include_hidden,
182
+ sort_by=args.sort_by,
183
+ reverse_sort=args.reverse_sort,
184
+ show_details=args.show_details,
185
+ base_path=args.base_path,
186
+ )
187
+
188
+ if not results:
189
+ print(f"No files found matching pattern: {args.query}")
190
+ sys.exit(0)
191
+
192
+ if args.output_format == "json":
193
+ import json
194
+
195
+ print(json.dumps(results, indent=2))
196
+
197
+ elif args.output_format == "table" or args.show_details:
198
+ print(f"Found {len(results)} files matching pattern: {args.query}")
199
+ print("-" * 80)
200
+
201
+ if args.show_details:
202
+ print(f"{'Name':<40} {'Size':<12} {'Modified':<20} {'Type':<8}")
203
+ print("-" * 80)
204
+
205
+ for result in results:
206
+ file_type = "DIR" if result["is_dir"] else "FILE"
207
+ size_str = format_size(result["size"]) if result["is_file"] else "-"
208
+
209
+ print(
210
+ f"{result['name']:<40} {size_str:<12} {result['modified_readable']:<20} {file_type:<8}"
211
+ )
212
+ else:
213
+ for result in results:
214
+ print(result["path"])
215
+
216
+ else: # list format
217
+ print(f"Found {len(results)} files matching pattern: {args.query}")
218
+ for result in results:
219
+ print(result["path"])
220
+
221
+ # Show truncation warning if results were limited
222
+ if args.max_results and len(results) == args.max_results:
223
+ print(
224
+ f"\nResults truncated to {args.max_results} items. Use --max_results to see more."
225
+ )
226
+
227
+
228
+ if __name__ == "__main__":
229
+ main()