Skip to main content

OpenCode custom tool for running remote bash commands over SSH.

Project description

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)

  1. 将工具模块挂载到 OpenCode(示例配置,参考 OpenCode 自定义工具指南进行调整):

  2. Register the tool module in OpenCode (example config, adjust per OpenCode docs):

    tools:
      - name: remote_bash
        module: remote_bash_tool.tool
        entrypoint: run
    
  3. 在 OpenCode 中调用工具:

  4. 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.yml runs tests on push/PR.

  • Publish: .github/workflows/publish.yml builds and publishes on v* 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remote_bash_tool-0.2.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remote_bash_tool-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file remote_bash_tool-0.2.0.tar.gz.

File metadata

  • Download URL: remote_bash_tool-0.2.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for remote_bash_tool-0.2.0.tar.gz
Algorithm Hash digest
SHA256 093b6183d8db866ca6f3eb69f3f56b6284ee0c8d3be320dd3b7a79cf6a567b93
MD5 bfef3619a8c3ed6742742aaf083c5751
BLAKE2b-256 dfec1ded9da420b82cb8fea2c980013121fb95349f59b236ecc9d9d5ed9226fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for remote_bash_tool-0.2.0.tar.gz:

Publisher: publish.yml on blizhan/remote-bash-tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file remote_bash_tool-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for remote_bash_tool-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b698637bcf7aa26abb28992802b42549b8621b939476d10af9c7850bd8930f03
MD5 acb9c734f030327dec98f02537fc1aba
BLAKE2b-256 db4fc6b7d37cfd32704cd732c408b255e72f70e96d78292ee5ccdce3c2f07806

See more details on using hashes here.

Provenance

The following attestation bundles were made for remote_bash_tool-0.2.0-py3-none-any.whl:

Publisher: publish.yml on blizhan/remote-bash-tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page