hypha-debugger 0.1.7__tar.gz → 0.1.9__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.
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/PKG-INFO +1 -1
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/__init__.py +1 -1
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/debugger.py +5 -36
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/source.py +64 -78
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/PKG-INFO +1 -1
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/pyproject.toml +1 -1
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/tests/test_services.py +5 -3
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/README.md +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/__main__.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/__init__.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/execute.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/filesystem.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/info.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/inspect_vars.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/utils/__init__.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/utils/env.py +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/SOURCES.txt +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/dependency_links.txt +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/entry_points.txt +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/requires.txt +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/top_level.txt +0 -0
- {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/setup.cfg +0 -0
|
@@ -54,24 +54,9 @@ def _build_instruction_block(service_url: str, token: str = "") -> str:
|
|
|
54
54
|
auth = f' -H "Authorization: Bearer $TOKEN"' if token else ""
|
|
55
55
|
lines = [
|
|
56
56
|
"# Hypha Remote Debugger — Python Process",
|
|
57
|
-
"# A debugger is attached to a running Python process.",
|
|
58
|
-
"# You can
|
|
59
|
-
"#
|
|
60
|
-
"#",
|
|
61
|
-
"# Available functions:",
|
|
62
|
-
"# get_process_info - PID, Python version, CWD, platform, memory",
|
|
63
|
-
"# execute_code - Run Python code (persistent REPL, auto-captures last expr)",
|
|
64
|
-
"# get_variable - Inspect a variable by name",
|
|
65
|
-
"# list_variables - List variables in a namespace",
|
|
66
|
-
"# get_stack_trace - Stack traces of all threads",
|
|
67
|
-
"# list_files - List directory contents",
|
|
68
|
-
"# read_file - Read file content (with offset/limit)",
|
|
69
|
-
"# write_file - Write/append to a file",
|
|
70
|
-
"# get_installed_packages - List pip packages",
|
|
71
|
-
"# get_source - Get debugger source code (for self-inspection)",
|
|
72
|
-
"# get_skill_md - Get full API docs as Markdown",
|
|
73
|
-
"#",
|
|
74
|
-
"# POST endpoints accept JSON body with parameter names as keys.",
|
|
57
|
+
"# A remote debugger is attached to a running Python process.",
|
|
58
|
+
"# You can execute code, read/write files, inspect variables, and more.",
|
|
59
|
+
"# Call get_skill_md for full API docs with all available functions.",
|
|
75
60
|
"",
|
|
76
61
|
f'SERVICE_URL="{service_url}"',
|
|
77
62
|
]
|
|
@@ -79,28 +64,12 @@ def _build_instruction_block(service_url: str, token: str = "") -> str:
|
|
|
79
64
|
lines.append(f'TOKEN="{token}"')
|
|
80
65
|
lines += [
|
|
81
66
|
"",
|
|
82
|
-
"#
|
|
83
|
-
f'curl "$SERVICE_URL/get_process_info"{auth}',
|
|
84
|
-
"",
|
|
85
|
-
"# Execute Python code (timeout default 30s):",
|
|
67
|
+
"# Execute Python code:",
|
|
86
68
|
f'curl -X POST "$SERVICE_URL/execute_code"{auth}'
|
|
87
69
|
' -H "Content-Type: application/json"'
|
|
88
70
|
" -d '{\"code\": \"import sys; sys.version\"}'",
|
|
89
71
|
"",
|
|
90
|
-
"#
|
|
91
|
-
f'curl -X POST "$SERVICE_URL/write_file"{auth}'
|
|
92
|
-
' -H "Content-Type: application/json"'
|
|
93
|
-
" -d '{\"path\": \"hello.txt\", \"content\": \"Hello, world!\"}'",
|
|
94
|
-
"",
|
|
95
|
-
"# List files in working directory:",
|
|
96
|
-
f'curl "$SERVICE_URL/list_files"{auth}',
|
|
97
|
-
"",
|
|
98
|
-
"# Read a file:",
|
|
99
|
-
f'curl -X POST "$SERVICE_URL/read_file"{auth}'
|
|
100
|
-
' -H "Content-Type: application/json"'
|
|
101
|
-
" -d '{\"path\": \"hello.txt\"}'",
|
|
102
|
-
"",
|
|
103
|
-
"# Get full API documentation:",
|
|
72
|
+
"# Get full API docs (all functions, parameters, examples):",
|
|
104
73
|
f'curl "$SERVICE_URL/get_skill_md"{auth}',
|
|
105
74
|
]
|
|
106
75
|
return "\n".join(lines)
|
|
@@ -87,104 +87,90 @@ def _get_skill_md_impl() -> str:
|
|
|
87
87
|
return """# Hypha Remote Debugger — Python Process API
|
|
88
88
|
|
|
89
89
|
## Overview
|
|
90
|
-
A debugger is attached to a running Python process. You
|
|
91
|
-
read/write files, inspect variables, and
|
|
90
|
+
A remote debugger is attached to a running Python process. You have full access
|
|
91
|
+
to execute code, read/write files, inspect variables, and install packages.
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
**Recommended approach**: Use `execute_code` as your primary tool — it's a
|
|
94
|
+
persistent Python REPL where variables, imports, and functions survive across
|
|
95
|
+
calls. The other endpoints are convenience shortcuts.
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
Get information about the current Python process.
|
|
97
|
-
- **Returns**: `{pid, cwd, python_version, hostname, platform, memory_mb, cpu_count, ...}`
|
|
98
|
-
- **Example**: `curl "$SERVICE_URL/get_process_info"`
|
|
97
|
+
## Quick Start
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
across calls in the default REPL namespace.
|
|
104
|
-
- **code** (string, required): Python code to execute.
|
|
105
|
-
- **namespace** (string, default `""`): Namespace. Empty = persistent REPL. `"__main__"` = main module.
|
|
106
|
-
- **timeout** (int, default `30`): Timeout in seconds. 0 for no timeout.
|
|
107
|
-
- **Returns**: `{ok, stdout, stderr, result, result_repr, result_type, error?, error_type?, error_message?, traceback?, timed_out?}`
|
|
108
|
-
- The last expression in the code block is automatically captured as `result`.
|
|
109
|
-
E.g. `"x = 1\\nx + 1"` returns `result=2`.
|
|
110
|
-
- **Example**:
|
|
111
|
-
```bash
|
|
112
|
-
curl -X POST "$SERVICE_URL/execute_code" \\
|
|
113
|
-
-H "Content-Type: application/json" \\
|
|
114
|
-
-d '{"code": "import sys; sys.version"}'
|
|
115
|
-
```
|
|
99
|
+
```bash
|
|
100
|
+
# Set the service URL (provided when debugger starts)
|
|
101
|
+
SERVICE_URL="<your-service-url>"
|
|
116
102
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
- **Returns**: `{name, type, repr, length?, shape?, dtype?, keys?}`
|
|
103
|
+
# Run Python code (persistent REPL — variables survive across calls):
|
|
104
|
+
curl -X POST "$SERVICE_URL/execute_code" \\
|
|
105
|
+
-H "Content-Type: application/json" \\
|
|
106
|
+
-d '{"code": "import os; os.listdir(\\".\\")"}'
|
|
122
107
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
- **include_private** (bool, default `false`): Include `_`-prefixed names.
|
|
128
|
-
- **Returns**: List of `{name, type, repr}`.
|
|
108
|
+
# Install a package:
|
|
109
|
+
curl -X POST "$SERVICE_URL/execute_code" \\
|
|
110
|
+
-H "Content-Type: application/json" \\
|
|
111
|
+
-d '{"code": "import subprocess; subprocess.check_output([\\\"pip\\\", \\\"install\\\", \\\"requests\\\"])"}'
|
|
129
112
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
113
|
+
# Write a file via execute_code (avoids JSON escaping issues):
|
|
114
|
+
curl -X POST "$SERVICE_URL/execute_code" \\
|
|
115
|
+
-H "Content-Type: application/json" \\
|
|
116
|
+
-d '{"code": "with open(\\\"hello.py\\\", \\\"w\\\") as f: f.write(\\\"print(42)\\\\n\\\")"}'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Functions
|
|
120
|
+
|
|
121
|
+
### execute_code(code, namespace?, timeout?) — PRIMARY
|
|
122
|
+
Execute Python code in a persistent REPL. The last expression is automatically
|
|
123
|
+
captured as the return value via AST parsing.
|
|
124
|
+
- **code** (str, required): Python code to execute.
|
|
125
|
+
- **namespace** (str, default `""`): Empty = persistent REPL, `"__main__"` = main module.
|
|
126
|
+
- **timeout** (int, default `30`): Seconds. 0 = no timeout.
|
|
127
|
+
- **Returns**: `{ok, stdout, stderr, result, result_repr, result_type, error?, error_type?, error_message?, traceback?, timed_out?}`
|
|
128
|
+
- Variables, functions, and imports persist across calls.
|
|
129
|
+
- Example: `"x = 1\\nx + 1"` returns `{ok: true, result: 2}`.
|
|
130
|
+
|
|
131
|
+
### get_process_info()
|
|
132
|
+
PID, CWD, Python version, hostname, platform, memory usage, CPU count.
|
|
133
|
+
- **Example**: `curl "$SERVICE_URL/get_process_info"`
|
|
134
134
|
|
|
135
135
|
### list_files(path?, pattern?)
|
|
136
|
-
List
|
|
137
|
-
- **path** (
|
|
138
|
-
- **pattern** (string): Glob filter, e.g. `"*.py"`.
|
|
136
|
+
List directory contents (sandboxed to CWD).
|
|
137
|
+
- **path** (str, default `"."`), **pattern** (str): glob filter e.g. `"*.py"`.
|
|
139
138
|
- **Returns**: `{path, entries: [{name, type, size?}], total}`
|
|
140
|
-
- **Example**: `curl "$SERVICE_URL/list_files"`
|
|
141
139
|
|
|
142
140
|
### read_file(path, max_lines?, offset?, encoding?)
|
|
143
141
|
Read a file (sandboxed to CWD).
|
|
144
|
-
- **path** (
|
|
145
|
-
- **max_lines** (int, default `500`): Max lines to read.
|
|
146
|
-
- **offset** (int, default `0`): Lines to skip from beginning.
|
|
142
|
+
- **path** (str, required), **max_lines** (int, default `500`), **offset** (int, default `0`).
|
|
147
143
|
- **Returns**: `{path, content, lines_read, offset, truncated}`
|
|
148
|
-
- **Example**:
|
|
149
|
-
```bash
|
|
150
|
-
curl -X POST "$SERVICE_URL/read_file" \\
|
|
151
|
-
-H "Content-Type: application/json" \\
|
|
152
|
-
-d '{"path": "main.py"}'
|
|
153
|
-
```
|
|
154
144
|
|
|
155
145
|
### write_file(path, content, mode?, create_dirs?, encoding?)
|
|
156
|
-
Write
|
|
157
|
-
- **path** (
|
|
158
|
-
- **content** (string, required): Content to write.
|
|
159
|
-
- **mode** (string, default `"w"`): `"w"` to overwrite, `"a"` to append.
|
|
160
|
-
- **create_dirs** (bool, default `true`): Create parent directories.
|
|
146
|
+
Write/append to a file (sandboxed to CWD). Auto-creates parent dirs.
|
|
147
|
+
- **path** (str), **content** (str), **mode** (`"w"` or `"a"`).
|
|
161
148
|
- **Returns**: `{path, bytes_written, mode}`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
149
|
+
|
|
150
|
+
### get_variable(name, namespace?)
|
|
151
|
+
Inspect a variable by name in a module namespace.
|
|
152
|
+
- **Returns**: `{name, type, repr, length?, shape?, dtype?, keys?}`
|
|
153
|
+
|
|
154
|
+
### list_variables(namespace?, filter?, include_private?)
|
|
155
|
+
List variables in a namespace. Filters by substring.
|
|
156
|
+
|
|
157
|
+
### get_stack_trace()
|
|
158
|
+
Stack traces of all threads. Useful for debugging hangs.
|
|
168
159
|
|
|
169
160
|
### get_installed_packages(filter?)
|
|
170
|
-
List
|
|
171
|
-
- **filter** (string): Substring filter for package names.
|
|
172
|
-
- **Returns**: List of `{name, version}`.
|
|
173
|
-
- **Example**: `curl "$SERVICE_URL/get_installed_packages"`
|
|
161
|
+
List pip packages. Optional name substring filter.
|
|
174
162
|
|
|
175
163
|
### get_source(module?)
|
|
176
|
-
Get
|
|
177
|
-
- **module** (string): Module path, e.g. `"services.execute"`. Empty to list modules.
|
|
178
|
-
- **Returns**: `{module, source, lines}` or `{modules, hint}`.
|
|
164
|
+
Get debugger source code. Empty = list modules, e.g. `"services.execute"`.
|
|
179
165
|
|
|
180
166
|
### get_skill_md()
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
- All file operations are sandboxed to the process CWD.
|
|
187
|
-
- POST endpoints accept JSON body
|
|
188
|
-
-
|
|
189
|
-
-
|
|
167
|
+
Returns this document.
|
|
168
|
+
|
|
169
|
+
## Tips
|
|
170
|
+
- **Use `execute_code` for file writes** when content has special characters —
|
|
171
|
+
it avoids JSON/curl escaping issues that affect `write_file` via HTTP.
|
|
172
|
+
- All file operations (list/read/write) are sandboxed to the process CWD.
|
|
173
|
+
- POST endpoints accept JSON body. GET endpoints take no body.
|
|
174
|
+
- Code execution has a 30s default timeout to prevent hangs.
|
|
175
|
+
- The REPL namespace is independent from `__main__` by default.
|
|
190
176
|
"""
|
|
@@ -255,7 +255,7 @@ def test_instruction_block_no_token():
|
|
|
255
255
|
assert "TOKEN=" not in block
|
|
256
256
|
assert "Authorization" not in block
|
|
257
257
|
assert "execute_code" in block
|
|
258
|
-
assert "
|
|
258
|
+
assert "get_skill_md" in block
|
|
259
259
|
|
|
260
260
|
|
|
261
261
|
def test_instruction_block_with_token():
|
|
@@ -302,11 +302,13 @@ def test_get_skill_md():
|
|
|
302
302
|
assert "SERVICE_URL" in md
|
|
303
303
|
|
|
304
304
|
|
|
305
|
-
def
|
|
305
|
+
def test_instruction_block_concise():
|
|
306
306
|
from hypha_debugger.debugger import _build_instruction_block
|
|
307
307
|
block = _build_instruction_block("https://example.com/ws/services/py-debugger-abc")
|
|
308
|
-
assert "get_source" in block
|
|
309
308
|
assert "get_skill_md" in block
|
|
309
|
+
# Should NOT have the verbose function list anymore
|
|
310
|
+
assert "get_variable" not in block
|
|
311
|
+
assert "list_files" not in block
|
|
310
312
|
|
|
311
313
|
|
|
312
314
|
def test_debug_session_print_instructions(capsys):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|