Skip to content
dsh.fish
Bundle

@deepseek-ai/dsh-exit-bash

One-click control that closes a session's persistent bash terminal (dual-face: /exit-bash command + session-header button) so the sandbox mode can be switched

Source
12362566
stars
1 stars
License
MIT
Updated
Updated 5 days ago

Readme

# dsh-exit-bash

一个「退出 Bash」按钮 + `/exit-bash` 命令,用来解决:**会话里已经跑过持久 bash 后无法切换沙箱模式**(`cannot change sandbox mode ... while persistent terminal sessions are open or being created`)。

## 原理

- 持久 `bash` 工具(`dsh-tool-bash-persistent`)的 PTY shell 在任务结束后仍存活;
- `dsh-terminal-bash` 在每次 `sandbox/mode` 事件提交前检查该 agent 是否还有活的 PTY(`hasOwnerActivity`),有就拒绝切换;
- 本插件的宿主半边注册 `/exit-bash` 命令:先给 shell 发 `exit`(宽限 `graceMs` 毫秒),再 `terminals.kill` 移除 PTY 记录,并中止仍在创建中的 spawn;
- 浏览器半边在会话头(agent preset 标签旁)放一个按钮,点击直接通过 `remote.commands.execute` 执行 `/exit-bash`(不经过 `commandUi`,避免 `commandUi` 内部拿不到 `remote.commands` 导致按钮无效)。命令结果以流程节点显示在对话里。

## 安装

```bash
dsh plugin --profile web add /path/to/dsh-exit-bash
# 重启 profile 使新的 bundle 层与客户端插件清单生效:
dsh web   # 重新启动你的 web profile
```

> 客户端插件清单(`dsh.client` 扫描)在启动时缓存,必须重启进程;宿主命令本身在 cordis 层支持热重载,但一次重启即可两者兼得。

## 使用

1. 任务跑完后,点击会话头部的 **退出 Bash** 按钮(或在输入框执行 `/exit-bash`);
2. 看到「已关闭 N 个持久终端」的流程节点后,再用输入框的权限选择器切换沙箱模式即可成功。

## 已知行为

- 会话没有持久终端(如 standard preset 的一次性 bash)时,命令返回「无需关闭」。
- 关闭后 agent 下一次调用 bash 会**重新创建一个终端**,且新终端按**切换后的沙箱模式**隔离运行——这正是期望行为。
- 若在 agent 正在执行 bash 命令时点击按钮,正在进行的工具调用会被终止(等同用户强制关闭终端)。

## 配套补丁(重要)

`dsh-tool-bash-persistent` 会缓存每个 agent 的 PTY id;外部用 `/exit-bash` 直接 `terminals.kill` 后,工具缓存仍指向旧 id,下一次 `bash` 调用会先报一次 `unknown PTY session ...` 再自愈。为了让「退出 Bash」后**下一次调用直接成功**,需要给 `@deepseek-ai/dsh-tool-bash-persistent` 打上本包附带的补丁:

```bash
# 在 web profile 目录执行(请先确保该目录可写)
cd ~/.dsh/profiles/web
cp /path/to/dsh-exit-bash/patches/@deepseek-ai__dsh-tool-bash-persistent.patch patches/
```

然后在 `pnpm-workspace.yaml` 的 `patchedDependencies` 中加入:

```yaml
patchedDependencies:
  '@deepseek-ai/dsh-tool-bash-persistent': patches/@deepseek-ai__dsh-tool-bash-persistent.patch
```

再执行:

```bash
pnpm install
dsh web
```

补丁会让 `persistentShells.get()` 在复用缓存的 PTY id 前先确认该 id 仍存在于 `terminals` 注册表;已被 `/exit-bash` 关闭时自动丢弃旧缓存并创建新终端,不再把 `unknown PTY session` 暴露给模型。

Install

dsh plugin --profile web add github:12362566/dsh-exit-bash

Profile: web

  • This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.
Source