-
Notifications
You must be signed in to change notification settings - Fork 6
feat(python): expose Bash class with Monty Python execution and external function handler
#760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chaliy
merged 4 commits into
everruns:main
from
shubhlohiya:feat/python-external-handler-bindings
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
50f2e68
feat(python): expose Bash class with Monty Python execution and exter…
shubhlohiya 7ee7412
address PR review feedback
shubhlohiya 36dd822
fix test: assert handler receives set (not list) for Monty set literals
shubhlohiya 9617a09
fix: refresh cancellation token on reset so cancel() targets new inte…
shubhlohiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,38 @@ | ||
| """Type stubs for bashkit native module.""" | ||
|
|
||
| from typing import Any, Callable | ||
| from collections.abc import Callable | ||
| from typing import Any, Protocol | ||
|
|
||
| class ExternalHandler(Protocol): | ||
| """Protocol for the external function handler passed to Bash. | ||
|
|
||
| Called when Monty Python code invokes a registered external function. | ||
| Must be an async callable with this exact signature. | ||
| """ | ||
|
|
||
| async def __call__(self, fn_name: str, args: list[Any], kwargs: dict[str, Any]) -> Any: ... | ||
|
|
||
| class Bash: | ||
| """Core bash interpreter with virtual filesystem. | ||
|
|
||
| State persists between calls — files created in one execute() are | ||
| available in subsequent calls. | ||
|
|
||
| Example: | ||
| Example (basic): | ||
| >>> bash = Bash() | ||
| >>> result = await bash.execute("echo 'Hello!'") | ||
| >>> print(result.stdout) | ||
| Hello! | ||
|
|
||
| Example (Python execution with external function handler): | ||
| >>> async def handler(fn_name: str, args: list, kwargs: dict) -> Any: | ||
| ... return await tool_executor.call(fn_name, kwargs) | ||
| >>> bash = Bash( | ||
| ... python=True, | ||
| ... external_functions=["api_request"], | ||
| ... external_handler=handler, | ||
| ... ) | ||
| >>> result = await bash.execute("python3 -c 'print(api_request(url=\"/data\"))'") | ||
| """ | ||
|
|
||
| def __init__( | ||
|
|
@@ -21,9 +41,13 @@ class Bash: | |
| hostname: str | None = None, | ||
| max_commands: int | None = None, | ||
| max_loop_iterations: int | None = None, | ||
| python: bool = False, | ||
| external_functions: list[str] | None = None, | ||
| external_handler: ExternalHandler | None = None, | ||
| ) -> None: ... | ||
| async def execute(self, commands: str) -> ExecResult: ... | ||
| def execute_sync(self, commands: str) -> ExecResult: ... | ||
| def cancel(self) -> None: ... | ||
| def reset(self) -> None: ... | ||
|
Comment on lines
48
to
51
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added — |
||
|
|
||
| class ExecResult: | ||
|
|
@@ -64,6 +88,7 @@ class BashTool: | |
| ) -> None: ... | ||
| async def execute(self, commands: str) -> ExecResult: ... | ||
| def execute_sync(self, commands: str) -> ExecResult: ... | ||
| def cancel(self) -> None: ... | ||
| def description(self) -> str: ... | ||
| def help(self) -> str: ... | ||
| def system_prompt(self) -> str: ... | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The built wheel is ~3.5 MB with the python feature enabled. I think the size/build-time impact is small enough that it is not worth the added complexity of a conditional Cargo feature, but happy to revisit if the maintainer feels differently.