@linxin666/dsh-win-bash 0.0.0-stage → 0.4.8

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.
Files changed (118) hide show
  1. package/LICENSE +202 -0
  2. package/PROVENANCE.md +215 -0
  3. package/README.i18n.yaml +6 -0
  4. package/README.md +264 -2
  5. package/README.zh.md +221 -0
  6. package/cordis.patch.yml +13 -0
  7. package/lib/index.js +2756 -0
  8. package/lib/types/background.d.ts +169 -0
  9. package/lib/types/config.d.ts +130 -0
  10. package/lib/types/gate.d.ts +179 -0
  11. package/lib/types/index.d.ts +104 -0
  12. package/lib/types/protocol.d.ts +90 -0
  13. package/lib/types/pwsh-replacement.d.ts +140 -0
  14. package/lib/types/runtime.d.ts +115 -0
  15. package/lib/types/shell.d.ts +184 -0
  16. package/lib/types/tool.d.ts +123 -0
  17. package/package.json +58 -3
  18. package/runtime/win32-x64/checksums.sha256 +91 -0
  19. package/runtime/win32-x64/etc/bash.bashrc +69 -0
  20. package/runtime/win32-x64/etc/fstab +6 -0
  21. package/runtime/win32-x64/etc/msystem +27 -0
  22. package/runtime/win32-x64/etc/msystem.d/CLANG64 +7 -0
  23. package/runtime/win32-x64/etc/msystem.d/CLANGARM64 +7 -0
  24. package/runtime/win32-x64/etc/msystem.d/MINGW32 +7 -0
  25. package/runtime/win32-x64/etc/msystem.d/MINGW64 +7 -0
  26. package/runtime/win32-x64/etc/msystem.d/MSYS +4 -0
  27. package/runtime/win32-x64/etc/msystem.d/UCRT64 +7 -0
  28. package/runtime/win32-x64/etc/nsswitch.conf +12 -0
  29. package/runtime/win32-x64/etc/package-versions.txt +67 -0
  30. package/runtime/win32-x64/etc/profile +146 -0
  31. package/runtime/win32-x64/etc/profile.d/bash_profile.sh +11 -0
  32. package/runtime/win32-x64/etc/profile.d/lang.sh +19 -0
  33. package/runtime/win32-x64/licenses/GPL-2.0.txt +338 -0
  34. package/runtime/win32-x64/licenses/GPL-3.0.txt +674 -0
  35. package/runtime/win32-x64/licenses/LGPL-2.1.txt +501 -0
  36. package/runtime/win32-x64/licenses/LGPL-3.0.txt +165 -0
  37. package/runtime/win32-x64/licenses/expat-COPYING.txt +21 -0
  38. package/runtime/win32-x64/licenses/gcc-libs-RUNTIME.LIBRARY.EXCEPTION.txt +73 -0
  39. package/runtime/win32-x64/licenses/gettext-runtime-COPYING.LIB.txt +501 -0
  40. package/runtime/win32-x64/licenses/gettext-runtime-COPYING.txt +13 -0
  41. package/runtime/win32-x64/licenses/git-for-windows-LICENSE.txt +360 -0
  42. package/runtime/win32-x64/licenses/heimdal-LICENSE.txt +33 -0
  43. package/runtime/win32-x64/licenses/libcbor-LICENSE.md +21 -0
  44. package/runtime/win32-x64/licenses/libffi-LICENSE.txt +21 -0
  45. package/runtime/win32-x64/licenses/libfido2-LICENSE.txt +26 -0
  46. package/runtime/win32-x64/licenses/libiconv-COPYING.LIB.txt +501 -0
  47. package/runtime/win32-x64/licenses/libiconv-COPYING.txt +674 -0
  48. package/runtime/win32-x64/licenses/libopenssl-LICENSE.txt +177 -0
  49. package/runtime/win32-x64/licenses/libpcre-LICENCE.txt +93 -0
  50. package/runtime/win32-x64/licenses/libsqlite-LICENSE +25 -0
  51. package/runtime/win32-x64/licenses/ncurses-LICENSE +29 -0
  52. package/runtime/win32-x64/licenses/openssh-LICENCE.txt +412 -0
  53. package/runtime/win32-x64/licenses/zlib-LICENSE +22 -0
  54. package/runtime/win32-x64/usr/bin/awk.exe +0 -0
  55. package/runtime/win32-x64/usr/bin/b2sum.exe +0 -0
  56. package/runtime/win32-x64/usr/bin/basename.exe +0 -0
  57. package/runtime/win32-x64/usr/bin/basenc.exe +0 -0
  58. package/runtime/win32-x64/usr/bin/bash.exe +0 -0
  59. package/runtime/win32-x64/usr/bin/cat.exe +0 -0
  60. package/runtime/win32-x64/usr/bin/cmp.exe +0 -0
  61. package/runtime/win32-x64/usr/bin/comm.exe +0 -0
  62. package/runtime/win32-x64/usr/bin/cp.exe +0 -0
  63. package/runtime/win32-x64/usr/bin/cut.exe +0 -0
  64. package/runtime/win32-x64/usr/bin/dash.exe +0 -0
  65. package/runtime/win32-x64/usr/bin/date.exe +0 -0
  66. package/runtime/win32-x64/usr/bin/diff.exe +0 -0
  67. package/runtime/win32-x64/usr/bin/diff3.exe +0 -0
  68. package/runtime/win32-x64/usr/bin/dirname.exe +0 -0
  69. package/runtime/win32-x64/usr/bin/echo.exe +0 -0
  70. package/runtime/win32-x64/usr/bin/env.exe +0 -0
  71. package/runtime/win32-x64/usr/bin/expr.exe +0 -0
  72. package/runtime/win32-x64/usr/bin/false.exe +0 -0
  73. package/runtime/win32-x64/usr/bin/find.exe +0 -0
  74. package/runtime/win32-x64/usr/bin/grep.exe +0 -0
  75. package/runtime/win32-x64/usr/bin/head.exe +0 -0
  76. package/runtime/win32-x64/usr/bin/ls.exe +0 -0
  77. package/runtime/win32-x64/usr/bin/mkdir.exe +0 -0
  78. package/runtime/win32-x64/usr/bin/mktemp.exe +0 -0
  79. package/runtime/win32-x64/usr/bin/msys-2.0.dll +0 -0
  80. package/runtime/win32-x64/usr/bin/msys-gcc_s-seh-1.dll +0 -0
  81. package/runtime/win32-x64/usr/bin/msys-gmp-10.dll +0 -0
  82. package/runtime/win32-x64/usr/bin/msys-iconv-2.dll +0 -0
  83. package/runtime/win32-x64/usr/bin/msys-intl-8.dll +0 -0
  84. package/runtime/win32-x64/usr/bin/msys-mpfr-6.dll +0 -0
  85. package/runtime/win32-x64/usr/bin/msys-ncursesw6.dll +0 -0
  86. package/runtime/win32-x64/usr/bin/msys-pcre-1.dll +0 -0
  87. package/runtime/win32-x64/usr/bin/msys-readline8.dll +0 -0
  88. package/runtime/win32-x64/usr/bin/mv.exe +0 -0
  89. package/runtime/win32-x64/usr/bin/pathchk.exe +0 -0
  90. package/runtime/win32-x64/usr/bin/printf.exe +0 -0
  91. package/runtime/win32-x64/usr/bin/pwd.exe +0 -0
  92. package/runtime/win32-x64/usr/bin/readlink.exe +0 -0
  93. package/runtime/win32-x64/usr/bin/rm.exe +0 -0
  94. package/runtime/win32-x64/usr/bin/rmdir.exe +0 -0
  95. package/runtime/win32-x64/usr/bin/sdiff.exe +0 -0
  96. package/runtime/win32-x64/usr/bin/sed.exe +0 -0
  97. package/runtime/win32-x64/usr/bin/seq.exe +0 -0
  98. package/runtime/win32-x64/usr/bin/sh.exe +0 -0
  99. package/runtime/win32-x64/usr/bin/sleep.exe +0 -0
  100. package/runtime/win32-x64/usr/bin/sort.exe +0 -0
  101. package/runtime/win32-x64/usr/bin/tail.exe +0 -0
  102. package/runtime/win32-x64/usr/bin/test.exe +0 -0
  103. package/runtime/win32-x64/usr/bin/touch.exe +0 -0
  104. package/runtime/win32-x64/usr/bin/tr.exe +0 -0
  105. package/runtime/win32-x64/usr/bin/true.exe +0 -0
  106. package/runtime/win32-x64/usr/bin/uname.exe +0 -0
  107. package/runtime/win32-x64/usr/bin/uniq.exe +0 -0
  108. package/runtime/win32-x64/usr/bin/wc.exe +0 -0
  109. package/runtime/win32-x64/usr/bin/xargs.exe +0 -0
  110. package/src/background.ts +270 -0
  111. package/src/config.ts +209 -0
  112. package/src/gate.ts +308 -0
  113. package/src/index.ts +277 -0
  114. package/src/protocol.ts +130 -0
  115. package/src/pwsh-replacement.ts +435 -0
  116. package/src/runtime.ts +240 -0
  117. package/src/shell.ts +630 -0
  118. package/src/tool.ts +481 -0
