dsh-bash-terminal-ts 0.8.1 → 0.8.3

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 (56) hide show
  1. package/README.de.md +1 -1
  2. package/README.en.md +6 -2
  3. package/README.es.md +1 -1
  4. package/README.fr.md +1 -1
  5. package/README.it.md +1 -1
  6. package/README.md +5 -1
  7. package/README.ru.md +1 -1
  8. package/agent-presets/README.md +170 -0
  9. package/agent-presets/install-presets.mjs +179 -0
  10. package/agent-presets/standard-win/agent.cordis.yml +271 -0
  11. package/agent-presets/standard-win/preset.yml +2 -0
  12. package/agent-presets/standard-win-gitbash/agent.cordis.yml +271 -0
  13. package/agent-presets/standard-win-gitbash/preset.yml +2 -0
  14. package/agent-presets/standard-win-msys2/agent.cordis.yml +272 -0
  15. package/agent-presets/standard-win-msys2/preset.yml +2 -0
  16. package/agent-presets/standard-win-payload/agent.cordis.yml +271 -0
  17. package/agent-presets/standard-win-payload/preset.yml +2 -0
  18. package/agent-presets/standard-win-wsl2/agent.cordis.yml +271 -0
  19. package/agent-presets/standard-win-wsl2/preset.yml +2 -0
  20. package/cordis.patch.yml +12 -0
  21. package/dist/client.core.js +43 -12
  22. package/dist/client.js +43 -12
  23. package/dsh.plugin.json +2 -2
  24. package/lib/client.js +43 -12
  25. package/lib/dsh-types.d.ts +3 -1
  26. package/lib/index.d.ts +23 -2
  27. package/lib/index.js +79 -18
  28. package/lib/locales.js +27 -9
  29. package/lib/payload.d.ts +72 -0
  30. package/lib/payload.js +279 -0
  31. package/lib/shell-id.d.ts +2 -2
  32. package/lib/shells.d.ts +11 -2
  33. package/lib/shells.js +18 -4
  34. package/lib/terminal.js +1 -0
  35. package/lib/webterminals/catalog.d.ts +2 -0
  36. package/lib/webterminals/catalog.js +1 -0
  37. package/lib/webterminals/host.js +2 -2
  38. package/lib/webterminals/mount.d.ts +5 -0
  39. package/lib/webterminals/mount.js +4 -0
  40. package/package.json +17 -11
  41. package/scripts/check-artifacts.mjs +1 -1
  42. package/scripts/link-shells.mjs +22 -0
  43. package/scripts/payload-alias.mjs +97 -0
  44. package/scripts/provision-payload.mjs +233 -0
  45. package/src/client.tsx +29 -4
  46. package/src/dsh-types.ts +3 -1
  47. package/src/index.ts +117 -16
  48. package/src/locales.ts +27 -9
  49. package/src/payload.ts +322 -0
  50. package/src/shell-id.ts +2 -2
  51. package/src/shells.ts +27 -5
  52. package/src/terminal.ts +1 -0
  53. package/src/webterminals/browser/api.ts +1 -1
  54. package/src/webterminals/catalog.ts +3 -0
  55. package/src/webterminals/host.ts +2 -2
  56. package/src/webterminals/mount.ts +9 -0
package/README.de.md CHANGED
@@ -10,7 +10,7 @@ DSH-Plugin (DeepSeek Harness): ein `shell`-Werkzeug, das unter Windows die Befeh
10
10
  >
11
11
  > | DSH-Segment | Branch | Plugin-Version | npm-dist-tag |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (exakte Aufzählung von 16 Versionen) | `main` (dieser Branch, versionsübergreifender Hauptzweig) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (exakte Aufzählung von 17 Versionen) | `main` (dieser Branch, versionsübergreifender Hauptzweig) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (historisch, eingefroren) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (historisch, eingefroren) | ≤ 0.5.2 | `dsh-0.1.5` |
package/README.en.md CHANGED
@@ -10,7 +10,7 @@ A DeepSeek Harness (DSH) plugin: one `shell` tool that runs commands through **P
10
10
  >
11
11
  > | DSH segment | Branch | Plugin series | npm dist-tag |
12
12
  > |-------------|--------|---------------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (exact 16-version enumeration) | `main` (this branch, cross-version trunk) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (exact 18-version enumeration) | `main` (this branch, cross-version trunk) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (historical, frozen) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (historical, frozen) | ≤ 0.5.2 | `dsh-0.1.5` |
@@ -31,6 +31,8 @@ A DeepSeek Harness (DSH) plugin: one `shell` tool that runs commands through **P
31
31
  - **Official sandbox seam**: the `shell` tool resolves the DSH sandbox policy per call and confines PowerShell argv through `ctx.sandbox` — same fail-closed `SandboxUnavailableError` semantics as the shipped executors. Git Bash, MSYS2 and WSL run unconfined: WSL is its own Linux VM, while Git Bash and MSYS2 cannot run under the DSH Windows ACL restricted-token runner (Cygwin/MSYS2 aborts with `CreateFileMapping` Win32 error 5). Official `sandbox_permissions` / `justification` escalation and denial markers included.
