rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
HuanLinOTO/dsh-plugin-sidebar-terminal-tools
DSH plugin: model-driven official sidebar terminals — six sidebar_terminal_* tools over ctx.terminalController; terminals auto-appear as native sidebar tabs, the user can take over anytime. / DSH 插件:模型驱动官方侧栏终端,自动出现原生终端 tab,用户可随时接管。
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:HuanLinOTO/dsh-plugin-sidebar-terminal-tools
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
DSH plugin that gives the model six sidebar_terminal_* tools over the official right-sidebar terminal stack (ctx.terminalController), which upstream exposes with no model-facing entry point. Terminals the model opens appear in the user's sidebar automatically as native terminal tabs, and the user can take over input at any time.
DSH 插件:把官方右侧栏终端(ctx.terminalController,上游零模型入口)通过 6 个 sidebar_terminal_* 工具交给模型驱动。模型开的终端会自动出现在用户侧栏成为官方终端 tab,用户可随时点「接管」亲自输入。
[!WARNING] 安全警告 / Security warning
- 这些终端以系统用户权限运行,不套 Agent 沙箱、不走审批(
terminalController的上游刻意设计,供人手操作;本插件把它交给模型)。启用即表示你接受模型可以在你的桌面/服务器上直接执行命令。- These terminals run with your system user's permissions, outside the Agent sandbox and the approval pipeline — that is an upstream property this plugin deliberately exposes to the model.
- 建议在 permission 规则里按工具名
sidebar_terminal_*加闸(至少对sidebar_terminal_open/sidebar_terminal_send要求确认)。- Consider gating
sidebar_terminal_*in your permission rules before enabling.- 与用户手动终端共享每会话
maxTerminals=8配额;模型开满后你自己就开不了了(反之亦然)。Terminals share the per-session quota of 8 with your manual sidebar terminals.- 无提权能力:OS / 容器层面的限制仍然生效。No privilege escalation: OS / container limits still apply.
| 工具 | 说明 |
|---|---|
sidebar_terminal_open |
开一条新终端(id stb-*),自动出现在侧栏;返回 terminalId/shell/cwd/cols/rows/state;配额满时返回 limit_reached。 |
sidebar_terminal_send |
向终端写输入(默认追加回车)。用户接管中时自动夺回控制权再写入,返回 regained_control: true。 |
sidebar_terminal_read |
读该终端的纯文本转录(ANSI 已清洗、行/字节有界、offset 从最新端计数的分页)。 |
sidebar_terminal_wait_for |
阻塞等待正则在转录中出现,返回五态之一:found / timeout / exited / gone / cancelled(核心与单测取自上一代插件 terminal-extension-wait-for)。 |
sidebar_terminal_close |
关闭终端(杀 shell)并释放转录。 |
sidebar_terminal_list |
列出本会话经本插件打开的终端(状态、行数、当前控制者是 plugin / user / none)。 |
只操作本插件创建并登记的 (sessionId, terminalId):用户手动开的终端永远不会被这些工具碰到。模型与用户对输入是同等地位:谁最后 attach 谁持有;用户接管后模型会收到一条注入提醒("用户可能执行了自己的命令"),下一次 send 自动收回控制。
English summary: six tools (open/send/read/wait_for/close/list) drive real sidebar terminals the user can watch and take over; transcripts are ANSI-cleaned and bounded; wait_for synchronizes on regex cues instead of busy-polling; only plugin-created terminals are reachable.
# from npm (recommended):
dsh plugin --profile web add @huanlin/dsh-plugin-sidebar-terminal-tools
# from a local checkout (dev):
dsh plugin --profile web add link:D:\Projects\deepseek-harness\dsh-plugin-sidebar-terminal-tools
预构建策略:lib/ 入库(含 host 与 client 双产物),无 prepare 脚本,npm 安装开箱即用。
挂载位置:本插件必须挂在 profile 根级(dsh plugin add 的默认行为)——terminalController 服务在 web-app 根 realm 提供,进任何 preset/isolate 组都注入不到。cordis.patch.yml 已按根级 insert 编写,不要把它挪进 preset 的 patch 组。
在 DSH GUI 设置页或 cordis.patch.yml 中配置(host half):
| 字段 | 默认 | 说明 |
|---|---|---|
transcriptLines |
5000 |
每终端保留转录行数 |
transcriptBytes |
1048576 |
每终端保留转录字节上限(1 MiB) |
defaultTimeoutMs |
10000 |
wait_for 缺省超时 |
minTimeoutMs / maxTimeoutMs |
100 / 600000 |
wait_for 超时钳制边界 |
pollIntervalMs |
150 |
wait_for 轮询间隔 |
tailLines / maxLineTextChars / maxTailBytes |
30 / 1000 / 8192 |
wait_for 摘录边界 |
maxMessageChars |
2000 |
用户接管提醒的长度上限 |
Client half(web 客户端配置层)可配 pollIntervalMs(活动窗口内的发现间隔,默认 3000ms,最小 250ms)。空闲时不发任何请求——见下方 Client half 说明。
src/index.ts + endpoint/attachment/registry/sanitize/wait-for):结构影子类型消费 ctx.terminalController(不 import @deepseek-ai/dsh-api-terminal-controller);每条终端一个 duplex attach 消费者(host 侧经合成 Remote invocation——gateway 分发同款 ctx.extend 机制——取得 RemoteStream,编号 TerminalInput 命令上行、snapshot/output/state/ack 帧下行),snapshot/output 经 ANSI 清洗进有界转录,state 帧维护 state/exitCode 并以 writable 位判定输入控制权(0.2.1 起上游移除 info.controllerId),用户接管时 agent.inject 一条提醒(同一接管会话只提醒一次)。src/client/,产物 lib/client.js 以 window.__ModuleLoader__.load({ id: <package name>, factory }) 注册):按活动窗口发现,不空闲轮询。Host 不推送终端列表,每次发现都是一次 POST /api/terminal/list 往返,因此不再按定时器轮询所有会话,而是订阅宿主转发的 api-session/status Remote Event(ctx.remote.$on,每回合 idle ⇄ running 各一次):running: true 打开该 Session 的活动窗口,窗口内每 pollIntervalMs 调一次 ctx.webTerminals.recover(sessionId, true)(必须带 refresh,缓存读会让回合中新开的终端永远不出现);running: false 关窗并收尾查一次;空闲页面零请求。窗口上限 MAX_ACTIVITY_WINDOW_MS(10 分钟)防止状态事件丢失导致无限轮询;宿主不支持转发事件(interactions=none)时退回旧的定时轮询。发现的 stb- 前缀终端用 ctx.sidebarRight.openTabIn() 开成官方 terminal tab,openTabIn 会展开侧栏列但不抢键盘焦点;上游本就把它设计为"打开即可见"。pnpm install # 需要本地 DSH checkout 的 link: devDependencies
pnpm test # vitest(84 例:wait_for 核心 23 + sanitize/endpoint/tools/client)
pnpm run typecheck # host + client 两个 tsconfig
pnpm run build # lib/index.js(host)+ lib/client/*.d.ts + lib/client.js(client bundle)
dsh plugin --profile web add @huanlin/dsh-plugin-sidebar-terminal-tools
# 重启 dsh web,浏览器硬刷新(client half 是启动图的一部分)
真机验收路径:让模型 sidebar_terminal_open → 侧栏自动出现终端 tab → sidebar_terminal_send("ping -n 4 127.0.0.1") → sidebar_terminal_wait_for("(Ping 统计|丢失)") → 你点「接管」输入一条命令 → 模型下一条 sidebar_terminal_read 能看到你的命令,且收到一条接管提醒。
cordis.patch.yml 一行 insert;不修改任何上游文件terminalController + 结构影子类型(src/shadow.ts)sidebar_terminal_、终端 id 前缀 stb-,均不与上游冲突npm pack --dry-run 清单仅 lib/ + cordis.patch.yml + README/LICENSE/package.jsonAGPL-3.0(wait_for 核心取自同一作者的 dsh-plugin-terminal-extension-wait-for @ 4dae4b8)
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: model、模型。