package/README.md CHANGED
@@ -1,3 +1,265 @@
1
- # Temporary Holding Version
1
+ # @linxin666/dsh-win-bash
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [中文](README.zh.md)
4
+
5
+ A pinned, private bash for Windows x64 DSH sessions. The plugin ships its own
6
+ Git for Windows MinGit payload, keeps one persistent bash process per session
7
+ behind the `win_bash` tool, and never falls back to a bash found on `PATH`.
8
+
9
+ ## Why
10
+
11
+ Models write shell commands in bash syntax - pipelines, `$VAR`, single
12
+ quotes, here-documents - and a Windows session whose only shell is PowerShell
13
+ answers many of them with a syntax error. Each error costs a round trip and
14
+ teaches the model nothing about the right dialect. This package removes that
15
+ loop by giving the session a real MSYS2 bash whose version and bytes are
16
+ pinned, so the dialect the model writes is the dialect that runs.
17
+
18
+ The shell is persistent because shell work is stateful: a command that `cd`s
19
+ or exports a variable expects the next command to see it. One process per
20
+ session is what makes that true.
21
+
22
+ ## What it does
23
+
24
+ - Registers ONE model-facing tool, `win_bash`. The name is deliberately not
25
+ `bash`: the host already mounts its own bash-family tools, and sharing a
26
+ name would replace or be replaced, silently either way.
27
+ - Keeps one persistent `bash -s` process per calling session. The working
28
+ directory, exported variables, functions, aliases and shell history survive
29
+ across calls for that session and belong to no other session.
30
+ - Runs each call as a foreground command with bounded stdout and stderr,
31
+ separated streams, and the command's real exit code. Output past the budget
32
+ is reported as truncated, in the text the model reads, rather than being cut
33
+ silently.
34
+ - Renders terminal escapes out of that text. On Windows, colour libraries
35
+ decide on the platform rather than on whether a terminal is attached, so a
36
+ piped `vitest` or `pnpm` run still emits colour codes; the tool carries the
37
+ bytes through and drops them where the text is rendered, so a caller reads
38
+ the message instead of `ESC [ 3 3 m`. A line a progress renderer repainted in
39
+ place shows the frame it finished on. The streams and the spill files keep
40
+ the exact bytes.
41
+ - Optionally runs a command as a background job in its own pinned bash process
42
+ and returns a job id at once, so a long build or watch does not hold the call
43
+ open or die with the session's shell. See [Background commands](#background-commands).
44
+ - Verifies the vendored payload against its SHA256 manifest before the tool is
45
+ registered at all; a mismatch refuses the mount.
46
+ - Replaces the host's own `pwsh` tool on the session's model-facing surface
47
+ while `win_bash` is registered, so command work goes to bash instead of to
48
+ the shell a model already knows. See [Which shell to use](#which-shell-to-use).
49
+
50
+ It adds no settings section, no HTTP route and no browser half: the Host
51
+ renders this row's configuration form from the plugin's own Config schema.
52
+
53
+ ## Which shell to use
54
+
55
+ The preference this plugin installs is a ladder, and it is a Windows ladder:
56
+
57
+ 1. **`win_bash`** for command work. It is the pinned MSYS2 bash, its state
58
+ survives across calls, and the dialect a model writes for it is the dialect
59
+ that runs.
60
+ 2. **`pwsh`** for the Windows-native work only PowerShell does - cmdlets, the
61
+ registry, Windows services - and as the fallback when a command is not bash.
62
+ The Host resolves it, so a machine with PowerShell 7 installed gets `pwsh`
63
+ and one without gets the Windows PowerShell the platform ships. This package
64
+ carries no PowerShell payload of its own.
65
+
66
+ While `win_bash` is registered, this plugin withdraws `pwsh` from the
67
+ session's tool surface, which is what makes the first rung stick: a model that
68
+ can see both shells picks the one it already knows, and nothing in a tool
69
+ schema outvotes that habit. The effect is exactly that - a session with one
70
+ listed shell - so the mnemonic the `win_bash` description carries is
71
+ "hides it rather than forbidding it".
72
+
73
+ - **Visibility only.** A `pwsh` call a model makes deliberately still runs.
74
+ There is no execution guard and no pre-execute denial: withdrawing the
75
+ fallback rung outright would trade a preference for a capability loss.
76
+ - **Per session, never process-wide.** The withdrawal is a scoped tool
77
+ restriction on the sessions this plugin serves. Anything else in the same
78
+ deployment keeps the surface it composed.
79
+ - **Only while `win_bash` is actually mounted.** A refused availability gate,
80
+ a payload that fails verification, a non-Windows host, or a row with
81
+ `replacePwsh: false` leaves `pwsh` exactly where it was. Withdrawing the
82
+ only usable shell of a deployment that ends up with no replacement shell
83
+ would leave the session with neither.
84
+ - **Windows only.** On POSIX the host shell is bash, win_bash does not mount,
85
+ and this logic produces no restriction, no listener and no effect at all.
86
+ - **Reversible.** Every restriction is lifted when its session is disposed and
87
+ when the plugin unloads, one isolated callback at a time.
88
+
89
+ Set `replacePwsh: false` to list both shells side by side and advertise the
90
+ preference with the tool description alone.
91
+
92
+ ## Availability
93
+
94
+ The tool serves sessions that run the LiangShen (梁神) agent preset, so its
95
+ availability follows that preset's **declaration**. At mount the plugin asks the
96
+ harness's agent-preset registry whether a preset with id `liangshen` is
97
+ declared; when it is, the tool registers, and when it is not, no tool is
98
+ registered at all and one info line states the reason. A tool that mounted and
99
+ refused every call would teach the model a capability the session does not have,
100
+ which is worse than an honest absence.
101
+
102
+ Three verdicts are distinguishable in the log, because they need different
103
+ actions: the preset is declared (registered), no such preset is declared (enable
104
+ the `dsh-liangshen` plugin row), and no usable agent-preset registry is
105
+ published in this deployment. Setting `syncWithLiangShen: false` skips the gate
106
+ entirely and always registers the tool.
107
+
108
+ The verdict waits for the host plugin tree to settle and then reads the roster.
109
+ A read that already carries the declaration decides at once; one that does not is
110
+ re-read on a short bounded schedule, because the declaring plugin publishes its
111
+ preset off its own activation return and the two can therefore land in either
112
+ order. A late declaration is never turned into a refusal.
113
+
114
+ The registry declares no roster-change event, so the verdict is decided once per
115
+ mount. Toggling the LiangShen row takes effect for `win_bash` after the plugin
116
+ manager refreshes the profile — the same freshness model the rest of the family
117
+ uses, not an immediate one.
118
+
119
+ ## Install
120
+
121
+ ### From the repository (development)
122
+
123
+ ```sh
124
+ git clone https://github.com/zhu1090093659/dsh-web.git
125
+ cd dsh-web
126
+ pnpm install
127
+ pnpm --filter @linxin666/dsh-win-bash build
128
+ dsh plugin --profile web add link:$(pwd)/packages/dsh-win-bash
129
+ ```
130
+
131
+ The bundle patch marks this package's row disabled on every non-Windows host,
132
+ so a POSIX profile can carry the same composition without mounting anything.
133
+
134
+ ## Configuration
135
+
136
+ | Field | Default | Meaning |
137
+ | --- | --- | --- |
138
+ | `timeoutMs` | 300000 | Whole-call wall-clock limit in milliseconds (1000..3600000). On expiry the shell is stopped and the next call starts a fresh one. |
139
+ | `maxStdoutBytes` | 131072 | Visible stdout byte budget (1024..1048576). Output past it is dropped from the front, and the result says so in its text. |
140
+ | `maxStderrBytes` | 32768 | Visible stderr byte budget (1024..524288). |
141
+ | `enableRunInBackground` | true | Whether `run_in_background` is offered. The parameter is advertised only when this is true and the deployment composes a job registry; a deployment without one never offers it, and a call that asks for it anyway is refused rather than run in the foreground. |
142
+ | `description` | built-in | Model-facing tool description; deployments may describe their own environment. |
143
+ | `syncWithLiangShen` | true | When true, the tool registers only while the `liangshen` agent preset is declared; false skips that gate and always registers. |
144
+ | `replacePwsh` | true | While this tool is registered, withdraw the host's `pwsh` tool from each session's model-facing surface. Visibility only: a deliberate `pwsh` call still runs. False lists both shells. |
145
+
146
+ ## Tool interface
147
+
148
+ | Parameter | Required | Meaning |
149
+ | --- | --- | --- |
150
+ | `command` | yes | The bash command to run, any number of lines. |
151
+ | `workdir` | no | Working directory for this command. Omitted keeps the shell's current directory. |
152
+ | `timeoutMs` | no | Per-call limit, clamped to the configured ceiling. |
153
+ | `run_in_background` | no | Run in a separate pinned bash process and return a job id at once. Offered only while a job registry is composed (see [Configuration](#configuration)). |
154
+
155
+ The result carries `stdout`, `stderr`, the command's `exitCode`, the
156
+ truncation facts for both streams (`stdoutTruncated`, `stderrTruncated`,
157
+ `stdoutLostHead`, `stderrLostHead`, `frameOverflow`, and the
158
+ `stdoutSpillPath`/`stderrSpillPath` files holding a complete stream), and
159
+ `jobId` when the call started a background job.
160
+
161
+ When a stream was cut, the model-facing text ends with a line such as:
162
+
163
+ ```text
164
+ [win_bash: stdout was truncated, only the last 131072 bytes are shown; the beginning was dropped; a middle window was dropped by the frame watch limit]
165
+ ```
166
+
167
+ ## Background commands
168
+
169
+ `run_in_background: true` runs the command in its OWN pinned bash process —
170
+ the same absolute payload path, the same environment contract, the same
171
+ confinement — and returns the job id immediately instead of waiting for the
172
+ command. Collect that job with the host's `job_output` and stop it with
173
+ `job_kill`.
174
+
175
+ The separate process is the point, not an implementation detail. The session's
176
+ persistent shell lives inside the subprocess provider's managed process range,
177
+ and disposing that range terminates every process still running in it, so a
178
+ job started with a trailing `&` dies with the shell that started it — on the
179
+ next timeout, the next abort, or the session's disposal. A background command
180
+ therefore owns its own process and outlives the call that started it.
181
+
182
+ - **Its own shell.** Never the session's persistent one, so a background
183
+ command cannot disturb the current directory, the exported variables or the
184
+ history of the foreground shell.
185
+ - **Same environment contract.** `PATH` with the payload's `usr/bin` first,
186
+ `MSYSTEM=MSYS`, `TERM=dumb`, `--norc --noprofile`, and `TMPDIR`/`TMP`/`TEMP`
187
+ pointing at a private directory owned by that job.
188
+ - **Same mode rule.** A restricted session is refused with the same
189
+ `SANDBOX_UNSUPPORTED` error a foreground call raises, before any process is
190
+ started and before any job is registered.
191
+ - **No timeout.** The call returns as soon as the job is registered; the
192
+ command's own lifetime is bounded by `job_kill` and by the session ending.
193
+ - **No silent downgrade.** On a deployment that composes no job registry the
194
+ call is refused with `BACKGROUND_UNAVAILABLE` and says so; it is never
195
+ quietly run in the foreground, which would hang the caller for the command's
196
+ whole lifetime and then die with that shell.
197
+
198
+ ## Permissions
199
+
200
+ The tool resolves the calling session's effective sandbox policy from the same
201
+ sandbox-policy service the host's own enforcing families use, and it resolves it
202
+ FOR THAT SESSION — a session's own mode outranks the deployment default, so a
203
+ session the user restricted cannot reach this shell through the default.
204
+
205
+ **This tool runs only under `danger-full-access`.** Any other mode is refused
206
+ with `SANDBOX_UNSUPPORTED`, before a process is spawned: the pinned MSYS2 bash
207
+ cannot start under a restricted token, so confinement cannot produce a working
208
+ shell here. Measured on win32 x64 (Windows 10.0.26200) against the real
209
+ restricted-token runner: `bash.exe`, `sh.exe`, `dash.exe` and `echo.exe` all die
210
+ before `main` with
211
+
212
+ ```text
213
+ NtCreateDirectoryObject(\BaseNamedObjects\msys-2.0S5-<hash>): 0xC0000022
214
+ ```
215
+
216
+ (exit 3221225794 / 0xC0000142), and system Git for Windows fails identically
217
+ (`couldn't create signal pipe, Win32 error 5`). `cmd.exe`, `node.exe` and
218
+ `powershell.exe` run confined on that same runner, so the runner is sound and the
219
+ limitation belongs to the MSYS runtime.
220
+
221
+ Refusing is the honest answer, not the cautious one: a shell whose every command
222
+ dies before `main` would still be reported as running inside a boundary that
223
+ never actually held a command. The refusal names the host's `bash`/`pwsh` tools,
224
+ which ARE confined, so a restricted session keeps a route rather than losing one.
225
+
226
+ This tool offers no per-call escalation argument.
227
+
228
+ ## Payload
229
+
230
+ The vendored runtime comes from Git for Windows `v2.56.0.windows.2` (the
231
+ official upstream release), reduced to the shell, its userland and its exact
232
+ DLL closure. Two assets of that release supply it: the MinGit archive
233
+ `MinGit-2.56.0.2-64-bit.zip` carries everything except `usr/bin/sleep.exe` and
234
+ `usr/bin/seq.exe`, which MinGit does not ship at all and which come from the
235
+ same release's full `Git-2.56.0.2-64-bit.tar.bz2`. Every file is registered in
236
+ `runtime/win32-x64/checksums.sha256` and every redistributed component's license
237
+ text ships beside it. [PROVENANCE.md](PROVENANCE.md) records both source URLs and
238
+ digests, the curation rules, the payload inventory and the license mapping.
239
+
240
+ ## Known limitations
241
+
242
+ - Windows x64 only. The payload is a Windows MSYS2 build and the tool refuses
243
+ to substitute a bash from `PATH` on any other platform or architecture.
244
+ - No ssh client is vendored. The MinGit tree's OpenSSH family is deliberately
245
+ excluded; use the session's own tools for remote work.
246
+ - One shell per session, and the session's shell dies with it. A shell that
247
+ exits or wedges is replaced on the next call, and that call says so.
248
+ - A command that prints past the visible budget loses the front of its output.
249
+ The tail is what is kept, and the result says it was cut, how many bytes are
250
+ shown, and where the complete stream is when the provider spilled one.
251
+ - A background job is one command in one process: it has no persistent state
252
+ across jobs, and it cannot be promoted from a running foreground call
253
+ (a foreground call that hits `timeoutMs` still stops its shell).
254
+
255
+ ## Follow-up work
256
+
257
+ - A packaging-time verification script that re-downloads the pinned source
258
+ assets, rebuilds the payload and diffs the result against `checksums.sha256`,
259
+ so a payload refresh is machine-checked rather than hand-reviewed.
260
+
261
+ ## License
262
+
263
+ Apache-2.0 for this package's own source. The vendored payload keeps its own
264
+ licenses (GPL-2.0-or-later and GPL-3.0-or-later among others); see
265
+ [PROVENANCE.md](PROVENANCE.md).
package/README.zh.md ADDED
@@ -0,0 +1,221 @@
1
+ # @linxin666/dsh-win-bash
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 为 Windows x64 的 DSH 会话提供「钉死版本 + 摘要的私有 bash」。插件随包携带自己的
6
+ Git for Windows MinGit 载荷,在 `win_bash` 工具背后为每个会话维持一个持久 bash 进程,
7
+ 且绝不回退到 `PATH` 上找到的 bash。
8
+
9
+ ## 为什么需要它
10
+
11
+ 模型习惯用 bash 语法写 shell 命令——管道、`$VAR`、单引号、here-document——而只有
12
+ PowerShell 的 Windows 会话往往只回一句语法错误。每一次报错都要多一轮往返,而且
13
+ 并不会告诉模型正确的写法。本包用真实、版本与字节都被钉死的 MSYS2 bash 消除这个
14
+ 循环:模型写什么方言,跑的就是什么方言。
15
+
16
+ shell 必须持久,因为 shell 是有状态的:一条命令 `cd` 过、export 过变量,下一条命令
17
+ 就该看得见。每个会话一个进程正是这一点的实现方式。
18
+
19
+ ## 是什么
20
+
21
+ - 只注册一个模型可见工具 `win_bash`。名字刻意不叫 `bash`:宿主本来就挂了自家的
22
+ bash 系工具,同名要么覆盖别人、要么被别人覆盖,两种都是静默的。
23
+ - 每个会话维持一个持久 `bash -s` 进程。当前目录、导出的变量、函数、别名和 shell
24
+ 历史在该会话的多次调用之间保留,且不与其它会话共享。
25
+ - 每次调用都是前台命令:stdout 与 stderr 分离、各有字节上限、返回命令真实的退出码。
26
+ 超出上限的输出会在模型读到的文本里被标记为截断,而不是被无声切掉。
27
+ - 在渲染出的文本里剥掉终端转义序列。Windows 上的着色库按平台而不是按「有没有接终端」
28
+ 判断,所以管道里的 `vitest`、`pnpm` 照样吐颜色码;本工具把字节原样带回来,在渲染
29
+ 成文本这一步丢掉它们,于是读到的是消息本身而不是 `ESC [ 3 3 m`。被进度条原地重绘
30
+ 的那一行只保留它最后停在的那一帧。原始流与 spill 文件仍保留精确字节。
31
+ - 可选地把命令作为后台任务放进它自己的钉死 bash 进程,立即返回 job id,
32
+ 于是长构建或 watch 既不占住这次调用,也不会随会话 shell 一起死。见
33
+ [后台命令](#后台命令)。
34
+ - 工具注册之前先按 SHA256 清单校验随包载荷;摘要不匹配即拒绝挂载。
35
+ - `win_bash` 注册期间,把宿主自带的 `pwsh` 工具从会话的模型可见面上替换掉,
36
+ 使命令工作落到 bash,而不是落到模型本来就更熟的那个 shell。见
37
+ [该用哪个 shell](#该用哪个-shell)。
38
+
39
+ 本包不注册设置分区、不注册 HTTP 路由、没有浏览器半区:宿主直接用它自己的 Config
40
+ schema 渲染本行的配置表单。
41
+
42
+ ## 该用哪个 shell
43
+
44
+ 本包安装的是一个优先阶梯,而且是一条 Windows 阶梯:
45
+
46
+ 1. **`win_bash`** 承担命令工作。它是钉死版本的 MSYS2 bash,状态跨调用保留,
47
+ 模型写什么方言,跑的就是什么方言。
48
+ 2. **`pwsh`** 承担只有 PowerShell 才做的 Windows 原生工作——cmdlet、注册表、
49
+ Windows 服务——并作为命令不是 bash 时的退路。它由宿主解析:装了 PowerShell 7
50
+ 的机器就是 `pwsh`,没装的则是平台自带的 Windows PowerShell。本包不携带任何
51
+ PowerShell 载荷。
52
+
53
+ `win_bash` 注册期间,本插件把 `pwsh` 从会话的工具面上撤下——这正是第一级能站住
54
+ 的原因:同时看得见两个 shell 的模型会选自己本来就熟的那个,而工具 schema 里没有
55
+ 任何东西能推翻这个习惯。效果就是「会话里只列出一个 shell」,因此 `win_bash` 描述里
56
+ 的记法是「隐藏它而不是禁止它」。
57
+
58
+ - **只管可见性。** 模型刻意发起的 `pwsh` 调用照常执行:这里没有执行层守卫,也没有
59
+ pre-execute 拒绝——直接把退路那一级拿掉,等于用能力损失换取一个偏好。
60
+ - **按会话生效,绝不进程级。** 撤下是本插件所服务会话上的作用域工具限制;同一部署
61
+ 里的其它部分保留自己组合出来的面。
62
+ - **只在 `win_bash` 真的挂载成功时。** 可用性门控拒绝、载荷校验失败、非 Windows
63
+ 宿主,或行里写了 `replacePwsh: false`,都会让 `pwsh` 原封不动。对最终没有替代
64
+ shell 的部署再撤掉它唯一可用的 shell,会让会话两个都没有。
65
+ - **仅 Windows。** POSIX 上宿主 shell 是 bash,win_bash 不挂载,这套逻辑不产生任何
66
+ 限制、监听器或副作用。
67
+ - **可逆。** 每条限制都会在对应会话销毁时、以及插件卸载时被解除,且逐个隔离回调。
68
+
69
+ 把 `replacePwsh` 设为 false 即可让两个 shell 并排列出,只靠工具描述表达偏好。
70
+
71
+ ## 可用性
72
+
73
+ 本工具服务于运行梁神(LiangShen)agent preset 的会话,因此其可用性跟随该预设的
74
+ **声明状态**。挂载时插件向宿主的 agent-preset 注册表查询是否声明了 id 为
75
+ `liangshen` 的预设:已声明则注册工具;未声明则完全不注册任何工具,并用一行
76
+ info 日志说明原因。一个「挂载了但每次调用都报错」的工具等于教模型一个会话并不
77
+ 具备的能力,比诚实的缺席更糟。
78
+
79
+ 日志中可区分三种判定,因为它们需要不同的处置:预设已声明(已注册)、未声明该
80
+ 预设(去启用 `dsh-liangshen` 插件行)、本部署没有可用的 agent-preset 注册表。
81
+ 把 `syncWithLiangShen` 设为 false 会完全跳过门控并总是注册本工具。
82
+
83
+ 判定会先等宿主插件树稳定,再读取名册。若首次读取就已带上该声明,立即判定;
84
+ 若没有,则按一个短的、有上限的节奏重读——因为声明方插件是在自己的激活返回之后才
85
+ 发布预设的,两者先后顺序不固定。迟到的声明绝不会被当成拒绝。
86
+
87
+ 注册表不提供声明变更事件,因此判定在每次挂载时做一次。切换梁神插件行后,
88
+ `win_bash` 会在插件管理器刷新 profile 后跟随生效——与家族其它部分同一套新鲜度
89
+ 模型,而非即时生效。
90
+
91
+ ## 安装
92
+
93
+ ### 从仓库安装(开发调试)
94
+
95
+ ```sh
96
+ git clone https://github.com/zhu1090093659/dsh-web.git
97
+ cd dsh-web
98
+ pnpm install
99
+ pnpm --filter @linxin666/dsh-win-bash build
100
+ dsh plugin --profile web add link:$(pwd)/packages/dsh-win-bash
101
+ ```
102
+
103
+ bundle patch 把本包的行在非 Windows 宿主上标为 disabled,因此 POSIX 的 profile 可以
104
+ 照常携带同一份组合,只是什么都不挂载。
105
+
106
+ ## 配置
107
+
108
+ | 字段 | 默认值 | 含义 |
109
+ | --- | --- | --- |
110
+ | `timeoutMs` | 300000 | 单次调用的墙钟上限(毫秒,1000..3600000)。超时会停掉该 shell,下一次调用起新 shell。 |
111
+ | `maxStdoutBytes` | 131072 | stdout 可见字节上限(1024..1048576)。超出部分从前面丢弃,并在结果文本里写明。 |
112
+ | `maxStderrBytes` | 32768 | stderr 可见字节上限(1024..524288)。 |
113
+ | `enableRunInBackground` | true | 是否提供 `run_in_background`。只有该项为 true 且部署组合了 job registry 时该参数才会被声明;没有 registry 的部署不会声明它,此时仍然请求该参数的调用会被拒绝,而不是退化到前台执行。 |
114
+ | `description` | 内置 | 面向模型的工具描述;部署可描述自己的环境。 |
115
+ | `syncWithLiangShen` | true | 为 true 时仅在 `liangshen` agent preset 已声明时注册本工具;false 跳过该门控、总是注册。 |
116
+ | `replacePwsh` | true | 本工具注册期间,把宿主的 `pwsh` 工具从每个会话的模型可见面上撤下。只管可见性:刻意发起的 `pwsh` 调用照常执行。false 则两个 shell 并列。 |
117
+
118
+ ## 工具接口
119
+
120
+ | 参数 | 必填 | 含义 |
121
+ | --- | --- | --- |
122
+ | `command` | 是 | 要执行的 bash 命令,可多行。 |
123
+ | `workdir` | 否 | 本次命令的工作目录。省略则沿用 shell 当前目录。 |
124
+ | `timeoutMs` | 否 | 单次上限,会被夹到配置的上限。 |
125
+ | `run_in_background` | 否 | 在独立的钉死 bash 进程里执行,并立即返回 job id。仅在组合了 job registry 时提供(见[配置](#配置))。 |
126
+
127
+ 结果包含 `stdout`、`stderr`、命令的 `exitCode`、两条流的截断事实
128
+ (`stdoutTruncated`、`stderrTruncated`、`stdoutLostHead`、`stderrLostHead`、
129
+ `frameOverflow`,以及保存完整流的 `stdoutSpillPath`/`stderrSpillPath`),
130
+ 以及本次调用的沙箱事实。
131
+
132
+ 某条流被截断时,模型可见文本末尾会多出一行,例如:
133
+
134
+ ```text
135
+ [win_bash: stdout was truncated, only the last 131072 bytes are shown; the beginning was dropped; a middle window was dropped by the frame watch limit]
136
+ ```
137
+
138
+ ## 后台命令
139
+
140
+ `run_in_background: true` 会在它**自己的**钉死 bash 进程里执行命令——同一条绝对
141
+ 载荷路径、同一份环境契约、同一套受限逻辑——并立即返回 job id,而不是等命令结束。
142
+ 用宿主的 `job_output` 收取该任务,用 `job_kill` 终止它。
143
+
144
+ 独立进程是要点,不是实现细节。会话的持久 shell 位于 subprocess provider 的托管进程
145
+ 范围内,销毁该范围会终止其中所有仍在运行的进程;因此用 shell 内 `&` 起的任务会随起
146
+ 它的 shell 一起死——下一次超时、下一次中止、或会话销毁时。所以后台命令拥有自己的进
147
+ 程,并比发起它的那次调用活得更久。
148
+
149
+ - **自己的 shell。** 绝不用会话的持久 shell,因此后台命令不会扰乱前台 shell 的当前
150
+ 目录、导出变量或历史。
151
+ - **同一份环境契约。** `PATH` 以载荷的 `usr/bin` 打头,`MSYSTEM=MSYS`、
152
+ `TERM=dumb`、`--norc --noprofile`,且 `TMPDIR`/`TMP`/`TEMP` 指向该任务私有的
153
+ 目录。
154
+ - **同一套模式规则。** 受限会话会以与前台调用相同的 `SANDBOX_UNSUPPORTED` 被拒绝,
155
+ 且发生在任何进程启动、任何任务注册之前。
156
+ - **没有超时。** 任务注册完成即返回;命令的寿命由 `job_kill` 与会话结束界定。
157
+ - **绝不静默退化。** 在没有组合 job registry 的部署上,该调用会以
158
+ `BACKGROUND_UNAVAILABLE` 被拒绝并说明原因;绝不会悄悄改成前台执行——那会让调用方
159
+ 一直等到命令结束,然后随那个 shell 一起死。
160
+
161
+ ## 权限
162
+
163
+ 本工具从宿主的 sandbox-policy 服务解析**调用会话**的有效沙箱策略——与宿主自己的执行族
164
+ 读的是同一个来源,且**带上该会话**:会话自身的模式优先于部署默认,因此用户已限制的会话
165
+ 无法经由部署默认摸到这个 shell。
166
+
167
+ **本工具只在 `danger-full-access` 下运行。** 其他模式一律在任何进程启动之前以
168
+ `SANDBOX_UNSUPPORTED` 拒绝:随包的 MSYS2 bash 在受限令牌下无法启动,所以受限在此
169
+ 不可能产出一个可用的 shell。在 win32 x64(Windows 10.0.26200)上对真实受限令牌 runner
170
+ 实测:`bash.exe`、`sh.exe`、`dash.exe`、`echo.exe` 全部在 `main` 之前死亡,报
171
+
172
+ ```text
173
+ NtCreateDirectoryObject(\BaseNamedObjects\msys-2.0S5-<hash>): 0xC0000022
174
+ ```
175
+
176
+ (退出码 3221225794 / 0xC0000142);系统 Git for Windows 同样失败(`couldn't create signal
177
+ pipe, Win32 error 5`)。同一 runner 下 `cmd.exe`、`node.exe`、`powershell.exe` 均正常,
178
+ 故 runner 本身是好的,限制属于 MSYS 运行时。
179
+
180
+ 拒绝才是诚实的答案,而不是保守的答案:一个每条命令都在 `main` 之前死掉的 shell,会被
181
+ 报告成「跑在某个边界内」,而那个边界从未真正拦住任何命令。
182
+
183
+ **win_bash 是首选 shell,不是唯一 shell。** 它服务不了某个会话时,就退到该平台的原生
184
+ shell 工具:受限会话里的 pwsh 会被保留在工具面上(见 `src/pwsh-replacement.ts`),
185
+ 每一条拒绝与失败信息也都会指明这个去处,避免模型反复重试一个不会恢复的 shell。
186
+
187
+ 本工具不提供单次调用提权参数。
188
+
189
+ ## 载荷
190
+
191
+ 随包载荷来自 Git for Windows `v2.56.0.windows.2`(官方上游 release),裁剪为
192
+ shell、其 userland 以及精确的 DLL 闭包。同一 release 的两份资产共同构成它:MinGit
193
+ 资产 `MinGit-2.56.0.2-64-bit.zip` 提供除 `usr/bin/sleep.exe` 与
194
+ `usr/bin/seq.exe` 之外的全部文件,这两个文件 MinGit 并不出货,取自同一 release 的
195
+ 完整包 `Git-2.56.0.2-64-bit.tar.bz2`。每个文件都登记在
196
+ `runtime/win32-x64/checksums.sha256`,每个被再分发组件的许可证文本都随载荷保留。
197
+ [PROVENANCE.md](PROVENANCE.md) 记录两份来源资产的 URL 与摘要、裁剪规则、载荷清单与
198
+ 许可证对照表。
199
+
200
+ ## 已知限制
201
+
202
+ - 仅支持 Windows x64。载荷是 Windows MSYS2 构建,工具在任何其它平台或架构上都拒绝
203
+ 用 `PATH` 上的 bash 顶替。
204
+ - 不携带 ssh 客户端。MinGit 树里的 OpenSSH 一族被刻意排除;远程操作用会话自己的
205
+ 工具。
206
+ - 每个会话一个 shell,并随会话结束而结束。shell 退出或卡死时下一次调用会换一个新的,
207
+ 且那次调用会明确说明。
208
+ - 命令输出超过可见上限时会丢掉前面的一段。保留的是尾部,结果里会写明被截断、显示了多少
209
+ 字节,以及在 provider 留下 spill 文件时完整流在哪里。
210
+ - 后台任务是「一个进程执行一条命令」:任务之间没有持久状态,也不能由正在跑的前台调用
211
+ 「升级」而来(前台调用到达 `timeoutMs` 时仍然会停掉它的 shell)。
212
+
213
+ ## 后续工作
214
+
215
+ - 打包期校验脚本:重新下载钉死的来源资产、重建载荷并与 `checksums.sha256` 对
216
+ 比,使载荷刷新由机器校验而不是靠人工评审。
217
+
218
+ ## 许可证
219
+
220
+ 本包自身源码为 Apache-2.0。随包载荷保留自己的许可证(含 GPL-2.0-or-later 与
221
+ GPL-3.0-or-later);见 [PROVENANCE.md](PROVENANCE.md)。
@@ -0,0 +1,13 @@
1
+ # Bundle patch for the dsh-win-bash plugin: one host-half row that registers the
2
+ # win_bash tool. The row id stays in this package's own namespace (the loader
3
+ # keeps ONE entry per id across every bundle, later wins, and a shared id is a
4
+ # silent loss), and the row's name is exactly the package name.
5
+ #
6
+ # The row is disabled on every non-Windows host: the vendored payload is a
7
+ # Windows x64 MSYS2 build and the tool refuses to fall back to a bash found on
8
+ # PATH, so on POSIX the row mounts nothing and costs nothing. The loader
9
+ # evaluates the !!js tag in the host process.
10
+ - insert:
11
+ - id: dsh-win-bash
12
+ name: '@linxin666/dsh-win-bash'
13
+ disabled: !!js process.platform !== 'win32'