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.
Files changed (22) hide show
  1. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/PKG-INFO +1 -1
  2. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/__init__.py +1 -1
  3. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/debugger.py +5 -36
  4. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/source.py +64 -78
  5. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/PKG-INFO +1 -1
  6. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/pyproject.toml +1 -1
  7. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/tests/test_services.py +5 -3
  8. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/README.md +0 -0
  9. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/__main__.py +0 -0
  10. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/__init__.py +0 -0
  11. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/execute.py +0 -0
  12. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/filesystem.py +0 -0
  13. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/info.py +0 -0
  14. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/services/inspect_vars.py +0 -0
  15. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/utils/__init__.py +0 -0
  16. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger/utils/env.py +0 -0
  17. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/SOURCES.txt +0 -0
  18. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/dependency_links.txt +0 -0
  19. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/entry_points.txt +0 -0
  20. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/requires.txt +0 -0
  21. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/hypha_debugger.egg-info/top_level.txt +0 -0
  22. {hypha_debugger-0.1.7 → hypha_debugger-0.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypha-debugger
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Injectable debugger for Python processes and AI agents, powered by Hypha RPC
5
5
  Author: Amun AI AB
6
6
  License: MIT
@@ -12,5 +12,5 @@ Usage (sync):
12
12
 
13
13
  from hypha_debugger.debugger import start_debugger, start_debugger_sync, DebugSession
14
14
 
15
- __version__ = "0.1.7"
15
+ __version__ = "0.1.9"
16
16
  __all__ = ["start_debugger", "start_debugger_sync", "DebugSession", "__version__"]
@@ -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 remotely execute code, read/write files, inspect variables,",
59
- "# and query process info via the HTTP API below.",
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
- "# Get process info (PID, Python version, CWD, memory):",
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
- "# Write a file:",
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 can remotely execute code,
91
- read/write files, inspect variables, and query process info via the HTTP API.
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
- ## Functions
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
- ### get_process_info()
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
- ### execute_code(code, namespace?, timeout?)
101
- Execute arbitrary Python code in the process. Uses AST parsing to automatically
102
- capture the last expression's value. Variables, functions, and imports persist
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
- ### get_variable(name, namespace?)
118
- Inspect a variable by name.
119
- - **name** (string, required): Variable name.
120
- - **namespace** (string, default `"__main__"`): Module namespace.
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
- ### list_variables(namespace?, filter?, include_private?)
124
- List variables in a namespace.
125
- - **namespace** (string, default `"__main__"`): Module namespace.
126
- - **filter** (string): Substring filter for names.
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
- ### get_stack_trace()
131
- Get stack traces of all threads.
132
- - **Returns**: List of `{thread_id, thread_name, stack}`.
133
- - **Example**: `curl "$SERVICE_URL/get_stack_trace"`
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 files and directories (sandboxed to CWD).
137
- - **path** (string, default `"."`): Directory path relative to CWD.
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** (string, required): File path relative to CWD.
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 content to a file (sandboxed to CWD).
157
- - **path** (string, required): File path relative to CWD.
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
- - **Example**:
163
- ```bash
164
- curl -X POST "$SERVICE_URL/write_file" \\
165
- -H "Content-Type: application/json" \\
166
- -d '{"path": "hello.txt", "content": "Hello!"}'
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 installed pip packages.
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 the source code of debugger modules.
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
- Get this API documentation as Markdown.
182
- - **Returns**: This document as a string.
183
- - **Example**: `curl "$SERVICE_URL/get_skill_md"`
184
-
185
- ## Notes
186
- - All file operations are sandboxed to the process CWD.
187
- - POST endpoints accept JSON body with parameter names as keys.
188
- - GET endpoints take no parameters (or use query params).
189
- - Code execution has a default 30s timeout to prevent hangs.
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
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypha-debugger
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Injectable debugger for Python processes and AI agents, powered by Hypha RPC
5
5
  Author: Amun AI AB
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hypha-debugger"
7
- version = "0.1.7"
7
+ version = "0.1.9"
8
8
  description = "Injectable debugger for Python processes and AI agents, powered by Hypha RPC"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -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 "write_file" in block
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 test_instruction_block_includes_new_functions():
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