32
32
  - **Interactive terminal**: the `terminal` tool opens persistent real-PTY sessions over node-pty — on non-Windows via the official `ctx.subprocess.spawnTerminal` seam, on Windows directly through node-pty because the upstream seam's process inspector is POSIX-only. Actions `open` / `send` / `read` / `signal` / `close`; shell state persists across calls; sessions are managed as background jobs and auto-close when idle.
33
33
  - **Background execution** via the generic jobs registry (`run_in_background` / `job_output` / `job_kill`).
34
+ - **Pinned POSIX runtime payload (a first-class fifth backend, off by default)**: package `@drscrewdriver/posix-runtime-win32-x64` (naming policy: our artifact names never carry bash/gitbash/msys tokens - the tree inside is Git-for-Windows). Two opt-in layers: `enablePosixPayload: true` (operator gate - runs the digest check at startup) plus a "POSIX payload" row switch `shellPayload` in Settings (default off - decides whether a provisioned payload may enter pickers or be chosen as the default terminal). It has its own catalog row, tool description (`bash -lc`), interactive terminal and `payload-unconfined` enforcement facts - it never substitutes for the Git Bash slot. Nothing is downloaded at install - provision it yourself from a LOCAL PortableGit SFX (`node scripts/provision-payload.mjs --from <sfx>`: reverse-unpack, SHA-256 pin, fully self-managed; no third-party payload packages are consumed). A detected WSL distro logs an advisory hint (a real WSL bash is usually the better shell) but does not hide the payload row - the digest gate is the only hard no, and a payload that fails it is never run, never silently replaced.
35
+ - **Terminal-semantics preset templates (`agent-presets/`)**: distributable Agent Presets that declare default terminal, command syntax and a "Terminal authority" anchor at the preset layer (PowerShell / Git Bash / MSYS2 / WSL2 / pinned-payload variants), installed via `npm run presets:install` - the benchmark-style hedge against plugins that rewrite default-terminal semantics at install time: the same bash-first experience, chosen by you in a layer that is auditable and reproducible.
34
36
 
35
37
  ## Screenshots
36
38
 
@@ -77,6 +79,8 @@ This plugin's own “Terminal (multi-shell)” tab needs nothing extra — all f
77
79
 
78
80
  The bundled `cordis.patch.yml` therefore adds two candidates that carry a file name of their own: `C:\msys64\usr\bin\msys-bash.exe` and `C:\Program Files\Git\bin\git-bash.exe`. Both are hard links (same inode, no extra space, delete them to revert), and they only produce a menu entry if they actually exist on the machine. A missing link is skipped per candidate, so the menu stays exactly as it was and nothing fails.
79
81
 
82
+ A third candidate is the pinned POSIX payload's menu entry: `%LOCALAPPDATA%\dsh-bash-terminal-ts\payloads\bash-terminal\bin\bash-terminal.exe` (the path is built from LOCALAPPDATA via `!!js`, so it adapts per user). It is also a hard link into the payload's `bin\`, deliberately named `bash-terminal.exe` - the menu's `bash` key already belongs to the WSL forwarder, and re-using it would push WSL out. The link and the stable junction are created automatically by `scripts/provision-payload.mjs` (only after the digest gate passes) or `node scripts/link-shells.mjs`, inside the user-writable LOCALAPPDATA - no elevation needed. Machines that never provisioned a payload simply have no file there and the candidate is skipped.
83
+
80
84
  Create the aliases (either route):
81
85
 
82
86
  ```powershell
