前言¶
DSH 插件生態奉行“一切皆插件”的理念。dsh-shell-host 是一個工具級 bundle,它原生支持 MSYS2 (UCRT64) bash,旨在爲 DSH shell 接縫提供持久連接能力。它提供了持久 PTY 會話、預設終端啓動器以及 WSL 橋接工具,與 shell 執行器無關,不提供 ctx.shell 上下文,也不接管上游 loader-row。
核心功能¶
持久 PTY 會話 (./pty)¶
./pty 是持久會話的核心,提供以下能力:
- PTY 管理:通過 src/pty/session-core.ts 實現。提供 pty_open、pty_send、pty_tail、pty_close 四個工具。
- SSH 交互:在 PTY 核心上構建全雙工 SSH 會話,提供 ssh_start、ssh_tail、ssh_send、ssh_close。
- ssh_start({ host, jump?, shell?, port?, options? }):支持標準端口、非標準端口(通過 -p 參數)、Keepalive 默認設置(ServerAliveInterval=15)以及自定義 -o 選項。
- 注意:會話斷開時不會自動重連,需顯式重新調用 ssh_start。
- 限制:默認 maxSessions 爲 8,超時會報錯。
預設終端 (./terminal)¶
./terminal 是啓動器層插件,提供單一工具 shell_open。
- 功能:shell_open(preset, cwd?, env?, idleTimeoutMs?)。它解析預設並通過 ./pty 的核心打開會話。
- 特性:
- 無中間人攔截,直接操作 PTY 核心。
- 支持自定義預設覆蓋內置預設,結果包含 source(來源)、overrode(是否覆蓋)、executable、probed、cwd 等字段。
- 支持可選的 idleTimeoutMs,當會話無新輸出時自動關閉。
WSL 橋接 (./wsl)¶
提供 Windows 訪問工具,供運行在 WSL 內的 agent 使用:
- win_ls、win_read、win_write、win_run、win_open
- win_path、win_drives
架構說明¶
- 非執行器:不包含 shell 執行器邏輯,不提供
ctx.shellprovider。 - 非接管者:不執行上游 loader-row takeover。
- 職責分離:一次性遠程命令屬於獨立的
dsh-shell-remote插件;長生命週期的交互會話(如ssh_start)由本插件處理。
宿主環境要求¶
本 bundle 假定宿主環境已安裝 MSYS2 工具鏈,不負責安裝 MSYS2。若缺失以下工具,agent 驗證手段可能降級:
pacman -S --needed diffutils patch jq unzip rsync
代碼示例¶
PTY 會話¶
import * as pty from 'dsh-shell-host/pty'
// 打開會話
const sessionId = pty.pty_open({ command: 'bash' })
// 發送數據
pty.pty_send(sessionId, 'ls -la\n')
// 查看輸出
const output = pty.pty_tail(sessionId)
SSH 會話¶
import * as pty from 'dsh-shell-host/pty'
// 啓動 SSH 會話
const sshSession = pty.ssh_start({
host: 'example.com',
user: 'admin',
port: 22,
options: '-o ProxyCommand=...' // 支持自定義選項
})
終端啓動器¶
import * as terminal from 'dsh-shell-host/terminal'
// 打開預設終端
const session = terminal.shell_open('pwsh', { cwd: '/tmp', idleTimeoutMs: 30000 })
許可證與鏈接¶
- 許可證:MIT
- 維護者:ch1bug
- GitHub:https://github.com/ch1bug/dsh-shell-host
- 目錄:https://www.skillhub.cn/plugins/ch1bug/dsh-shell-host