定制 adachsoft/ssh-tool 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/ssh-tool

Composer 安装命令:

composer require adachsoft/ssh-tool

包简介

SSH integration for AdachSoft AiToolCall — login, remote command execution and session management for pluggable AI tool actions.

README 文档

README

PHP Version License

SSH Tool is a bridge between AdachSoft AiToolCall and SSH operations. It implements the ToolInterface and uses the Strategy pattern to provide clean, testable SSH actions (login, logout, command execution, account management, etc.).

Features

  • Full SSH session management (login/logout)
  • Remote command execution with stdout/stderr/exit code handling
  • Optional per-call timeout for command execution (in milliseconds)
  • Configurable maximum size of returned stdout/stderr (max_output_length) with safe truncation
  • Account listing and details retrieval
  • Strategy/Command pattern for easy extension
  • Strict type safety and comprehensive error handling
  • PHPUnit tests (unit + functional)

Installation

composer require adachsoft/ssh-tool

Usage

1. Configuration

use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;
use AdachSoft\SshTool\Config\SshToolConfigKeyEnum;

$config = new ConfigMap([
    // Required: JSON repository with SSH accounts
    SshToolConfigKeyEnum::JSON_REPOSITORY_FILE_PATH->value => '/path/to/accounts.json',

    // Required: base URL of the SSH HTTP API used by ssh-gate
    SshToolConfigKeyEnum::SSH_API_BASE_URL->value => 'https://your-ssh-api.example.com',

    // Optional: maximum length of stdout/stderr returned to the LLM (default: 10000)
    SshToolConfigKeyEnum::MAX_OUTPUT_LENGTH->value => 10_000,
]);

2. Registering the Tool

use AdachSoft\AiToolCall\PublicApi\Builder\AiToolCallFacadeBuilder;
use AdachSoft\SshTool\Factory\SshToolFactory;

$facade = AiToolCallFacadeBuilder::new()
    ->withSpiFactories([new SshToolFactory()])
    ->withToolConfigs(['ssh' => $config])
    ->build();

3. Available Actions

The tool supports the following actions via the action parameter:

  • login – Authenticates and returns a session token
  • logout – Ends an active SSH session
  • executeCommand – Runs a command on a remote host
  • getAccount – Retrieves details of a specific account
  • listAccounts – Lists all configured accounts (without passwords)
  • listSessions – Lists active sessions

Example call:

use AdachSoft\AiToolCall\SPI\Collection\KeyValueMap;
use AdachSoft\AiToolCall\SPI\Dto\ToolCallRequestDto;

$result = $facade->callTool(new ToolCallRequestDto(
    'ssh',
    new KeyValueMap([
        'action' => 'executeCommand',
        'sessionToken' => 'abc123',
        'command' => 'ls -la',
        // Optional: timeout in milliseconds
        'timeout' => 5_000,
    ])
));

echo $result->result->get('stdout');

4. Timeout and output truncation

  • The optional timeout parameter is validated as a positive integer (in milliseconds) and passed directly to the underlying SshCommandRequest.
  • To protect the conversation context, both stdout and stderr are truncated when their length exceeds max_output_length from configuration (default: 10000).
  • When truncation happens, a notice is appended to the output:
    • "[Output truncated due to length limit]" for stdout
    • "[Error output truncated due to length limit]" for stderr

Development

Running Tests

# Unit + Functional tests
vendor/bin/phpunit

# Production/end-to-end tests (if available)
vendor/bin/phpunit --group production

Code Quality

vendor/bin/rector process --config=rector.php
vendor/bin/php-cs-fixer fix
vendor/bin/phpstan analyse src tests

Architecture

  • SshTool – thin router/delegator
  • SshActionInterface + concrete *Action classes – each action is a separate, testable strategy
  • SshToolFactory – creates facade and injects actions
  • All public documentation is in English per project rules.

License

MIT License – see the LICENSE file for details.

Part of the AdachSoft ecosystem. For more information see adachsoft.com.

adachsoft/ssh-tool 适用场景与选型建议

adachsoft/ssh-tool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「ssh」 「ssh-client」 「session-management」 「command-pattern」 「strategy-pattern」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adachsoft/ssh-tool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adachsoft/ssh-tool 我们能提供哪些服务?
定制开发 / 二次开发

基于 adachsoft/ssh-tool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 41
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-23