remote-bash-tool
OpenCode 自定义工具:通过 SSH(读取 ~/.ssh/config)在远程机器执行 bash 命令,基于 asyncssh 支持异步调用。
OpenCode custom tool: run bash commands on remote hosts via SSH (reads ~/.ssh/config), powered by asyncssh with async support.
Install (uv)
uv venv
uv sync
Usage
示例:在终端中直接执行(无需单独脚本文件):
Example: run directly in terminal (no script file needed):
# 使用 uvx 直接运行
uvx --from remote-bash-tool remote-bash --host-alias prod-db --command "uptime"
# 在项目内,使用 uv
uv run remote-bash --host-alias prod-db --command "uptime"
# 或者安装到环境后
remote-bash --host-alias prod-db --command "uptime"
# 如果想要 JSON 输出
remote-bash --host-alias prod-db --command "df -h" --json
也支持模块方式运行:
Module invocation is also supported:
python -m remote_bash_tool --host-alias prod-db --command "uptime"
查看帮助:
Show help:
remote-bash --help
示例:在 Python 代码中直接调用工具方法。
Example: call from Python code:
import asyncio
from remote_bash_tool.tool import run
async def main() -> None:
result = await run(
{"host_alias": "prod-db", "command": "uptime", "stream_output": True}
)
print(result["stdout"])
asyncio.run(main())
OpenCode config (optional)
-
将工具模块挂载到 OpenCode(示例配置,参考 OpenCode 自定义工具指南进行调整):
-
Register the tool module in OpenCode (example config, adjust per OpenCode docs):
tools: - name: remote_bash module: remote_bash_tool.tool entrypoint: run
-
在 OpenCode 中调用工具:
-
Call the tool in OpenCode:
{ "host_alias": "prod-db", "command": "df -h", "timeout": 10, "stream_output": true }
CI & PyPI Publishing
-
CI:
.github/workflows/ci.yml会在 push/PR 时运行测试。 -
发布:
.github/workflows/publish.yml会在推送v*标签时构建并发布到 PyPI(使用 Trusted Publishing)。 -
首次发布:如果 PyPI 还没有该项目,先用 API Token 完成首发;首发后再在 PyPI 配置 Trusted Publisher 并切回 OIDC。
-
CI:
.github/workflows/ci.ymlruns tests on push/PR. -
Publish:
.github/workflows/publish.ymlbuilds and publishes onv*tags (Trusted Publishing). -
First publish: if the project does not exist on PyPI, use an API token once; then configure a Trusted Publisher and switch back to OIDC.
发布步骤示例:
Publish example:
git tag v0.1.0
git push origin v0.1.0
Metadata
Release files for remote-bash-tool 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| remote_bash_tool-0.2.0.tar.gz | 34.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| remote_bash_tool-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.1 kB
Release files / remote_bash_tool-0.2.0.tar.gz
| Download URL | remote_bash_tool-0.2.0.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
093b6183d8db866ca6f3eb69f3f56b6284ee0c8d3be320dd3b7a79cf6a567b93
|
|
BLAKE2b-256 checksum How to use checksums |
dfec1ded9da420b82cb8fea2c980013121fb95349f59b236ecc9d9d5ed9226fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.
Transparency logRelease files / remote_bash_tool-0.2.0-py3-none-any.whl
| Download URL | remote_bash_tool-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b698637bcf7aa26abb28992802b42549b8621b939476d10af9c7850bd8930f03
|
|
BLAKE2b-256 checksum How to use checksums |
db4fc6b7d37cfd32704cd732c408b255e72f70e96d78292ee5ccdce3c2f07806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.
Transparency log