@@ -192,7 +196,7 @@ Details, the argv/env table and the measured smoke output are in `README.md` (Ch
192
196
 
193
197
  ## Config
194
198
 
195
- Web UI: Settings -> General -> Default terminal. Plugin row `config` overrides: `defaultShell`, `timeoutMs`, `maxTimeoutMs`, `pwshPath`, `gitBashPath`, `msys2Path`, `wslPath`, plus the bottom-terminal fields `shellGitBash`, `shellMsys2`, `shellWsl`, `wslDistro`.
199
+ Web UI: Settings -> General -> Default terminal. Plugin row `config` overrides: `defaultShell`, `timeoutMs`, `maxTimeoutMs`, `pwshPath`, `gitBashPath`, `msys2Path`, `wslPath`, plus the bottom-terminal fields `shellGitBash`, `shellMsys2`, `shellWsl`, `shellPayload`, `wslDistro`, and the payload fields `enablePosixPayload`, `payloadPosixPath` (restart to apply).
196
200
 
197
201
  ## Uninstall
198
202
 
package/README.es.md CHANGED
@@ -10,7 +10,7 @@ Plugin de DSH (DeepSeek Harness): una herramienta `shell` que ejecuta de forma u
10
10
  >
11
11
  > | Segmento DSH | Rama | Versión del plugin | dist-tag npm |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (enumeración exacta de 16 versiones) | `main` (esta rama, troncal entre versiones) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (enumeración exacta de 17 versiones) | `main` (esta rama, troncal entre versiones) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (histórica, congelada) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (histórica, congelada) | ≤ 0.5.2 | `dsh-0.1.5` |
package/README.fr.md CHANGED
@@ -10,7 +10,7 @@ Plugin DSH (DeepSeek Harness) : un outil `shell` qui exécute de manière unifi
10
10
  >
11
11
  > | Segment DSH | Branche | Version du plugin | dist-tag npm |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (énumération exacte de 16 versions) | `main` (cette branche, tronc inter-versions) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (énumération exacte de 17 versions) | `main` (cette branche, tronc inter-versions) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (historique, gelée) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (historique, gelée) | ≤ 0.5.2 | `dsh-0.1.5` |
package/README.it.md CHANGED
@@ -10,7 +10,7 @@ Plugin DSH (DeepSeek Harness): uno strumento `shell` che esegue in modo unificat
10
10
  >
11
11
  > | Segmento DSH | Branch | Versione plugin | dist-tag npm |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (enumerazione esatta di 16 versioni) | `main` (questo branch, trunk cross-versione) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (enumerazione esatta di 17 versioni) | `main` (questo branch, trunk cross-versione) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (storico, congelato) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (storico, congelata) | ≤ 0.5.2 | `dsh-0.1.5` |
package/README.md CHANGED
@@ -10,7 +10,7 @@ DSH(DeepSeek Harness)插件:一个 `shell` 工具,在 Windows 上统一
10
10
  >
11
11
  > | DSH 段 | 分支 | 插件版本 | npm dist-tag |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1`(16 档精确枚举) | `main`(本分支,跨版本主干) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3`(18 档精确枚举) | `main`(本分支,跨版本主干) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0`(历史,冻结) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5`(历史,冻结) | ≤ 0.5.2 | `dsh-0.1.5` |
@@ -40,6 +40,8 @@ DSH(DeepSeek Harness)插件:一个 `shell` 工具,在 Windows 上统一
40
40
  - 通过共享的 `ctx.subprocess` seam 派生进程:进程树终止(Windows `taskkill /T`)、SIGTERM→grace→SIGKILL、输出 spill 文件,与官方 `dsh-tool-bash` / `dsh-tool-pwsh` 行为一致。
41
41
  - 后台任务注册进通用 `jobs` registry,支持 `run_in_background` / `job_output` / `job_kill`。
42
42
  - 前端设置页的「默认终端」是枚举(UI 自动渲染为下拉),模型每次调用都只按该设置执行,无法自行切换终端。
43
+ - **钉版 POSIX 运行时载荷(第五个一等终端后端,默认关)**:载荷包 `@drscrewdriver/posix-runtime-win32-x64`(命名政策:我们的制品不带 bash/gitbash/msys token;里面是 Git-for-Windows 运行时树)。两层开关:`enablePosixPayload: true`(操作者门,启动时跑摘要校验)+ 设置页里的「POSIX payload」行开关 `shellPayload`(默认关,决定已装载载荷能否进选择器/被选为默认终端);它有自己的目录行、专属工具描述(bash -lc)、交互终端与 `payload-unconfined` 执法面,**不顶替 Git Bash 槽位**。载荷不随包下载,用 `node scripts/provision-payload.mjs --from <本地 PortableGit SFX>` 自备(反解包 + SHA-256 钉版,自管不取用任何第三方载荷包);**检测到已装 WSL 发行版时只记一条建议日志**(WSL 里的 bash 通常更好用,拿不准选 `wsl`),不屏蔽载荷行——硬门只有摘要校验一条;校验不过即 fail-closed,绝不裸跑、绝不静默换执行器。详见 `src/payload.ts` 头注释。
44
+ - **终端语义预设模板(`agent-presets/`)**:把「默认终端 + 命令语法 + 终端归属权」显式声明在 Agent Preset 层的可分发模板(PowerShell / Git Bash / MSYS2 / WSL2 / 钉版 POSIX 载荷五变体,含 Terminal authority 锚),用 `npm run presets:install` 装机——对标那些「安装即改写默认终端语义」的插件:同一份 bash-first 体验,由你在预设层自己选,可审计、可复现。
43
45
 
44
46
  ## 安装(web profile)
45
47
 
@@ -120,6 +122,8 @@ node "$env:APPDATA\nvm\<node-version>\node_modules\@deepseek-ai\dsh\lib\bin.js"
120
122
 
121
123
  包内 `cordis.patch.yml` 因此给官方终端追加两个**带自己文件名**的候选:`C:\msys64\usr\bin\msys-bash.exe` 和 `C:\Program Files\Git\bin\git-bash.exe`。它们是硬链接(同一 inode,不占空间,删掉即恢复原状),**必须机器上真存在**才有条目;不存在时宿主按候选逐个跳过,菜单与改动前完全一致,不报错。
122
124
 
125
+ 第三个候选是**钉版 POSIX 载荷**的菜单入口:`%LOCALAPPDATA%\dsh-bash-terminal-ts\payloads\bash-terminal\bin\bash-terminal.exe`(路径由 `!!js` 从 LOCALAPPDATA 拼出,每用户自适应)。它同样是指向载荷 `bin\bash.exe` 的硬链接,但名字故意叫 `bash-terminal.exe` 而不是任何裸 `bash`:官方菜单的 `bash` 键已经属于 WSL 转发器,重名会把 WSL 挤出菜单。链接与稳定 junction 由 `scripts/provision-payload.mjs`(摘要校验通过后才写)或 `node scripts/link-shells.mjs` 自动创建在用户可写的 LOCALAPPDATA 里,**不需要提权**;没装载过载荷的机器上该路径不存在,同样按候选跳过。插件自己的底部终端选择器与官方菜单同口径:WSL 发行版在场只是一条建议日志(「真 WSL bash 通常更好用」),**不屏蔽载荷行**——硬门只有摘要校验一条。
126
+
123
127
  建别名(任选一条路径):
124
128
 
125
129
  ```powershell
package/README.ru.md CHANGED
@@ -10,7 +10,7 @@
10
10
  >
11
11
  > | Сегмент DSH | Ветка | Версия плагина | npm dist-tag |
12
12
  > |--------|------|----------|--------------|
13
- > | `0.1.0-rc.2 – 0.2.1-rc.1` (точное перечисление 16 версий) | `main` (эта ветка, кросс-версионный транк) | 0.8.x | `latest` |
13
+ > | `0.1.0-rc.2 – 0.2.1-rc.3` (точное перечисление 17 версий) | `main` (эта ветка, кросс-версионный транк) | 0.8.x | `latest` |
14
14
  > | `>=0.2.0-rc.1 <0.2.1-0` | `compat/0.2.0` (историческая, заморожена) | 0.7.x | `dsh-0.2.0` |
15
15
  > | 0.1.7-rc.1 – 0.1.7.x | `compat/0.1.7` | 0.6.x | `dsh-0.1.7` |
16
16
  > | 0.1.5-alpha.1 – 0.1.5-rc.x | `ts/0.1.5` (историческая, заморожена) | ≤ 0.5.2 | `dsh-0.1.5` |
@@ -0,0 +1,170 @@
1
+ # agent-presets — 终端语义预设模板(对标型对冲包)
2
+
3
+ > 中文 | [English below](#english)
4
+
5
+ ## 这是什么
6
+
7
+ 这组模板把「默认终端是什么、用什么语法写命令、谁有权改终端」这些语义**显式声明在
8
+ Agent Preset 层**,作为对 `dsh-ops` 一类「安装即改写默认终端语义(提示词优先其自带
9
+ bash)」插件的**对标型对冲**:同一份体验(bash-first、报错循环少),但你是在预设层
10
+ 自己选的、可审计的、可复现的,而不是被某个插件在提示词层默默改掉的。
11
+
12
+ DSH 0.2.1-alpha.3 起子代理能力面强制走预设(`agentPreset`,toolFilter 已移除),
13
+ 预设层是官方承认的「能力组合声明位」——把终端语义锚在这里,正是它该待的位置。
14
+
15
+ ## 模板清单
16
+
17
+ | 模板 | 默认终端 | persona 语法锚 | 官方 shell 工具挂载 |
18
+ |------|----------|----------------|---------------------|
19
+ | `standard-win` | PowerShell (pwsh) | PowerShell 语法、`\` 路径、引号/编码/管道陷阱清单 | **tool-pwsh 保留**(win32 启用,沙箱化 PowerShell 面属 Windows 默认体验);tool-bash 禁用 |
20
+ | `standard-win-gitbash` | Git Bash | POSIX bash、`/c/...`、bash 错误纪律/MSYS 路径转换/CRLF-编码段 | tool-bash、tool-pwsh 均禁用 |
21
+ | `standard-win-msys2` | MSYS2 bash | POSIX bash、`/c/...`、错误纪律/路径转换/双运行时(msys vs mingw64)/CRLF-编码段 | 同上 |
22
+ | `standard-win-wsl2` | WSL2 bash | Linux bash、`/mnt/c/...`、错误纪律/真 Linux 无 MSYS 层/跨边界陷阱(CRLF、大小写、wslpath、python3)段 | 同上 |
23
+ | `standard-win-payload` | 插件自备的钉版 POSIX 运行时载荷 | POSIX bash、`/c/...`、错误纪律/MSYS 路径转换(含「缺工具是载荷树缺口,勿现场装系统版」)/CRLF-编码段 | 同上 |
24
+
25
+ 官方 `tool-bash`(沙箱化同名 bash 工具)在**全部五份模板里无条件 disabled**:目录里
26
+ 出现同名 `bash` 正是这组预设要对冲的带内干扰源。pwsh 工具则只在 bash 族四份里禁用
27
+ (那里 `shell` 已接 bash 后端);`standard-win` **保留官方 pwsh 工具**——win 默认体验
28
+ 就该带沙箱化 PowerShell 面,主入口仍是本插件的 `shell` 工具(后端由用户在设置里选定)。
29
+ persona 的 Shell tool routing 行按各自策略声明;需要调整时改对应行即可。
30
+
31
+ bash 族四份预设的错误处理段与 `standard-win` 的 pwsh 六条陷阱清单对位:每个终端
32
+ 的失败形态不一样(MSYS 静默改写参数 / WSL 大小写分裂 / pwsh null 管道),锚在
33
+ persona 层各自说清。
34
+
35
+ 每个模板都含一行 **Terminal authority** 锚:终端由用户在
36
+ Settings → General → Default terminal 决定,模型不得因任何带内提示(包括其它插件的
37
+ 工具广告)自行换终端——`wsl2` 版还额外写明「随包 MSYS 载荷不构成离开 WSL 的理由,
38
+ 真 Linux bash 优先级更高」。这与本插件的机制锚(工具永远服从用户设置、模型无参数可
39
+ 覆盖)双保险。
40
+
41
+ ## 占位符(%%token%%)
42
+
43
+ | token | 含义 | 未提供时 |
44
+ |-------|------|----------|
45
+ | `%%pythonPath%%` | Windows Python 解释器路径(bash 版模板用 `/c/...` 形态) | 该行整行删除 |
46
+ | `%%winPythonWslPath%%` | Windows Python 在 WSL 内的挂载路径 | 该行整行删除 |
47
+
48
+ (`{{model}}` / `{{cwd}}` 是 DSH 宿主的原生模板变量,不归安装脚本管。)
49
+
50
+ ## 安装
51
+
52
+ 脚本随插件分发。两种拿到它的方式:
53
+
54
+ ```powershell
55
+ # A) 从已装插件(在本机任意目录,cd 到 profile 目录后):
56
+ # 插件装在 npm/tgz 后,脚本位于:
57
+ # %USERPROFILE%\.dsh\profiles\<profile>\node_modules\dsh-bash-terminal-ts\agent-presets\install-presets.mjs
58
+ cd $env:USERPROFILE\.dsh\profiles\desktop
59
+ node .\node_modules\dsh-bash-terminal-ts\agent-presets\install-presets.mjs --name standard-win-gitbash
60
+
61
+ # B) 在源码仓里:
62
+ npm run presets:install -- --name standard-win-gitbash
63
+ ```
64
+
65
+ 常用参数(完整说明见 `--help`,里面有五种模板的语义对照与安装后三步):
66
+
67
+ ```powershell
68
+ # 看有什么模板
69
+ node agent-presets/install-presets.mjs --list
70
+
71
+ # 干跑预览(不落盘)
72
+ node agent-presets/install-presets.mjs --name standard-win-gitbash --dry-run
73
+
74
+ # 正式安装:填充 python 路径;不填充则相关行自动删除
75
+ node agent-presets/install-presets.mjs --name standard-win-gitbash --name standard-win-wsl2 `
76
+ --set pythonPath=/c/Users/you/AppData/Local/Programs/Python/Python313/python.exe
77
+ ```
78
+
79
+ **机器中立保证**:模板不含任何本机事实(真实路径一律是 `%%token%%` 或 `<you>` 示例形);
80
+ 不传 `--set` 安装永远是安全的——含未填 token 的行整行删除,不会把 `%%` 碎片写进提示词。
81
+ 脚本只写预设文件:不联网、不改 PATH、不碰 profile 以外的配置。
82
+
83
+ 目标目录默认 `%USERPROFILE%\.dsh\.agent-presets`(可用 `--dest` 改)。已有同名预设
84
+ 会**先整目录备份到 `.agent-presets` 之外**(`%USERPROFILE%\.dsh\_agent-presets-backup\<时间戳>\`)
85
+ 再覆盖——备份绝不留在挂载根里面,否则会被宿主当成一个预设挂载。
86
+
87
+ 安装后三层对齐(`--help` 与安装完成提示都会把这三步说清):
88
+
89
+ 1. 重启/热加载 DSH(宿主开机才挂载 `.agent-presets`);
90
+ 2. 会话选用该预设(子代理经 `agentPreset` 继承);
91
+ 3. 把本插件的 `defaultShell` 设成同一终端(Settings → General 或 `cordis.patch.yml`)。
92
+ 选 `standard-win-payload` 还要两步都开:`enablePosixPayload: true`(操作者门,重启生效)
93
+ + 设置页「POSIX payload」行开关 `shellPayload`(默认关)——载荷是双层 opt-in。
94
+
95
+ ## 配套推荐:dsh-preset-doctor(DSH 预设医生)
96
+
97
+ 装了这组模板后,推荐同时安装 **dsh-preset-doctor**(npm 直接可装)——它是预设层
98
+ 的配套治理工具,与本模板包正好互补:
99
+
100
+ - **跨版本失效自动修**:DSH 把预设机制从「`.agent-presets/` 目录扫描」换到
101
+ 「`cordis.patch.yml` 声明式」时,旧模板会静默失效(UI 只显示加载失败,没有
102
+ 行号没有原因)。预设医生自动扫描、机械可修的**对齐到当前宿主版本语法**
103
+ (写前 `.bak`、原子写、幂等、零 LLM),不可机械修的逐条报告文件:行号+原因+建议。
104
+ - **行级开关与对齐**:每张预设卡内嵌 composition 行清单,可直接禁用/启用预设里的
105
+ 某一工具行(比如把 bash 系模板的 `tool-pwsh` 再关掉一档)、漂移行一键「对齐」——
106
+ 本模板包的人格/工具挂载声明从此不用手改 YAML。
107
+ - **代际显示**:告诉你每个预设「写于哪个版本时代、需要跨越哪些节点」,多主线
108
+ (0.1.1+ 五条线)运行时自选适配分支。
109
+
110
+ 一句话分工:**本包把终端语义写进预设,预设医生让预设在各代宿主下持续可挂载、可治理。**
111
+
112
+ 配套使用三步:
113
+
114
+ 1. 在与本插件同一 profile 里 npm 安装 `dsh-preset-doctor`,重启;
115
+ 2. 打开预设医生面板:刚装的这组模板会被扫成预设卡,每张卡显示它「写于哪个版本
116
+ 时代、需跨越哪些节点」;宿主升过版的,卡上会出现漂移行与「对齐」按钮;
117
+ 3. 机械可修的点「对齐」一次到位(自动 `.bak`+原子写);想微调模板里某一行的挂载
118
+ (比如把 bash 系模板的 `tool-pwsh` 行再禁用掉),用卡内行开关——不要手改 YAML。
119
+
120
+ ## 与钉版 POSIX 载荷(增强 1)的衔接
121
+
122
+ `standard-win-payload` 假设你启用了本插件的备用载荷(命名政策:我们自己的制品不带 bash/gitbash/msys token,载荷包叫 `@drscrewdriver/posix-runtime-win32-x64`,里面是 Git-for-Windows 运行时树):
123
+
124
+ ```yaml
125
+ # profile 的 cordis.patch.yml(本插件条目 config 下)
126
+ enablePosixPayload: true # 操作者门:启动时跑摘要校验
127
+ # 可选:显式载荷根或其 bin/bash.exe;留空走自动发现
128
+ payloadPosixPath: ""
129
+ # 载荷解析成功后,还需在设置页打开「POSIX payload」行开关(shellPayload,默认关)
130
+ # 它才能进底部终端选择器/被选为默认终端(两层 opt-in)
131
+ ```
132
+
133
+ 载荷用 `node scripts/provision-payload.mjs --from <本地 PortableGit SFX>` 自备
134
+ (反解包 + SHA-256 钉版,见脚本头注释)。**优先级规则**:检测到 WSL 已装发行版时
135
+ 载荷不启用(WSL bash 更好用),系统装有 Git Bash / MSYS2 时也用不到载荷——载荷
136
+ 只是最后一级备用执行器,且摘要校验不过就绝不运行(fail-closed)。
137
+
138
+ ## English
139
+
140
+ These templates declare terminal semantics (default shell, command syntax, who may
141
+ change the terminal) **in the Agent Preset layer**, as a benchmark-style hedge
142
+ against harness plugins that silently rewrite default-terminal semantics at install
143
+ time. Same bash-first outcome, chosen by you, auditable, reproducible — and every
144
+ template carries a "Terminal authority" line telling the model not to switch
145
+ terminals because of in-band tool advertising. Install with
146
+ `node agent-presets/install-presets.mjs --name <preset> [--set key=value]` (run
147
+ `--help` for the full walkthrough: template semantics table, placeholder rules,
148
+ the three post-install alignment steps). From an installed plugin the script sits
149
+ at `node_modules/dsh-bash-terminal-ts/agent-presets/install-presets.mjs` inside
150
+ your profile dir. Machine-neutral by construction: templates carry no local
151
+ facts, and a line whose `%%token%%` was not filled via `--set` is dropped whole
152
+ — installing with zero `--set` flags is always safe. Existing presets are backed
153
+ up OUTSIDE the mount root before overwriting.
154
+ `standard-win-payload` pairs with this plugin's opt-in pinned POSIX runtime
155
+ payload (`enablePosixPayload`, package `@drscrewdriver/posix-runtime-win32-x64` —
156
+ our artifact names never carry bash/gitbash/msys tokens, though the tree inside is
157
+ Git-for-Windows; see `scripts/provision-payload.mjs`); a detected WSL
158
+ distro outranks the payload, and an unverifiable payload never runs.
159
+
160
+ Companion recommendation: install **dsh-preset-doctor** (on npm). It scans mounted
161
+ agent presets across host-version migrations, mechanically realigns what it can
162
+ (atomic, `.bak`-first, zero-LLM) and reports the rest with file:line and a
163
+ suggestion — including per-row switches inside each preset card, so the tool
164
+ rows these templates declare stay governable without hand-editing YAML. Using it
165
+ with these templates: install it in the same profile, restart, open its panel —
166
+ the presets you just installed appear as cards showing the era they were written
167
+ for; hit "对齐/align" on drifted ones and use the in-card row switches to tune
168
+ individual tool rows instead of editing YAML by hand. This package writes
169
+ terminal semantics into presets; preset-doctor keeps those presets mountable and
170
+ manageable across generations.
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+ // agent-presets/install-presets.mjs - copy a terminal-semantics preset template
3
+ // into the DSH deployment (%USERPROFILE%\.dsh\.agent-presets by default).
4
+ //
5
+ // What it does:
6
+ // 1. resolves the %%placeholder%% tokens from --set key=value pairs;
7
+ // 2. DROPS any line whose placeholder was not provided (the line is optional
8
+ // machine guidance by design - an unfilled `%%pythonPath%%` sentence is
9
+ // worse than no sentence);
10
+ // 3. backs up an existing same-name preset OUTSIDE .agent-presets (a backup
11
+ // inside the preset dir would be mounted as a preset), then writes.
12
+ // It never deletes anything: overwrite happens only after the backup copy.
13
+ import { parseArgs } from "node:util";
14
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
15
+ import { homedir } from "node:os";
16
+ import { dirname, join, resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+ const TEMPLATES = readdirSync(HERE, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
21
+
22
+ const { values: opt, positionals } = parseArgs({
23
+ allowPositionals: true,
24
+ options: {
25
+ name: { type: "string", multiple: true },
26
+ all: { type: "boolean", default: false },
27
+ dest: { type: "string" },
28
+ set: { type: "string", multiple: true },
29
+ "dry-run": { type: "boolean", default: false },
30
+ list: { type: "boolean", default: false },
31
+ help: { type: "boolean", default: false }
32
+ }
33
+ });
34
+
35
+ if (opt.help || opt.list) {
36
+ console.log(`templates here: ${TEMPLATES.join(", ")}`);
37
+ if (opt.help) {
38
+ console.log([
39
+ "usage:",
40
+ " node install-presets.mjs --list # what is available",
41
+ " node install-presets.mjs --name <preset> [--name ...] # install selected templates",
42
+ " node install-presets.mjs --all [--dry-run] # everything, or preview first",
43
+ " from an installed plugin (profile dir):",
44
+ " node node_modules/dsh-bash-terminal-ts/agent-presets/install-presets.mjs --name <preset>",
45
+ " from the source repo: npm run presets:install -- --name <preset>",
46
+ "",
47
+ "what each template anchors (default terminal + its failure-mode guidance):",
48
+ " standard-win PowerShell (pwsh) - the Windows default, six-item pitfall list",
49
+ " standard-win-gitbash Git Bash - POSIX bash, /c/... paths, MSYS path-conversion traps",
50
+ " standard-win-msys2 MSYS2 bash - + msys-vs-mingw64 dual-runtime guidance",
51
+ " standard-win-wsl2 WSL2 Linux bash - /mnt/c paths, case-sensitivity/CRLF/wslpath traps",
52
+ " standard-win-payload pinned POSIX payload - digest-verified backup runtime; opt-in twice, see below",
53
+ "",
54
+ "placeholders (%%token%% lines in the persona):",
55
+ " --set pythonPath=<path> Windows interpreter; bash templates want /c/... form",
56
+ " --set winPythonWslPath=<path> the same interpreter as WSL sees it (/mnt/c/... form)",
57
+ "A line whose token was not --set is DROPPED whole - installing with no --set flags",
58
+ "is always safe and machine-neutral (no %% residue can ever be written).",
59
+ "",
60
+ "after installing - keep the three layers in agreement:",
61
+ " 1. restart / hot-reload DSH (the host mounts %USERPROFILE%\\.dsh\\.agent-presets at boot);",
62
+ " 2. pick the preset for the session (subagents inherit it through agentPreset);",
63
+ " 3. set this plugin's default terminal to the SAME shell: Settings -> General ->",
64
+ " Default terminal (or defaultShell in cordis.patch.yml). For the payload",
65
+ " template ALSO: enablePosixPayload: true in cordis.patch.yml (operator gate,",
66
+ " takes effect on restart) AND the 'POSIX payload' row switch shellPayload: true",
67
+ " on the settings page - the payload is deliberately opt-in twice.",
68
+ "",
69
+ "safety: an existing same-name preset is copied OUTSIDE the mount root",
70
+ "(%USERPROFILE%\\.dsh\\_agent-presets-backup\\<timestamp>\\) before overwriting; nothing is deleted.",
71
+ "",
72
+ "companion: install the dsh-preset-doctor plugin (npm) - it scans these mounted",
73
+ "presets across host-version migrations, auto-realigns what it can and gives",
74
+ "per-row switches inside each preset card, so the templates stay governable",
75
+ "without hand-editing YAML."
76
+ ].join("\n"));
77
+ }
78
+ process.exit(0);
79
+ }
80
+
81
+ const chosen = opt.all ? TEMPLATES : (opt.name ?? positionals);
82
+ if (chosen.length === 0) {
83
+ console.error("install-presets: nothing selected - use --name <preset> or --all");
84
+ process.exit(2);
85
+ }
86
+ for (const name of chosen) {
87
+ if (!TEMPLATES.includes(name)) {
88
+ console.error(`install-presets: unknown template ${JSON.stringify(name)}; available: ${TEMPLATES.join(", ")}`);
89
+ process.exit(2);
90
+ }
91
+ }
92
+
93
+ const sets = {};
94
+ for (const kv of opt.set ?? []) {
95
+ const i = kv.indexOf("=");
96
+ if (i <= 0) {
97
+ console.error(`install-presets: bad --set ${JSON.stringify(kv)} (expected key=value)`);
98
+ process.exit(2);
99
+ }
100
+ sets[kv.slice(0, i).trim()] = kv.slice(i + 1);
101
+ }
102
+
103
+ const dest = resolve(opt.dest ?? join(process.env.USERPROFILE ?? homedir(), ".dsh", "agent-presets"));
104
+ // Backup lives OUTSIDE the preset directory: .agent-presets is a mount root and
105
+ // every subdirectory of it is treated as a preset by the host.
106
+ const backupRoot = resolve(dest, "..", "_agent-presets-backup");
107
+
108
+ function render(text) {
109
+ const out = [];
110
+ for (const line of text.split(/\r?\n/)) {
111
+ const tokens = [...line.matchAll(/%%([A-Za-z][\w]*)%%/g)].map((m) => m[1]);
112
+ if (tokens.length === 0) {
113
+ out.push(line);
114
+ continue;
115
+ }
116
+ const missing = tokens.filter((t) => !(t in sets));
117
+ if (missing.length > 0) {
118
+ // An optional machine-guidance line without its value: drop the whole
119
+ // line rather than ship a sentence with a hole in it.
120
+ console.log(` note: dropped line (missing --set ${missing.join(", ")}): ${line.trim().slice(0, 80)}...`);
121
+ continue;
122
+ }
123
+ out.push(line.replace(/%%([A-Za-z][\w]*)%%/g, (_m, t) => sets[t]));
124
+ }
125
+ return out.join(/\r\n/.test(text) ? "\r\n" : "\n");
126
+ }
127
+
128
+ let wrote = 0;
129
+ for (const name of chosen) {
130
+ const srcDir = join(HERE, name);
131
+ const target = join(dest, name);
132
+ console.log(`\n[${name}] -> ${target}`);
133
+ const files = readdirSync(srcDir).filter((f) => statSync(join(srcDir, f)).isFile());
134
+ const rendered = new Map();
135
+ for (const f of files) {
136
+ const raw = readFileSync(join(srcDir, f), "utf8");
137
+ // preset.yml has no placeholders but goes through the same pipe for the
138
+ // BOM/encoding check; render() is a no-op there.
139
+ rendered.set(f, f.endsWith(".yml") ? render(raw) : raw);
140
+ }
141
+ // Refuse to write a file that still contains an unresolved token.
142
+ for (const [f, text] of rendered) {
143
+ const leftover = text.match(/%%[A-Za-z][\w]*%%/g);
144
+ if (leftover !== null) {
145
+ console.error(`install-presets: ${f} still holds ${leftover.join(", ")} - pass --set for each or fix the template`);
146
+ process.exit(1);
147
+ }
148
+ }
149
+ if (opt["dry-run"]) {
150
+ console.log(" dry-run: nothing written");
151
+ continue;
152
+ }
153
+ if (existsSync(target)) {
154
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
155
+ const bak = join(backupRoot, stamp, name);
156
+ mkdirSync(dirname(bak), { recursive: true });
157
+ cpSync(target, bak, { recursive: true });
158
+ console.log(` existing preset backed up to ${bak}`);
159
+ }
160
+ mkdirSync(target, { recursive: true });
161
+ for (const [f, text] of rendered) {
162
+ writeFileSync(join(target, f), text, "utf8");
163
+ console.log(` wrote ${f}`);
164
+ wrote++;
165
+ }
166
+ }
167
+ console.log(`\ndone (${wrote} files).`);
168
+ console.log("next: 1) restart / hot-reload DSH to mount the presets; 2) pick the preset per session;");
169
+ console.log("3) set this plugin's defaultShell (Settings -> General) to the SAME terminal the preset anchors.");
170
+ if (chosen.includes("standard-win-payload")) {
171
+ console.log("and for standard-win-payload: enablePosixPayload: true in cordis.patch.yml (restart),");
172
+ console.log("then flip the 'POSIX payload' row switch (shellPayload) on the settings page - opt-in twice.");
173
+ }
174
+ if (Object.keys(sets).length === 0) {
175
+ console.log("note: no --set was passed, so machine-specific sentences (python path) were dropped;");
176
+ console.log("re-run with --set pythonPath=<path> later if you want them in the prompt.");
177
+ }
178
+ console.log("tip: the dsh-preset-doctor plugin keeps these presets mountable across host");
179
+ console.log("versions (auto-realign + per-row switches in each preset card) - worth installing.");