dsh-bash-terminal-ts 0.8.8 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +201 -190
- package/README.en.md +2 -1
- package/README.md +3 -2
- package/agent-presets/README.md +171 -170
- package/agent-presets/install-presets.mjs +180 -179
- package/agent-presets/standard-win-niu/agent.cordis.yml +271 -0
- package/agent-presets/standard-win-niu/preset.yml +2 -0
- package/cordis.patch.yml +84 -83
- package/dist/client.core.js +10 -1
- package/dist/client.js +10 -1
- package/docs/dsh-plugin-development.md +169 -0
- package/docs/niu-backend.md +197 -0
- package/dsh.plugin.json +3 -3
- package/lib/client.js +10 -1
- package/lib/dsh-types.d.ts +14 -2
- package/lib/index.d.ts +15 -2
- package/lib/index.js +43 -5
- package/lib/locales.js +9 -0
- package/lib/shell-id.d.ts +1 -1
- package/lib/shells.d.ts +1 -0
- package/lib/shells.js +8 -2
- package/lib/terminal.js +4 -0
- package/lib/webterminals/host.js +2 -2
- package/lib/webterminals/mount.js +1 -0
- package/locale/de.json +6 -6
- package/locale/en.json +6 -6
- package/locale/es.json +6 -6
- package/locale/fr.json +6 -6
- package/locale/it.json +6 -6
- package/locale/ja.json +6 -6
- package/locale/ko.json +6 -6
- package/locale/ru.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +151 -149
- package/scripts/check-artifacts.mjs +96 -96
- package/src/client.tsx +685 -685
- package/src/dsh-types.ts +332 -320
- package/src/index.ts +1316 -1275
- package/src/locales.ts +461 -452
- package/src/shell-id.ts +11 -11
- package/src/shells.ts +279 -272
- package/src/terminal.ts +616 -612
- package/src/webterminals/host.ts +361 -361
- package/src/webterminals/mount.ts +237 -236
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# DSH 插件开发沉淀(dsh-bash-terminal-ts 实战)
|
|
2
|
+
|
|
3
|
+
从零开发一个交付级 DSH 插件(shell 三终端 + 沙箱 + 交互式 PTY + 原生设置 UI)的经验总结。
|
|
4
|
+
面向"下一个 DSH 插件开发者",按"正确范式 → 关键机制 → 踩坑清单 → 测试/CI → 发布"组织。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 一、DSH 插件架构(官方范式)
|
|
9
|
+
|
|
10
|
+
### 1. Bundle manifest(插件分发标准)
|
|
11
|
+
|
|
12
|
+
插件包声明 `dsh.bundle.patch`(指向包内 `cordis.patch.yml`),profile 在
|
|
13
|
+
`dsh.profile.bundles` 列出包名后 **DSH 自动应用挂载**,无需手改 profile 配置。
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
// package.json
|
|
17
|
+
"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
# cordis.patch.yml(包内,bundle 层)
|
|
22
|
+
- insert:
|
|
23
|
+
- id: my-plugin
|
|
24
|
+
name: my-plugin
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
安装:`dsh plugin --profile <p> add <pkg>`(或 profile bundles 手动加)。
|
|
28
|
+
**验证**:`dsh --profile <p> --dump-config` 看 entry 是否出现。
|
|
29
|
+
|
|
30
|
+
### 2. Host / Client 双面
|
|
31
|
+
|
|
32
|
+
- **Host 面**(`lib/index.js`):服务端逻辑(工具注册、settings、subprocess)—— cordis 插件,`inject` 声明依赖,`apply(ctx, config)`。
|
|
33
|
+
- **Client 面**(浏览器):`package.json` 声明 `dsh.client: { platform: "web" }` + `exports["./client"]`,源码打包成
|
|
34
|
+
`window.__ModuleLoader__.load({ id, factory: (require) => ... })` 格式,host 通过
|
|
35
|
+
`/plugins/<name>/client.js` 动态服务,浏览器端注入 `__DSH_BOOT__`。
|
|
36
|
+
- **共享模块**(浏览器 require 可用)= 壳层种子表 `PLATFORM_MODULES`。0.1.5-rc.1 的精确条目:
|
|
37
|
+
`react`、`react/jsx-runtime`、`react-dom`、`react-dom/client`、`@deepseek-ai/cordis`、
|
|
38
|
+
`@deepseek-ai/dsh-client-store`、`@deepseek-ai/dsh-client-ui-slots`、
|
|
39
|
+
`@deepseek-ai/dsh-client-ui-primitives`、`@deepseek-ai/dsh-client-ui-dockkit`
|
|
40
|
+
—— 打包时 **external**(`esbuild --external:@deepseek-ai/* --external:react*`)。
|
|
41
|
+
- ⚠️ 种子表**按精确裸名命中**:`@deepseek-ai/dsh-client-store/client` 这类子路径**不会**命中
|
|
42
|
+
(`stripClientSuffix` 只对 boot graph 的动态包行生效,对种子词不生效)。旧名
|
|
43
|
+
`dsh-client-runtime` 在 0.1.5 已从种子表消失 → 运行时 `require` 直接抛
|
|
44
|
+
"missed the module table",Web GUI 冒 "Failed to load plugins"。
|
|
45
|
+
升级 DSH 后先确认自己要的模块在种子表里怎么拼。
|
|
46
|
+
- 需要**非种子**模块时,用 `dsh.client.external` 列出精确 specifier(host 会把该动态包行排到消费者之前);
|
|
47
|
+
`dsh.client.inject` 只表达包级依赖边(组合顺序),列种子词合法且无副作用。
|
|
48
|
+
|
|
49
|
+
### 3. 依赖注入规范
|
|
50
|
+
|
|
51
|
+
- `inject` 声明依赖(服务名:`tools`、`settings`、`subprocess`、`sandbox`、
|
|
52
|
+
`sandboxPolicy`、`shellEnv`、`systemPrompt`、`jobs` 等)。
|
|
53
|
+
- 注册副作用用 `ctx.effect` 返回 disposer;无全局可变状态;进程派生走 `ctx.subprocess`。
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 二、关键机制
|
|
58
|
+
|
|
59
|
+
### 1. Settings(用户配置)
|
|
60
|
+
|
|
61
|
+
- 注册(0.1.5):`ctx.settings.register("ns", z.object({...}), { base })` —— 旧的
|
|
62
|
+
`settingsNamespace("ns")` 包装函数已从 `@deepseek-ai/dsh-settings` 移除(0.1.0 时代产物);
|
|
63
|
+
命名空间必须是「小写字母开头 + 小写字母/数字/连字符」的字符串。
|
|
64
|
+
- 读取:`scope.get()`(每次 update 后更新 resolved,无需 watch)
|
|
65
|
+
- ~~白名单限制~~ **已作废**:0.1.5 的 Web 设置面走 `settings.describe()` 动态枚举已注册 namespace,
|
|
66
|
+
不再有硬编码白名单,`settings-not-exposed` 也不存在了(`install.ps1` 的白名单 patch 属历史遗留)。
|
|
67
|
+
- **原生设置行**:注册 `settings.general.item` slot(通用设置区)。**UI 必须照官方
|
|
68
|
+
EnterBehaviorRow 语法**(不是凭感觉):row 布局(标题+描述左、selector 右)、
|
|
69
|
+
`border-bottom: 1px solid var(--dsw-alias-border-l2)`、16px padding、
|
|
70
|
+
标题 14px/400 `label-primary`、描述 12px `label-tertiary`、胶囊 selector
|
|
71
|
+
(`bg-module-platform` + 18px 圆角 + chevron 图标 + `align="end"` portal Menu)。
|
|
72
|
+
CSS 用 `<style data-plugin-css>` 注入(与第一方行同构)。
|
|
73
|
+
|
|
74
|
+
### 2. Sandbox(沙箱接缝)
|
|
75
|
+
|
|
76
|
+
- `ctx.sandboxPolicy.resolve({ session })` → `{ mode, workspaceRoot, sessionId }`
|
|
77
|
+
- `ctx.sandbox.confine(argv, policy)` → `{ argv: [...runner, "--", ...argv], enforcement, denialSignatures, runnerFailureRules }`
|
|
78
|
+
- 语义:`danger-full-access` 不包装;受限模式 **fail-closed**(后端不可用抛
|
|
79
|
+
`SandboxUnavailableError`,拒绝裸跑 —— 与官方 executor 一致)。
|
|
80
|
+
- 例外:Git Bash 因 Cygwin/MSYS2 与 Windows ACL 受限令牌不兼容(`CreateFileMapping`
|
|
81
|
+
Win32 error 5),在本插件中与 WSL 一样不经过 `ctx.sandbox.confine` 包装;
|
|
82
|
+
结果报告 `enforcement: gitbash-unconfined`。
|
|
83
|
+
- 升级契约:`sandbox_permissions`(enum `ESCALATION_TARGETS`)+ `justification`,
|
|
84
|
+
经 `approveEscalation`(`ctx.approval`)严格宽化校验;被拒时渲染官方标记
|
|
85
|
+
`[sandbox: file access denied under <mode> mode]` + 升级提示。
|
|
86
|
+
- Windows 后端 = ACL restricted-token launcher(`node-addon-landlock-run-win32-x64`)——
|
|
87
|
+
可用时负责 PowerShell 的受限包装;Git Bash 因 Cygwin/MSYS2 不兼容保持不包装。
|
|
88
|
+
|
|
89
|
+
### 3. Subprocess / PTY
|
|
90
|
+
|
|
91
|
+
- `ctx.subprocess.spawn(spec)`:`{ argv, cwd, stdio, graceMs, signal, env }`,
|
|
92
|
+
handle 有 `collected`(stdout/stderr 读取器)、`done`、`terminate()`。
|
|
93
|
+
- `ctx.subprocess.spawnTerminal(spec)`(node-pty/ConPTY):`{ argv, cwd, env, rows, cols, graceMs }`
|
|
94
|
+
→ handle:`write(data)`、`output`(Readable)、`done`、`signalForeground(sig)`、
|
|
95
|
+
`terminate()`。
|
|
96
|
+
- 交互式终端设计要点:会话注册进 jobs(`job_kill` 可管理)、**空闲超时自动关闭**
|
|
97
|
+
(防 PTY 进程树泄漏)、缓冲上限 + 截断提示、settle 读取(等输出稳定返回完整回复)。
|
|
98
|
+
|
|
99
|
+
### 4. Jobs(后台任务)
|
|
100
|
+
|
|
101
|
+
`jobs.start({ kind, label, owner, run: () => ({ cancel?, done, readOutput? }) })` → jobId。
|
|
102
|
+
`done` 是 Promise<JobOutcome>;`readOutput` 增量读。工具 `run_in_background` 参数即此。
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 三、踩坑清单(血泪)
|
|
107
|
+
|
|
108
|
+
1. **`node_modules/@deepseek-ai` 必须是 junction(本机开发)**。DSH 的 Loader 走 Node 原生
|
|
109
|
+
解析,而插件真实路径在 profile 外面(`D:\workspace\...`):只有这个 junction 能让插件
|
|
110
|
+
和宿主**共用同一份** `@deepseek-ai/*` 模块实例;否则会落回插件自带的副本(历史上曾因此
|
|
111
|
+
停留在 0.1.0-rc.6,而宿主已经是 0.1.5)。⚠️ **npm install 会删掉这个 junction 并装一份新副本**
|
|
112
|
+
(更早还曾反过来清空 junction 指向的 profile 依赖树)——依赖用 junction 时,插件项目里
|
|
113
|
+
只跑 `npm install --package-lock-only`(只改 lock,不碰 node_modules)+ `npm pack --dry-run` 验证产物。
|
|
114
|
+
本机现状:`New-Item -ItemType Junction -Path D:\workspace\projects\dsh-bash-terminal-ts\node_modules\@deepseek-ai -Target $env:USERPROFILE\.dsh\profiles\node_modules\@deepseek-ai`。
|
|
115
|
+
2. **PowerShell 5.1 `Set-Content -Encoding UTF8` 写 BOM** → DSH 的 JSON.parse 崩溃
|
|
116
|
+
(`Unexpected token ''`)。改 profile package.json 必须无 BOM
|
|
117
|
+
(`[System.IO.File]::WriteAllText($p, $json, (New-Object System.Text.UTF8Encoding($false)))`)。
|
|
118
|
+
3. **Windows ConPTY 兼容性**:
|
|
119
|
+
- Windows PowerShell 5.1 在某些受限环境无法在 ConPTY 启动(0x8009001d,证书类错误)——
|
|
120
|
+
可能是环境特殊而非普遍;普通用户机器大概率正常(需实测确认)。
|
|
121
|
+
- `wsl -e bash -i`(默认发行版)在 ConPTY 下失败(Wsl/Service/0x8007072c,RPC 句柄
|
|
122
|
+
类型不匹配)→ 改用 `wsl -- bash -i` 即正常;显式 `-d <distro>` 时 `-e` 正常。
|
|
123
|
+
- `AttachConsole failed` 是 node-pty 在非控制台宿主的清理钩子噪声,不影响功能。
|
|
124
|
+
4. **`defineStore(decl)` 返回 `{ spec, create }`**(0.1.5 从 `@deepseek-ai/dsh-client-store` 导入,
|
|
125
|
+
旧名 `dsh-client-runtime`),不是 store!真正 store(含 actions)
|
|
126
|
+
由 `slots.register` 内部 `create()` 生成 —— 在 `inject` 回调里绑定 actions 并
|
|
127
|
+
push 初始快照(theme 行模式)。
|
|
128
|
+
5. **测试断言路径大小写**:CI(windows-latest)的 `SystemRoot` 是 `C:\Windows`,
|
|
129
|
+
本机可能是 `C:\WINDOWS` —— 断言必须动态取 `process.env.SystemRoot`,别硬编码。
|
|
130
|
+
6. **client/terminal 测试跨环境模块解析**:本机 react/node-pty 在 profile 依赖树,
|
|
131
|
+
CI 没有 → 双路径解析(`createRequire(import.meta.url)` 优先,profile fallback),
|
|
132
|
+
CI workflow 用 `npm install react react-dom node-pty --no-save`。
|
|
133
|
+
7. **run_code 模板字符串转义**:往文件写含 `\r`/`\n`/反引号的内容时,外层模板会
|
|
134
|
+
提前解析(`\r` 变真实 CR → JS 源码语法错;反引号需转义)。用数组 join 或
|
|
135
|
+
仔细转义。
|
|
136
|
+
8. **React 组件测试**:直接调用组件函数会触发 hook 违规(`useState` 在渲染器外)。
|
|
137
|
+
用 `react-dom/server` 的 `renderToString(createElement(Component, props))`。
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 四、测试与 CI
|
|
142
|
+
|
|
143
|
+
- 套件:unit(纯函数)、apply(mock ctx 集成)、client(__ModuleLoader__ 模拟 + 真实
|
|
144
|
+
React 渲染)、terminal(**真实 node-pty** 交互会话)。
|
|
145
|
+
- 环境相关测试宽容处理(PowerShell 5.1 / wsl 无发行版时 NOTE 跳过而非失败)。
|
|
146
|
+
- CI:windows-latest + `npm install react react-dom node-pty --no-save` +
|
|
147
|
+
`node scripts/build-client.mjs`(先 build client 再跑 client 测试)。
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 五、发布
|
|
152
|
+
|
|
153
|
+
```powershell
|
|
154
|
+
node scripts/build-client.mjs # 重建 client bundle
|
|
155
|
+
npm pack --dry-run # 检查内容(lib/dist/src/cordis.patch.yml/README/LICENSE)
|
|
156
|
+
npm publish --otp <验证码> # 2FA 账号需要
|
|
157
|
+
git tag v<version> && git push origin v<version>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 六、设计原则(对照 DSH 15 条)
|
|
163
|
+
|
|
164
|
+
- 依赖走 `inject`;副作用 `ctx.effect` 返回 disposer;无全局可变状态;
|
|
165
|
+
能力封装成 seam(消费官方 `ctx.sandbox`/`ctx.subprocess`/`ctx.jobs` 而非重造);
|
|
166
|
+
外部副作用(进程)有逆(terminate/teardown)。
|
|
167
|
+
- **侵入性边界**:插件 = 独立可卸载的 bundle 增量,不替换官方 `ctx.shell` provider
|
|
168
|
+
(tool-pwsh 是 PowerShell 专用消费者,替换会破坏契约)、不禁用官方工具 ——
|
|
169
|
+
"原生"是融入而不破坏。
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Niubash(niu)第六后端 · 集成记录
|
|
2
|
+
|
|
3
|
+
> 交付版本:`dsh-bash-terminal-ts@0.9.0` · 分支 `feat/niu-shell-backend` · 2026-11-16
|
|
4
|
+
> 本文件记录集成依据、实测证据与已知边界,供后续排障与跨版本适配对照。
|
|
5
|
+
|
|
6
|
+
## 1. 为什么要加 niu
|
|
7
|
+
|
|
8
|
+
Git Bash 与 MSYS2 都跑在 MSYS2 的 POSIX 模拟层上,这带来两个结构性代价:
|
|
9
|
+
|
|
10
|
+
1. **无法被 DSH 的 Windows ACL 受限令牌 runner 包裹**。`src/index.ts` 顶部注释记录:bash 在受限令牌下启动即 `CreateFileMapping … Win32 error 5` 中止,因此二者被设计为 unconfined。也就是说这个插件此前**没有任何一个既跑 POSIX 语法、又守沙箱的后端**。
|
|
11
|
+
2. **bash 版本停在 5.2**。Git for Windows 捆绑的是 5.2 线,5.3 的语法不可用。
|
|
12
|
+
|
|
13
|
+
niu 是 Rust 原生二进制、无 MSYS/Cygwin 模拟 DLL、引擎对齐 GNU Bash 5.3.20 语义,因此是第一个可能同时满足「POSIX 语法」与「受限沙箱」的候选。**但沙箱结论尚未在农场格证实**,见 §5。
|
|
14
|
+
|
|
15
|
+
## 2. 后端接线面(与 payload 同构的一等后端)
|
|
16
|
+
|
|
17
|
+
| 接线点 | 文件 | 内容 |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| 类型 | `src/shell-id.ts` | `ShellId` 增加 `"niu"` |
|
|
20
|
+
| 后端列表 | `src/index.ts` | `SHELLS` 六项 |
|
|
21
|
+
| 优先级 | `src/shells.ts` | `["powershell","gitbash","msys2","wsl","niu","payload"]`(niu 在 payload 之前,payload 仍末位兜底) |
|
|
22
|
+
| 显示名 | `src/shells.ts` | `LABELS.niu = "Niubash"` |
|
|
23
|
+
| 路径槽 | `src/dsh-types.ts` | `ResolvedPaths.niu?: string` |
|
|
24
|
+
| 路径探测 | `src/index.ts` | `candidateNiuPaths()` |
|
|
25
|
+
| 模型侧 argv | `src/index.ts` | `[niu, "-lc", command]` |
|
|
26
|
+
| 交互 argv | `src/terminal.ts` / `src/shells.ts` | `[niu, "-i"]`(读 `~/.niubashrc`) |
|
|
27
|
+
| 开关 | `src/index.ts` | `shellNiu`(默认 `true`,检测到即可用) |
|
|
28
|
+
| 路径覆写 | `src/index.ts` | `niuPath`(默认 `""` = 自动探测) |
|
|
29
|
+
| 开关写回 | `src/webterminals/host.ts` / `mount.ts` | `SWITCH_FIELD.niu = "shellNiu"` |
|
|
30
|
+
| 客户端下拉 | `src/client.tsx` | `SHELLS` 六项 |
|
|
31
|
+
| 宿主菜单候选 | `cordis.patch.yml` | `- niu.exe` |
|
|
32
|
+
| 本地化 | `src/locales.ts` + `locale/*.json` | 九语 `shell.niu` |
|
|
33
|
+
|
|
34
|
+
### 路径探测顺序
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
%LOCALAPPDATA%\Programs\Niubash\niu.exe ← 安装器默认落点
|
|
38
|
+
%LOCALAPPDATA%\Microsoft\WinGet\Links\niu.exe
|
|
39
|
+
%ProgramFiles%\Niubash\niu.exe
|
|
40
|
+
PATH 各段 \niu.exe
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**大小写陷阱**:安装器写入注册表 User Path 的是大写 `Niubash`。首候选必须匹配该大小写——在大小写敏感文件系统上是硬要求(Windows 自身不敏感,但候选表要能解释自己)。
|
|
44
|
+
|
|
45
|
+
### 菜单候选命名铁律
|
|
46
|
+
|
|
47
|
+
候选表只能写 `niu.exe`,**绝不能**写 `winuxcmd\bin\bash.exe`。
|
|
48
|
+
|
|
49
|
+
`discoverShells` 按可执行文件名去重并保留最早一条;`bash.exe` 这个键在 Windows 上已经被 `C:\Windows\System32\bash.exe`(WSL 转发器)占着。一旦把 niu 的 bash 硬链接放进候选表,就会抢走该键并把 WSL 挤出菜单。
|
|
50
|
+
|
|
51
|
+
## 3. 已修复的阻断级缺陷(0.9.0)
|
|
52
|
+
|
|
53
|
+
### 3.1 `ShellId` 双份定义漂移
|
|
54
|
+
|
|
55
|
+
`src/dsh-types.ts` 与 `src/shell-id.ts` 曾各持一份联合类型,前者漏了 `niu`,而 `index.ts` 恰好从前者 import。
|
|
56
|
+
|
|
57
|
+
后果链:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
SHELL_DESCRIPTIONS: Record<ShellId, string> ← 只在 dsh-types 的五值联合下检查
|
|
61
|
+
→ 缺 niu 键,编译期不报错
|
|
62
|
+
→ toolDescription(true, "niu") 里 lead === undefined
|
|
63
|
+
→ 提示词出现双空格空洞("...is niu; commands run there. Each call...")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**修法**:`dsh-types.ts` 改为 `export type { ShellId } from "./shell-id.js"`,单一真源。
|
|
67
|
+
|
|
68
|
+
**防复发**:`test/unit.ts` 的键集断言由手写五元组改为**从运行时 `SHELLS` 派生**:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
assert.deepStrictEqual(Object.keys(SHELL_DESCRIPTIONS).sort(), [...SHELLS].sort());
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
今后任何后端漏写 lead 句都会先让测试变红,而不是静默进提示词。
|
|
75
|
+
|
|
76
|
+
### 3.2 `SHELL_DESCRIPTIONS` 缺 niu 键
|
|
77
|
+
|
|
78
|
+
随 3.1 一并修复,同时补 `niu` 专属 lead 句(`niu -lc`、WinuxCmd、bash 5.3、无 MSYS 层、`~/.niubashrc`)。
|
|
79
|
+
|
|
80
|
+
### 3.3 顺带修掉 main 的 lint 红灯
|
|
81
|
+
|
|
82
|
+
合入 `origin/main` 后,`test/terminal.ts:222` 的 ANSI 剥离正则触发 `no-control-regex`。该问题自 main 的 `8e2f773` 起就存在——**main 自己的 lint 本来就是红的**。
|
|
83
|
+
|
|
84
|
+
改为 `String.fromCharCode(27)` 拼 `RegExp`,语义不变。
|
|
85
|
+
|
|
86
|
+
## 4. 实测证据(本机 Windows,2026-11-16)
|
|
87
|
+
|
|
88
|
+
### 4.1 niu 运行时
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
$ niu --version
|
|
92
|
+
Niubash 1.5.0 — bash-compatible shell for Windows, Linux, macOS, and Android
|
|
93
|
+
rubash git 29bbf52481c3
|
|
94
|
+
winuxcmd WinuxCmd 1.2.1
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 4.2 三形态冒烟
|
|
98
|
+
|
|
99
|
+
| 形态 | 命令 | 结果 |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| 登录 + 命令 | `niu -lc 'echo hi; uname; git --version; ls'` | exit 0,四段输出齐 |
|
|
102
|
+
| 非登录 + 命令 | `niu -c 'echo $BASH_VERSION'` | `5.3.20(1)-release` |
|
|
103
|
+
| 交互 | `niu -i` | 提示符正常响应 |
|
|
104
|
+
| PTY(node-pty) | `niu -i` + `echo PTY_NIU_OK=$BASH_VERSION` | PASS |
|
|
105
|
+
|
|
106
|
+
`uname` 报 `MSYS_NT-10.0-26300`——**这是为脚本兼容的自称,引擎是原生 Rust**,不能据此推断存在 MSYS 运行时。
|
|
107
|
+
|
|
108
|
+
`git` 为 `2.56.0.windows.4.niugit`:git-for-windows C 源码用 MSVC 构建,无 launcher 跳转。
|
|
109
|
+
|
|
110
|
+
### 4.3 路径解析
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
resolved paths: {
|
|
114
|
+
pwsh: ...WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe
|
|
115
|
+
gitbash: C:\Program Files\Git\bin\bash.exe
|
|
116
|
+
msys2: C:\msys64\usr\bin\bash.exe
|
|
117
|
+
wsl: C:\Windows\System32\wsl.exe
|
|
118
|
+
niu: C:\Users\<you>\AppData\Local\Programs\Niubash\niu.exe ← 命中
|
|
119
|
+
}
|
|
120
|
+
buildArgv("niu", "echo hi") → [<niu.exe>, "-lc", "echo hi"]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 5. 已知边界与未决项
|
|
124
|
+
|
|
125
|
+
### 5.1 沙箱包裹决策(未裁决)
|
|
126
|
+
|
|
127
|
+
`findings` F2 的假设是「niu 可能能在 confined 模式跑」。本机对照实验**无区分度**(danger-full-access 会话里两种 shell 都 exit 0,未触及 ACL 受限令牌面),结论**既未被证实也未被证伪**。
|
|
128
|
+
|
|
129
|
+
当前实现:niu 分支**不加 `ctx.sandbox` 包裹**,与 gitbash/msys2/wsl 同为 unconfined。待农场格真 confined 实测后再裁决。
|
|
130
|
+
|
|
131
|
+
### 5.2 `--ec`(base64 命令传输)未落地
|
|
132
|
+
|
|
133
|
+
niu 支持 `niu --ec <base64>`,可规避 Windows 引号重写、`$` 展开、反斜杠塌缩、CRLF 转换。但 `-l` 与 `--ec` 能否叠加未验证,且 base64 会降低失败可读性。先以 `-lc` 跑通,加固留待后续。
|
|
134
|
+
|
|
135
|
+
### 5.3 无 digest 门禁
|
|
136
|
+
|
|
137
|
+
与 `payload` 的严格姿态不一致:payload 要求 SHA-256 命中内置台账或 operator 信任文件,niu 只是运行时探测的外部可执行文件。可复现性依赖用户机器上装的是哪个版本。当前策略是**记录**(`niu --version` 打一行日志)而非**拦截**。
|
|
138
|
+
|
|
139
|
+
## 6. Git Bash 5.2 vs Niubash 5.3 · 差分实测
|
|
140
|
+
|
|
141
|
+
本机对照(36 项探针),结论:**语法层面只差一条**,其余差异在工具实现来源与环境标识。
|
|
142
|
+
|
|
143
|
+
### 6.1 唯一的语法级差异
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
${ cmd; } 无 fork 命令替换
|
|
147
|
+
Git Bash 5.2.37 → /usr/bin/bash: line 1: ${ echo A; }: bad substitution
|
|
148
|
+
Niubash 5.3.20 → x=A
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 6.2 工具实现差异(不影响写脚本,影响探测式脚本)
|
|
152
|
+
|
|
153
|
+
| 项 | Git Bash | Niubash |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `uname -s` | `MINGW64_NT-10.0` | `MSYS_NT-10.0`(兼容自称) |
|
|
156
|
+
| `sed --version` | `GNU sed 4.9` | `WinuxCmd 1.2.1` |
|
|
157
|
+
| `command -v sed` | `/usr/bin/sed` | `sed`(裸名) |
|
|
158
|
+
| `git --version` | `2.53.0.windows.1` | `2.56.0.windows.4.niugit` |
|
|
159
|
+
| `/dev/tty` | `No such device or address` | 可用(映射到 console) |
|
|
160
|
+
| 工具来源 | `/usr/bin` + `/mingw64/bin`(GNU 8.32) | `winuxcmd\usr\bin`(182 个 exe) |
|
|
161
|
+
|
|
162
|
+
**`sed` / `cat` / `cp` / `rm` 在 niu 里是 shell emulation**(`type sed` → `is a shell emulation of …\sed.exe`),而 `grep` / `awk` / `find` / `ls` / `mv` 是真 exe。实测行为几乎一致(`-i` 备份、`y///`、hold space、分支、`-A`、`-n` 全过),但 `--version` 暴露身份。
|
|
163
|
+
|
|
164
|
+
### 6.3 完全一致的部分(29/36)
|
|
165
|
+
|
|
166
|
+
POSIX 核心全套(`[ ]` / `$()` / for / case / while read / 函数 / `set -eu` / trap)、bash 扩展全套(数组 / 关联数组 / `[[ ]]` / 进程替换 / 花括号 / herestring)、路径双形态、`name=value` 不翻译、`/dev/null`、`/dev/stdin`、`sed -i`、后台作业 `&` / `wait $!`。
|
|
167
|
+
|
|
168
|
+
### 6.4 两边都有的坑(非 niu 独有)
|
|
169
|
+
|
|
170
|
+
`nohup <builtin>` 会 127:`nohup true` / `nohup :` 两边都报 `failed to run command`,因为 builtin 不是可执行文件。外部命令两边都正常。
|
|
171
|
+
|
|
172
|
+
## 7. 验证门禁
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
npm run build → exit 0
|
|
176
|
+
ARTIFACT GATES PASS: client 508KB, no node leaks, xterm bundled,
|
|
177
|
+
css inlined, ws external, 9 locale files, 46 dictionary keys none dead
|
|
178
|
+
npm test → exit 0(七件全绿,含真 node-pty 交互会话)
|
|
179
|
+
npm run lint → exit 0
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 8. 预设面
|
|
183
|
+
|
|
184
|
+
`agent-presets/standard-win-niu/` 提供「标准模式 (Windows-Niubash)」模板:
|
|
185
|
+
|
|
186
|
+
- `preset.yml`:显示名与描述
|
|
187
|
+
- `agent.cordis.yml`:persona 锚定 niu 语法族别(bash 5.3 / WinuxCmd / 无 MSYS 层 / `~/.niubashrc` / `/dev/null` 唯一设备翻译)
|
|
188
|
+
|
|
189
|
+
安装:`node agent-presets/install-presets.mjs --name standard-win-niu`
|
|
190
|
+
|
|
191
|
+
**注意**:预设只写提示词,**不绑定 `defaultShell`**。要让会话真的跑在 niu 上,仍需在 Settings → General → Default terminal 选择 Niubash(或把 `defaultShell: niu` 写进 profile 配置)。这与 `standard-win-payload` 的「opt-in 两次」是同一套哲学。
|
|
192
|
+
|
|
193
|
+
## 9. 发版记录
|
|
194
|
+
|
|
195
|
+
- 版本:`0.8.8` → `0.9.0`(新增后端属 minor)
|
|
196
|
+
- 双清单同步:`package.json` 与 `dsh.plugin.json` 版本号一致,description 双语均含 Niubash
|
|
197
|
+
- CHANGELOG:`0.9.0 (2026-11-16)` 节
|
package/dsh.plugin.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-bash-terminal-ts",
|
|
3
3
|
"name": "dsh-bash-terminal-ts",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"description": {
|
|
6
|
-
"en": "One shell tool that runs commands through PowerShell, Git Bash, MSYS2 or
|
|
7
|
-
"zh": "一个 shell 工具,可在 Windows 上通过 PowerShell / Git Bash / MSYS2 / WSL 执行命令;另提供底部工作台的内嵌终端,支持按 shell 激活开关与默认 shell 回落链。"
|
|
6
|
+
"en": "One shell tool that runs commands through PowerShell, Git Bash, MSYS2, WSL or Niubash on Windows, plus an embedded terminal for the bottom dock with per-shell activation switches and a default-shell fallback chain.",
|
|
7
|
+
"zh": "一个 shell 工具,可在 Windows 上通过 PowerShell / Git Bash / MSYS2 / WSL / Niubash 执行命令;另提供底部工作台的内嵌终端,支持按 shell 激活开关与默认 shell 回落链。"
|
|
8
8
|
},
|
|
9
9
|
"homepage": "https://github.com/drscrewdriver/dsh-bash-terminal-ts",
|
|
10
10
|
"repository": {
|
package/lib/client.js
CHANGED
|
@@ -6157,6 +6157,7 @@ var zh = {
|
|
|
6157
6157
|
"dock.state.notInstalled": "\u672A\u63A2\u6D4B\u5230",
|
|
6158
6158
|
"dock.state.wslPreferred": "\u5DF2\u68C0\u6D4B\u5230 WSL \u53D1\u884C\u7248\uFF08\u4F18\u5148\u7528 WSL bash\uFF09",
|
|
6159
6159
|
"shell.payload": "POSIX payload",
|
|
6160
|
+
"shell.niu": "Niubash",
|
|
6160
6161
|
"dock.state.noDistro": "\u65E0\u5DF2\u5B89\u88C5\u53D1\u884C\u7248",
|
|
6161
6162
|
"dock.state.launcherOnly": "\u53EA\u627E\u5230\u542F\u52A8\u5668\uFF0C\u65E0\u6CD5\u5185\u5D4C",
|
|
6162
6163
|
"dock.powershell.locked": "PowerShell \u662F\u4FDD\u5E95\u540E\u7AEF\uFF0C\u65E0\u6CD5\u5173\u95ED\u3002",
|
|
@@ -6204,6 +6205,7 @@ var en = {
|
|
|
6204
6205
|
"dock.state.notInstalled": "Not found",
|
|
6205
6206
|
"dock.state.wslPreferred": "WSL distro detected (WSL bash preferred)",
|
|
6206
6207
|
"shell.payload": "POSIX payload",
|
|
6208
|
+
"shell.niu": "Niubash",
|
|
6207
6209
|
"dock.state.noDistro": "No distro installed",
|
|
6208
6210
|
"dock.state.launcherOnly": "Only a launcher was found; it cannot be embedded",
|
|
6209
6211
|
"dock.powershell.locked": "PowerShell is the fallback backend and cannot be turned off.",
|
|
@@ -6251,6 +6253,7 @@ var ja = {
|
|
|
6251
6253
|
"dock.state.notInstalled": "\u898B\u3064\u304B\u308A\u307E\u305B\u3093",
|
|
6252
6254
|
"dock.state.wslPreferred": "WSL \u30C7\u30A3\u30B9\u30C8\u30EA\u691C\u51FA\u6E08\u307F\uFF08WSL bash \u512A\u5148\uFF09",
|
|
6253
6255
|
"shell.payload": "POSIX payload",
|
|
6256
|
+
"shell.niu": "Niubash",
|
|
6254
6257
|
"dock.state.noDistro": "\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u6E08\u307F\u30C7\u30A3\u30B9\u30C8\u30EA\u30D3\u30E5\u30FC\u30B7\u30E7\u30F3\u306A\u3057",
|
|
6255
6258
|
"dock.state.launcherOnly": "\u30E9\u30F3\u30C1\u30E3\u30FC\u306E\u307F\u691C\u51FA\u3001\u57CB\u3081\u8FBC\u307F\u4E0D\u53EF",
|
|
6256
6259
|
"dock.powershell.locked": "PowerShell \u306F\u6700\u5F8C\u306E\u4EE3\u66FF\u306E\u305F\u3081\u7121\u52B9\u5316\u3067\u304D\u307E\u305B\u3093\u3002",
|
|
@@ -6298,6 +6301,7 @@ var ko = {
|
|
|
6298
6301
|
"dock.state.notInstalled": "\uD0D0\uC9C0\uB418\uC9C0 \uC54A\uC74C",
|
|
6299
6302
|
"dock.state.wslPreferred": "WSL \uBC30\uD3EC\uD310 \uAC10\uC9C0\uB428 (WSL bash \uC6B0\uC120)",
|
|
6300
6303
|
"shell.payload": "POSIX payload",
|
|
6304
|
+
"shell.niu": "Niubash",
|
|
6301
6305
|
"dock.state.noDistro": "\uC124\uCE58\uB41C \uBC30\uD3EC\uD310 \uC5C6\uC74C",
|
|
6302
6306
|
"dock.state.launcherOnly": "\uB7F0\uCC98\uB9CC \uBC1C\uACAC\uB418\uC5B4 \uB0B4\uC7A5\uD560 \uC218 \uC5C6\uC74C",
|
|
6303
6307
|
"dock.powershell.locked": "PowerShell\uC740 \uCD5C\uC885 \uB300\uCCB4 \uD56D\uBAA9\uC774\uBBC0\uB85C \uB04C \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.",
|
|
@@ -6345,6 +6349,7 @@ var fr = {
|
|
|
6345
6349
|
"dock.state.notInstalled": "Non d\xE9tect\xE9",
|
|
6346
6350
|
"dock.state.wslPreferred": "Distro WSL d\xE9tect\xE9e (bash WSL pr\xE9f\xE9r\xE9)",
|
|
6347
6351
|
"shell.payload": "POSIX payload",
|
|
6352
|
+
"shell.niu": "Niubash",
|
|
6348
6353
|
"dock.state.noDistro": "Aucune distribution install\xE9e",
|
|
6349
6354
|
"dock.state.launcherOnly": "Seuls des lanceurs ont \xE9t\xE9 trouv\xE9s; int\xE9gration impossible",
|
|
6350
6355
|
"dock.powershell.locked": "PowerShell sert de repli final et ne peut pas \xEAtre d\xE9sactiv\xE9.",
|
|
@@ -6392,6 +6397,7 @@ var de = {
|
|
|
6392
6397
|
"dock.state.notInstalled": "Nicht gefunden",
|
|
6393
6398
|
"dock.state.wslPreferred": "WSL-Distro erkannt (WSL bash bevorzugt)",
|
|
6394
6399
|
"shell.payload": "POSIX payload",
|
|
6400
|
+
"shell.niu": "Niubash",
|
|
6395
6401
|
"dock.state.noDistro": "Keine Distribution installiert",
|
|
6396
6402
|
"dock.state.launcherOnly": "Nur Launcher gefunden; Einbettung nicht m\xF6glich",
|
|
6397
6403
|
"dock.powershell.locked": "PowerShell ist die letzte R\xFCckfallm\xF6glichkeit und kann nicht deaktiviert werden.",
|
|
@@ -6439,6 +6445,7 @@ var it = {
|
|
|
6439
6445
|
"dock.state.notInstalled": "Non trovato",
|
|
6440
6446
|
"dock.state.wslPreferred": "Distro WSL rilevata (bash WSL preferito)",
|
|
6441
6447
|
"shell.payload": "POSIX payload",
|
|
6448
|
+
"shell.niu": "Niubash",
|
|
6442
6449
|
"dock.state.noDistro": "Nessuna distribuzione installata",
|
|
6443
6450
|
"dock.state.launcherOnly": "Trovato solo un launcher; incorporamento non possibile",
|
|
6444
6451
|
"dock.powershell.locked": "PowerShell \xE8 il ripiego finale e non pu\xF2 essere disattivato.",
|
|
@@ -6486,6 +6493,7 @@ var ru = {
|
|
|
6486
6493
|
"dock.state.notInstalled": "\u041D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D",
|
|
6487
6494
|
"dock.state.wslPreferred": "\u041E\u0431\u043D\u0430\u0440\u0443\u0436\u0435\u043D \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432 WSL (\u043F\u0440\u0435\u0434\u043F\u043E\u0447\u0442\u0438\u0442\u0435\u043B\u044C\u043D\u0435\u0435 WSL bash)",
|
|
6488
6495
|
"shell.payload": "POSIX payload",
|
|
6496
|
+
"shell.niu": "Niubash",
|
|
6489
6497
|
"dock.state.noDistro": "\u041D\u0435\u0442 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u044B\u0445 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043E\u0432",
|
|
6490
6498
|
"dock.state.launcherOnly": "\u041D\u0430\u0439\u0434\u0435\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u043B\u0430\u0443\u043D\u0447\u0435\u0440, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043D\u0438\u0435 \u043D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E",
|
|
6491
6499
|
"dock.powershell.locked": "PowerShell \u2014 \u0440\u0435\u0437\u0435\u0440\u0432\u043D\u044B\u0439 \u0432\u0430\u0440\u0438\u0430\u043D\u0442, \u0435\u0433\u043E \u043D\u0435\u043B\u044C\u0437\u044F \u043E\u0442\u043A\u043B\u044E\u0447\u0438\u0442\u044C.",
|
|
@@ -6533,6 +6541,7 @@ var es = {
|
|
|
6533
6541
|
"dock.state.notInstalled": "No detectado",
|
|
6534
6542
|
"dock.state.wslPreferred": "Distro de WSL detectada (se prefiere bash de WSL)",
|
|
6535
6543
|
"shell.payload": "POSIX payload",
|
|
6544
|
+
"shell.niu": "Niubash",
|
|
6536
6545
|
"dock.state.noDistro": "Sin distribuci\xF3n instalada",
|
|
6537
6546
|
"dock.state.launcherOnly": "Solo se encontr\xF3 un lanzador; no se puede incrustar",
|
|
6538
6547
|
"dock.powershell.locked": "PowerShell es el respaldo final y no puede desactivarse.",
|
|
@@ -7698,7 +7707,7 @@ function MultiShellTerminal(props) {
|
|
|
7698
7707
|
// src/client.tsx
|
|
7699
7708
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
7700
7709
|
var SETTINGS_NS = "settings.bash-terminal";
|
|
7701
|
-
var SHELLS = ["powershell", "gitbash", "msys2", "wsl", "payload"];
|
|
7710
|
+
var SHELLS = ["powershell", "gitbash", "msys2", "wsl", "payload", "niu"];
|
|
7702
7711
|
var ROW_CSS = ".btRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}.btRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}.btTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.btDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}.btSelector{background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;border-radius:18px;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex}.btSelector:hover{background:var(--dsw-alias-interactive-bg-hover)}.btGear{position:fixed;right:16px;bottom:110px;z-index:10000;width:40px;height:40px;border-radius:50%;border:1px solid rgba(127,127,127,.4);background:rgba(30,30,32,.85);color:inherit;cursor:pointer;font-size:17px;box-shadow:0 4px 16px rgba(0,0,0,.35)}.btOverlay{position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,.45)}.btPanel{position:fixed;top:6vh;left:50%;transform:translateX(-50%);width:min(760px,92vw);max-height:84vh;overflow-y:auto;z-index:10001;background:var(--dsw-alias-bg-module-platform,rgba(30,30,32,.92));border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.3));border-radius:14px;padding:20px;color:var(--dsw-alias-label-primary)}.btBadge{border-radius:10px;padding:2px 8px;font-size:11px;line-height:16px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-tertiary);white-space:nowrap}.btBadgeOk{color:var(--dsw-alias-label-primary)}.btNotice{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;padding:8px 0}.btWarn{color:var(--dsw-status-warning-default,#b8860b)}.btRowSwitch{padding-right:0}.btSwitch{width:40px;height:24px;border-radius:12px;border:none;cursor:pointer;background:var(--dsw-alias-bg-module-platform);position:relative;flex:none;transition:background .15s ease;box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l2)}.btSwitch::after{content:'';position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:var(--dsw-alias-label-tertiary);transition:transform .15s ease,background .15s ease}.btSwitchOn{background:var(--dsw-alias-interactive-brand,#2f6fed)}.btSwitchOn::after{transform:translateX(16px);background:#fff}.btSwitch:disabled{cursor:not-allowed;opacity:.4}.btSwitch:disabled::after{background:var(--dsw-alias-label-quaternary,#8a8a8a)}.btInput{background:var(--dsw-alias-bg-module-platform);height:32px;border:none;border-radius:8px;color:var(--dsw-alias-label-primary);padding:0 10px;font:inherit;min-width:0;flex:1}.btPick{position:relative;display:inline-block}.btPickBtn{gap:6px}.btPickSm{height:28px;padding:0 10px;border-radius:14px;font-size:12px;line-height:18px}.btPickBtn:disabled{opacity:.4;cursor:not-allowed}.btPickText{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.btPickCaret{color:var(--dsw-alias-label-tertiary);font-size:10px;line-height:1}.btPickList{position:absolute;z-index:1000;top:calc(100% + 4px);left:0;min-width:100%;max-height:260px;overflow-y:auto;padding:4px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-overlay);box-shadow:0 8px 24px rgba(0,0,0,.28)}.btPickOpt{padding:6px 10px;font-size:12px;line-height:18px;border-radius:6px;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap}.btPickOpt:hover{background:var(--dsw-alias-interactive-bg-hover)}.btPickOptOn{color:var(--dsw-alias-interactive-brand);font-weight:600}";
|
|
7703
7712
|
if (typeof document !== "undefined" && document.querySelector('style[data-plugin-css="bash-terminal-row"]') === null) {
|
|
7704
7713
|
const tag = document.createElement("style");
|
package/lib/dsh-types.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The terminal backends this plugin exposes.
|
|
3
|
+
*
|
|
4
|
+
* Re-exported from `./shell-id.js` rather than declared here: the browser graph
|
|
5
|
+
* needs the same union (socket frames, catalog rows) and `shell-id.ts` is the one
|
|
6
|
+
* module with no Node references, so it is the single source of truth. Declaring
|
|
7
|
+
* a second copy here is how `niu` shipped in the union the catalog reads while
|
|
8
|
+
* `SHELL_DESCRIPTIONS` stayed five-keyed - a drift the compiler cannot see,
|
|
9
|
+
* because `Record<ShellId, string>` only complains in the module that owns the
|
|
10
|
+
* wider union.
|
|
11
|
+
*/
|
|
12
|
+
export type { ShellId } from "./shell-id.js";
|
|
3
13
|
/** Permissive node of the DSH JSON-schema dialect used in tool output declarations. */
|
|
4
14
|
export interface JsonSchemaNode {
|
|
5
15
|
type?: string;
|
|
@@ -177,6 +187,8 @@ export interface ResolvedPaths {
|
|
|
177
187
|
wsl?: string;
|
|
178
188
|
/** The digest-verified pinned POSIX runtime payload (see src/payload.ts). */
|
|
179
189
|
payload?: string;
|
|
190
|
+
/** Niubash (native bash reimplementation); see candidateNiuPaths in index.ts. */
|
|
191
|
+
niu?: string;
|
|
180
192
|
}
|
|
181
193
|
export interface CollectSpec {
|
|
182
194
|
maxBytes: number;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const name = "bash-terminal";
|
|
|
4
4
|
/** Services required before the tool can register. */
|
|
5
5
|
export declare const inject: string[];
|
|
6
6
|
/** The terminal backends this tool exposes, in catalog order. */
|
|
7
|
-
export declare const SHELLS: readonly ["powershell", "gitbash", "msys2", "wsl", "payload"];
|
|
7
|
+
export declare const SHELLS: readonly ["powershell", "gitbash", "msys2", "wsl", "payload", "niu"];
|
|
8
8
|
/** The backend used when the caller does not name one. */
|
|
9
9
|
export declare const DEFAULT_SHELL: ShellId;
|
|
10
10
|
/** Static shape of the runtime configuration schema. */
|
|
@@ -64,6 +64,10 @@ export interface ConfigValues {
|
|
|
64
64
|
enablePosixPayload: boolean;
|
|
65
65
|
/** Explicit payload root or bin/bash.exe path; '' = auto-discovery only. */
|
|
66
66
|
payloadPosixPath: string;
|
|
67
|
+
/** Fixed niu.exe path; '' = auto-discovery via candidateNiuPaths. */
|
|
68
|
+
niuPath: string;
|
|
69
|
+
/** Activation switch for the Niubash row (default true: detected means on). */
|
|
70
|
+
shellNiu: boolean;
|
|
67
71
|
}
|
|
68
72
|
/** Runtime configuration schema. */
|
|
69
73
|
export declare const Config: import("./dsh.js").SchemasterySchema;
|
|
@@ -91,10 +95,19 @@ export declare function candidateGitBashPaths(env?: NodeJS.ProcessEnv): string[]
|
|
|
91
95
|
* under the DSH Windows ACL restricted-token sandbox.
|
|
92
96
|
*/
|
|
93
97
|
export declare function candidateMsys2Paths(env?: NodeJS.ProcessEnv): string[];
|
|
98
|
+
/**
|
|
99
|
+
* Niubash locations, in preference order: the per-user installer default
|
|
100
|
+
* (LOCALAPPDATA\Programs\Niubash) first, then the winget shim link, then a
|
|
101
|
+
* machine-wide install, then PATH entries. Read from the registry on this
|
|
102
|
+
* machine: the installer writes a USER Path entry pointing at the capitalized
|
|
103
|
+
* directory, so the first candidate must match that exact casing on
|
|
104
|
+
* case-sensitive filesystems (Windows itself is case-insensitive).
|
|
105
|
+
*/
|
|
106
|
+
export declare function candidateNiuPaths(env?: NodeJS.ProcessEnv): string[];
|
|
94
107
|
export declare function defaultWslPath(env?: NodeJS.ProcessEnv): string;
|
|
95
108
|
/** Executable paths, possibly undefined when a backend is not installed. */
|
|
96
109
|
export type { ResolvedPaths };
|
|
97
|
-
type PathConfig = Partial<Pick<ConfigValues, "pwshPath" | "gitBashPath" | "msys2Path" | "wslPath">>;
|
|
110
|
+
type PathConfig = Partial<Pick<ConfigValues, "pwshPath" | "gitBashPath" | "msys2Path" | "wslPath" | "niuPath">>;
|
|
98
111
|
export declare function resolveAllPaths(config?: PathConfig, env?: NodeJS.ProcessEnv, payloadBash?: string): ResolvedPaths;
|
|
99
112
|
export declare function buildArgv(shell: string, command: string, paths: ResolvedPaths, distro?: string): Array<string | undefined>;
|
|
100
113
|
/**
|
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ const ENTRY_ID = "tool-bash-terminal";
|
|
|
34
34
|
/** Services required before the tool can register. */
|
|
35
35
|
export const inject = ["tools", "systemPrompt", "shellEnv", "subprocess", "settings", "sandbox", "sandboxPolicy"];
|
|
36
36
|
/** The terminal backends this tool exposes, in catalog order. */
|
|
37
|
-
export const SHELLS = ["powershell", "gitbash", "msys2", "wsl", "payload"];
|
|
37
|
+
export const SHELLS = ["powershell", "gitbash", "msys2", "wsl", "payload", "niu"];
|
|
38
38
|
/** The backend used when the caller does not name one. */
|
|
39
39
|
export const DEFAULT_SHELL = "powershell";
|
|
40
40
|
/** Default per-command timeout (ms). */
|
|
@@ -78,7 +78,9 @@ export const Config = z.object({
|
|
|
78
78
|
// Payload gate state is read once per process (paths resolve at startup), so
|
|
79
79
|
// these are deliberately NOT volatile: a flip needs the restart it implies.
|
|
80
80
|
enablePosixPayload: z.boolean().default(false),
|
|
81
|
-
payloadPosixPath: z.string().default("")
|
|
81
|
+
payloadPosixPath: z.string().default(""),
|
|
82
|
+
niuPath: z.string().default(""),
|
|
83
|
+
shellNiu: z.boolean().default(true).volatile()
|
|
82
84
|
});
|
|
83
85
|
// ---- executable resolution ------------------------------------------------
|
|
84
86
|
function candidateExists(candidate) {
|
|
@@ -167,6 +169,31 @@ export function candidateMsys2Paths(env = process.env) {
|
|
|
167
169
|
candidates.push("C:\\msys64\\msys2.exe"); // last resort: see the note above
|
|
168
170
|
return candidates;
|
|
169
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Niubash locations, in preference order: the per-user installer default
|
|
174
|
+
* (LOCALAPPDATA\Programs\Niubash) first, then the winget shim link, then a
|
|
175
|
+
* machine-wide install, then PATH entries. Read from the registry on this
|
|
176
|
+
* machine: the installer writes a USER Path entry pointing at the capitalized
|
|
177
|
+
* directory, so the first candidate must match that exact casing on
|
|
178
|
+
* case-sensitive filesystems (Windows itself is case-insensitive).
|
|
179
|
+
*/
|
|
180
|
+
export function candidateNiuPaths(env = process.env) {
|
|
181
|
+
const localAppData = env.LOCALAPPDATA ?? "";
|
|
182
|
+
const programFiles = env.ProgramFiles ?? "C:\\Program Files";
|
|
183
|
+
const candidates = [];
|
|
184
|
+
if (localAppData.length > 0) {
|
|
185
|
+
candidates.push(join(localAppData, "Programs", "Niubash", "niu.exe"));
|
|
186
|
+
candidates.push(join(localAppData, "Microsoft", "WinGet", "Links", "niu.exe"));
|
|
187
|
+
}
|
|
188
|
+
candidates.push(join(programFiles, "Niubash", "niu.exe"));
|
|
189
|
+
for (const entry of (env.PATH ?? "").split(";")) {
|
|
190
|
+
const trimmed = entry.trim().replace(/^"|"$/g, "");
|
|
191
|
+
if (trimmed.length === 0)
|
|
192
|
+
continue;
|
|
193
|
+
candidates.push(join(trimmed, "niu.exe"));
|
|
194
|
+
}
|
|
195
|
+
return candidates;
|
|
196
|
+
}
|
|
170
197
|
export function defaultWslPath(env = process.env) {
|
|
171
198
|
const systemRoot = env.SystemRoot ?? "C:\\Windows";
|
|
172
199
|
return join(systemRoot, "System32", "wsl.exe");
|
|
@@ -184,10 +211,13 @@ export function resolveAllPaths(config = {}, env = process.env, payloadBash) {
|
|
|
184
211
|
const wsl = config.wslPath && config.wslPath.trim().length > 0
|
|
185
212
|
? config.wslPath
|
|
186
213
|
: defaultWslPath(env);
|
|
214
|
+
const niu = config.niuPath && config.niuPath.trim().length > 0
|
|
215
|
+
? config.niuPath
|
|
216
|
+
: resolveFromCandidates(candidateNiuPaths(env));
|
|
187
217
|
// The payload is its OWN backend (first-class catalog row) - it never
|
|
188
218
|
// silently substitutes for the gitbash slot, so a row labelled "Git Bash"
|
|
189
219
|
// always names a shell the machine actually has.
|
|
190
|
-
return { pwsh, gitbash, msys2, wsl, ...(payloadBash !== undefined ? { payload: payloadBash } : {}) };
|
|
220
|
+
return { pwsh, gitbash, msys2, wsl, niu, ...(payloadBash !== undefined ? { payload: payloadBash } : {}) };
|
|
191
221
|
}
|
|
192
222
|
// ---- argv / env construction ------------------------------------------------
|
|
193
223
|
export function buildArgv(shell, command, paths, distro) {
|
|
@@ -205,6 +235,11 @@ export function buildArgv(shell, command, paths, distro) {
|
|
|
205
235
|
// Same login-shell rule as msys2/gitbash: the payload is a
|
|
206
236
|
// Git-for-Windows tree and `-lc` is what gives it a usable PATH.
|
|
207
237
|
return [paths.payload, "-lc", command];
|
|
238
|
+
case "niu":
|
|
239
|
+
// Same login-shell rule: -lc sources the profile chain so winuxcmd's
|
|
240
|
+
// bin directory joins PATH. (niu has no MSYS runtime; see findings F2
|
|
241
|
+
// for the sandbox question this backend answers.)
|
|
242
|
+
return [paths.niu, "-lc", command];
|
|
208
243
|
case "wsl": {
|
|
209
244
|
const distroArg = distro !== undefined && distro.trim().length > 0 ? ["-d", distro.trim()] : [];
|
|
210
245
|
return [paths.wsl, ...distroArg, "-e", "bash", "-lc", command];
|
|
@@ -423,7 +458,8 @@ export const SHELL_DESCRIPTIONS = {
|
|
|
423
458
|
gitbash: "Execute a bash command (Git for Windows bash -lc <command>) and return its stdout/stderr. POSIX syntax; paths like /d/WorkSpace; PATH includes /usr/bin and /mingw64/bin so git, npm, ssh etc. work; environment variables via $NAME.",
|
|
424
459
|
msys2: "Execute a bash command (MSYS2 bash -lc <command>) and return its stdout/stderr. POSIX syntax; paths like /c/...; PATH includes /usr/bin and /mingw64/bin so git, npm, gcc, make etc. work; environment variables via $NAME. MSYS2 provides a full GCC/mingw64 toolchain.",
|
|
425
460
|
wsl: "Execute a Linux bash command (wsl [-d <distro>] -e bash -lc <command>) and return its stdout/stderr. Linux syntax; Windows files under /mnt/d/...; environment variables via $NAME.",
|
|
426
|
-
payload: "Execute a bash command in the plugin's pinned POSIX runtime payload (a digest-verified Git-for-Windows bash -lc <command>) and return its stdout/stderr. POSIX syntax; paths like /c/...; PATH includes /usr/bin so git, npm, ssh etc. work; environment variables via $NAME. Use it only when the user has deliberately enabled the payload backend."
|
|
461
|
+
payload: "Execute a bash command in the plugin's pinned POSIX runtime payload (a digest-verified Git-for-Windows bash -lc <command>) and return its stdout/stderr. POSIX syntax; paths like /c/...; PATH includes /usr/bin so git, npm, ssh etc. work; environment variables via $NAME. Use it only when the user has deliberately enabled the payload backend.",
|
|
462
|
+
niu: "Execute a bash command (Niubash niu -lc <command>) and return its stdout/stderr. GNU bash 5.3 semantics; WinuxCmd applets (ls, cp, rm, grep, find, cat, sed, awk, ...) are on PATH; native Windows paths such as C:\\... are kept as-is while /c/... style arguments are translated; environment variables via $NAME. Niubash is a native binary with no MSYS emulation layer, so /dev/* redirects other than /dev/null do not exist; its startup file is ~/.niubashrc."
|
|
427
463
|
};
|
|
428
464
|
/**
|
|
429
465
|
* Render the model-facing tool description for one backend. The backend is
|
|
@@ -438,7 +474,7 @@ export function toolDescription(backgroundEnabled, shell = DEFAULT_SHELL) {
|
|
|
438
474
|
const base = [
|
|
439
475
|
`The user's chosen default terminal (Settings -> General -> Default terminal) is ${active}; commands run there.`,
|
|
440
476
|
lead,
|
|
441
|
-
"Each call spawns a fresh shell: no state (cwd, variables, aliases) persists between calls - pass workdir instead of using cd. Non-zero exits are reported as [exit code: N] markers; investigate failures before moving on. Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. Commands run under the DSH sandbox: confined modes (read-only / workspace-write) are enforced through ctx.sandbox and deny fail-closed for PowerShell; danger-full-access, Git Bash, MSYS2, the pinned POSIX payload, and WSL run unconfined."
|
|
477
|
+
"Each call spawns a fresh shell: no state (cwd, variables, aliases) persists between calls - pass workdir instead of using cd. Non-zero exits are reported as [exit code: N] markers; investigate failures before moving on. Long output is truncated to its tail; the full output is saved to a file whose path is reported when available. Commands run under the DSH sandbox: confined modes (read-only / workspace-write) are enforced through ctx.sandbox and deny fail-closed for PowerShell; danger-full-access, Git Bash, MSYS2, the pinned POSIX payload, Niubash, and WSL run unconfined."
|
|
442
478
|
].join(" ");
|
|
443
479
|
if (!backgroundEnabled)
|
|
444
480
|
return base;
|
|
@@ -616,6 +652,8 @@ export function apply(ctx, config = {}) {
|
|
|
616
652
|
return read(config.shellWsl, true);
|
|
617
653
|
if (shell === "payload")
|
|
618
654
|
return read(config.shellPayload, false);
|
|
655
|
+
if (shell === "niu")
|
|
656
|
+
return read(config.shellNiu, true);
|
|
619
657
|
return false;
|
|
620
658
|
};
|
|
621
659
|
/**
|