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 支持异步调用。

安装与依赖(uv)

uv venv
uv sync

使用方式

示例:在终端中直接执行(无需单独脚本文件):

# 发布到包后(使用 uvx 直接运行)
uvx run 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

也支持模块方式运行:

python -m remote_bash_tool --host-alias prod-db --command "uptime"

查看帮助:

remote-bash --help

示例:在 Python 代码中直接调用工具方法。

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 配置(可选)

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

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

    {
      "host_alias": "prod-db",
      "command": "df -h",
      "timeout": 10,
      "stream_output": true
    }
    

CI 与发布到 PyPI

  • CI:.github/workflows/ci.yml 会在 push/PR 时运行测试。
  • 发布:.github/workflows/publish.yml 会在推送 v* 标签时构建并发布到 PyPI(使用 Trusted Publishing)。

发布步骤示例:

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.1.0.tar.gz (31.9 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.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for remote_bash_tool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6527a9eb254d3e902a2b891063d0e9d28fa1c2780a032c99b56129fc7d3390c5
MD5 deaee53a075c5d6069a4ffd647b1da9c
BLAKE2b-256 261632a24766b80ec00a1e6e6191cfd59381d16268cb6d7cf1f67d43fe29af1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for remote_bash_tool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0295146d47d6476a79ea71228508686560d9fce0ab88d43fbe0db987c35b41
MD5 29e61e75bdcaf68e5413e1b61a142b4d
BLAKE2b-256 456a1220f3e6c4b642db9e0b4c70dcc77b1fbdac9ff44aba60872cab17db7ed6

See more details on using hashes here.

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