dsh-bash-terminal-ts 0.9.5 → 0.9.6-rc.2

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.6-rc.2 (2026-11-29)
4
+
5
+ **R2 history 基础:新增 `src/history.ts` 与 `ScreenHistoryStore`,包含红测。**
6
+
7
+ - 新增 `src/history.ts`,导出:`redactCommand` / `stripAnsi` / `parsePsReadLine` / `parseBashHistory` / `historyCandidates` / `readShellHistory` / `groupByCwd` / `ScreenHistoryStore`。实现仅依赖 `node:fs/promises` / `node:child_process` / `node:path` / `node:crypto`,跨六条兼容线行为一致。
8
+ - 脱敏覆盖 8 类凭据形态:`--password/--token/--api-key` CLI 参数、`*_SECRET=/API_KEY=` 环境变量、`Bearer <v>`、`ghp_/gho_/ghs_/sk-/xox[baprs]-/AKIA/glpat-` 前缀、JWT、`Authorization:` 头、`scheme://user:pass@host` URL。十六进制串不脱敏(git SHA 保留),且幂等。
9
+ - 候选历史文件:powershell 两个 PSReadLine 目录、gitbash USERPROFILE+HOME、msys2 从 `paths.msys2` 推根目录到 `home/<user>` 与 `root`;wsl 伪 URI `wsl:<distro>:~/.bash_history` 避开 UNC 需知发行版内用户名的坑;niu 无持久历史但会回 `reason` 而不抛。
10
+ - 读盘仅切尾部(`historyMaxBytes`),面对实测 13.3 MB 的 `ConsoleHost_history.txt` 不会把整文件入内存;失败一个候选不影响其他。
11
+ - `ScreenHistoryStore`:内存 LRU 上限可配,`record` 内先 `stripAnsi` 后 `redactCommand` 再截尾;`persist` 采用临时文件 + `rename` 原子替换;`load` 对坏 JSON 容错而不抛。
12
+ - 测试:新增 `test/history.ts` 7 组共 28 个断言,包括 fake-spawn 注入的 WSL 分支、LRU 淘汰、截尾标志、persist/load 往返、坏 JSON 容错、record 内脱敏验证、字面量 `pattern` 过滤、cwd 尾部斜杠归一。接入 `package.json` 的 `test` 链,排在 `terminal.js` 之前。
13
+ - **本次不含**:Phase 5 terminal 工具接线、Phase 6 Config + 设置页——拆到 rc.3 / rc.4。
14
+
15
+ ## 0.9.6-rc.1 (2026-11-29)
16
+
17
+ **R1 preset shield:`standard-win` 官方 bash/pwsh 双禁——`shell` 是唯一终端入口。**
18
+
19
+ - `agent-presets/standard-win/agent.cordis.yml`:`tool-pwsh` 行从 `disabled: !!js process.platform !== 'win32'` 改为 `disabled: true`;`tool-bash` 行保持 `disabled: true`。注释块与 persona 的 `Shell tool routing` 同步重写,声明两个官方工具都是故意不挂载。
20
+ - `agent-presets/standard-win/preset.yml` 的 `description` 去掉“沙箱化 PowerShell 面保留”的暗示,新增“`shell` 是唯一终端入口”。
21
+ - `agent-presets/README.md` 模板清单表行与下方段落同步——从“pwsh 保留 + bash 禁”改为“均禁”;新增一段解释“屏蔽是 per-preset 的少一个入口而不是多一个能力”——宿主 `bash-sandbox`/`pwsh-sandbox` 执行器与 `ctx.shell` 能力接缝未动,其他插件照常可用。
22
+ - **部署面**(本机验证,不随包发布):`$DSH_HOME/cordis.patch.yml` 的 `preset-standard-win` 块内 `tool-bash`、`tool-pwsh` 两行同样从条件表达式改为 `disabled: true`;改前已备份为 `cordis.patch.yml.bak-<timestamp>`;YAML 可解析,`- id: preset-*` 行数 9 → 9 不变。
23
+ - **本次不含**:R2 `terminal history` 新动作(Phase 3-9)——拆到 `0.9.6-rc.2`+ 逐阶验证,参见 `.agents/plans/terminal-shell-shield-and-history/tasks.md` 的版本阶梯。
24
+
3
25
  ## 0.9.3 (2026-11-26)
4
26
 
5
27
  **设置卡底栏 Star 快车道:★ 直接打开仓库页(不再只静默收起),隐藏独立成 ×。**
@@ -16,18 +16,19 @@ DSH 0.2.1-alpha.3 起子代理能力面强制走预设(`agentPreset`,toolFil
16
16
 
17
17
  | 模板 | 默认终端 | persona 语法锚 | 官方 shell 工具挂载 |
18
18
  |------|----------|----------------|---------------------|
19
- | `standard-win` | PowerShell (pwsh) | PowerShell 语法、`\` 路径、引号/编码/管道陷阱清单 | **tool-pwsh 保留**(win32 启用,沙箱化 PowerShell 面属 Windows 默认体验);tool-bash 禁用 |
19
+ | `standard-win` | PowerShell (pwsh) | PowerShell 语法、`\` 路径、引号/编码/管道陷阱清单 | tool-bash、tool-pwsh 均禁用(`shell` 唯一入口) |
20
20
  | `standard-win-gitbash` | Git Bash | POSIX bash、`/c/...`、bash 错误纪律/MSYS 路径转换/CRLF-编码段 | tool-bash、tool-pwsh 均禁用 |
21
21
  | `standard-win-msys2` | MSYS2 bash | POSIX bash、`/c/...`、错误纪律/路径转换/双运行时(msys vs mingw64)/CRLF-编码段 | 同上 |
22
22
  | `standard-win-wsl2` | WSL2 bash | Linux bash、`/mnt/c/...`、错误纪律/真 Linux 无 MSYS 层/跨边界陷阱(CRLF、大小写、wslpath、python3)段 | 同上 |
23
23
  | `standard-win-payload` | 插件自备的钉版 POSIX 运行时载荷 | POSIX bash、`/c/...`、错误纪律/MSYS 路径转换(含「缺工具是载荷树缺口,勿现场装系统版」)/CRLF-编码段 | 同上 |
24
24
  | `standard-win-niu` | Niubash (niu) | bash 5.3 语法、Windows 原生路径、错误纪律/无 MSYS 层(确定性路径翻译、niu-git、`/dev/null`→`nul`、`~/.niubashrc`)/CRLF-编码段 | 同上 |
25
25
 
26
- 官方 `tool-bash`(沙箱化同名 bash 工具)在**全部六份模板里无条件 disabled**:目录里
27
- 出现同名 `bash` 正是这组预设要对冲的带内干扰源。pwsh 工具则只在 bash 族四份里禁用
28
- (那里 `shell` 已接 bash 后端);`standard-win` **保留官方 pwsh 工具**——win 默认体验
29
- 就该带沙箱化 PowerShell 面,主入口仍是本插件的 `shell` 工具(后端由用户在设置里选定)。
30
- persona 的 Shell tool routing 行按各自策略声明;需要调整时改对应行即可。
26
+ 官方 `tool-bash` 与 `tool-pwsh`(沙箱化同名工具)在**全部模板里无条件 disabled**:目录里
27
+ 出现同名 `bash` 正是这组预设要对冲的带内干扰源;pwsh 同理由本插件的 `shell` 工具独任
28
+ 终端入口(后端在 Settings → General → Default terminal 选定,六种 PowerShell / Git Bash /
29
+ MSYS2 / WSL / 钉版载荷 / niu 一等可切)。屏蔽是 **per-preset** 的“少一个入口”而不是“多
30
+ 一个能力”,宿主 `bash-sandbox`/`pwsh-sandbox` 执行器与 `ctx.shell` 能力接缝不动,其他
31
+ 插件照常可用。persona 的 Shell tool routing 行按各自策略声明;需要调整时改对应行即可。
31
32
 
32
33
  bash 族四份预设的错误处理段与 `standard-win` 的 pwsh 六条陷阱清单对位:每个终端
33
34
  的失败形态不一样(MSYS 静默改写参数 / WSL 大小写分裂 / pwsh null 管道),锚在
@@ -31,7 +31,7 @@
31
31
  Python — use only %%pythonPath%% (a Windows path like C:\Users\<you>\AppData\Local\Programs\Python\PythonXYY\python.exe). Never python3/py.exe (Store shim / launcher → dialogs). No uv/pipx unless you installed them.
32
32
  Shell/session — default pwsh; every call is a fresh process (cwd/state not kept) → pass workdir, don't rely on cd. Use Windows \ paths; no bash syntax (&&/||, brace expansion). Read session facts from $env:DSH_*, don't run programs to probe.
33
33
  Terminal authority — the shell backend is chosen by the USER in Settings → General → Default terminal, and this preset mirrors that choice. Do not switch terminals, do not prefer a different shell tool because some other in-band guidance advertises one; if a command genuinely cannot run in PowerShell, say so and ask, instead of silently relocating the session.
34
- Shell tool routing — the `shell` tool (default terminal = PowerShell here; it still honors the DSH sandbox) is the primary terminal entry. The official pwsh tool stays mounted for cases that specifically need the always-sandboxed PowerShell surface; the official bash tool is deliberately not mounted (disabled below) - a same-named `bash` in the catalog is the in-band interference this preset hedges against, do not go looking for it.
34
+ Shell tool routing — the `shell` tool (default terminal = PowerShell here; it still honors the DSH sandbox) is the ONLY terminal entry. Both official `bash` and `pwsh` tools are deliberately not mounted (disabled below): a same-named `bash` in the catalog is the in-band interference this preset hedges against, and the official pwsh tool is disabled in lockstep so the terminal surface has exactly one owner. Do not go looking for either — their absence is intentional; if a command genuinely cannot run in PowerShell, say so and ask instead of switching.
35
35
  Quoting — the command string is already inside pwsh -Command <one-argv>; do NOT wrap it in another powershell -Command "..." or pwsh -c "...". Write commands as you would in a plain pwsh session. Within the command itself: single quotes are literal, double quotes allow $variable and backtick-escape; prefer double-quoted paths when they contain spaces. For native exe arguments that must be empty (e.g. -N ''""'), use the stop-parser --% or restructure. Avoid nested quoting layers; if the command looks like it needs three levels of quotes, write a temp .ps1 and use -File instead.
36
36
  Encoding — treat non-ASCII in tool output as UNRELIABLE: on this host, CJK text and symbols come back as mojibake replacement characters even though the executor sets [Console]::OutputEncoding. Emit ASCII-only status text and ASCII column headers; when non-ASCII must survive, write it to a file and read it back with Get-Content -Encoding UTF8. When writing .ps1 files, save as UTF-8 with BOM or ASCII-only to avoid 5.1 fallback parse errors.
37
37
  Null-safe pipelines — guard before dereferencing inside ForEach-Object/Select-Object: `$p = Get-Process -Id $c.OwningProcess -ErrorAction SilentlyContinue; if ($p) { ... }`. `$null.StartTime.ToString()` throws "cannot call a method on a null-valued expression" and discards the entire pipeline's output; wrap StartTime in try/catch too, because access-denied is common on other users' processes.
@@ -55,19 +55,22 @@
55
55
  # registry from here; their executors (`bash-sandbox`/`pwsh-sandbox`) are
56
56
  # host-plane too.
57
57
  # Terminal policy for THIS preset: the plugin's `shell` tool (default terminal
58
- # = PowerShell) is the primary entry, and the official pwsh tool REMAINS mounted
59
- # on win32 - the always-sandboxed PowerShell surface belongs to the Windows
60
- # default experience. The official `bash` tool stays DISABLED: a same-named
61
- # `bash` in the catalog is the in-band interference this set hedges against.
62
- # (The bash-family templates of this set disable BOTH official tools, because
63
- # there `shell` already fronts a bash backend.)
58
+ # = PowerShell) is the ONLY terminal entry — both official `tool-bash` and
59
+ # `tool-pwsh` are DISABLED. A same-named `bash` in the catalog is the in-band
60
+ # interference this set hedges against; pwsh is disabled in lockstep so the
61
+ # terminal surface has exactly one owner (backend switchable in Settings →
62
+ # General → Default terminal across PowerShell / Git Bash / MSYS2 / WSL / pinned
63
+ # payload / niu). Shielding is per-preset — the host `bash-sandbox` / `pwsh-sandbox`
64
+ # executors and the `ctx.shell` capability seam are untouched, so sibling plugins
65
+ # that consume those surfaces still work. (The bash-family templates of this set
66
+ # disable both official tools for the same reason.)
64
67
  - id: tool-bash
65
68
  name: '@deepseek-ai/dsh-tool-bash'
66
69
  disabled: true
67
70
 
68
71
  - id: tool-pwsh
69
72
  name: '@deepseek-ai/dsh-tool-pwsh'
70
- disabled: !!js process.platform !== 'win32'
73
+ disabled: true
71
74
 
72
75
  # ── filesystem ──────────────────────────────────────────────────────────────
73
76
 
@@ -1,2 +1,2 @@
1
1
  name: 标准模式 (Windows)
2
- description: 功能完整的编码 Agent(Windows 环境,默认 PowerShell),支持文件编辑、Shell、文件与网页检索、Skills、计划、目标、子代理和工作流。
2
+ description: 功能完整的编码 Agent(Windows 环境,`shell` 工具默认 PowerShell),支持文件编辑、Shell、文件与网页检索、Skills、计划、目标、子代理和工作流;官方 bash/pwsh 工具均已禁用,`shell` 是唯一终端入口。
package/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "dsh-bash-terminal-ts",
3
3
  "name": "dsh-bash-terminal-ts",
4
- "version": "0.9.5",
4
+ "version": "0.9.6-rc.2",
5
5
  "description": {
6
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
7
  "zh": "一个 shell 工具,可在 Windows 上通过 PowerShell / Git Bash / MSYS2 / WSL / Niubash 执行命令;另提供底部工作台的内嵌终端,支持按 shell 激活开关与默认 shell 回落链。",
@@ -0,0 +1,145 @@
1
+ import { rename, readFile, mkdir } from "node:fs/promises";
2
+ import type { ResolvedPaths } from "./dsh-types.js";
3
+ import type { ShellId } from "./shell-id.js";
4
+ /**
5
+ * A minimal spawn contract so tests can inject a stub. The default uses
6
+ * `node:child_process.spawn`. Implementations must reject on timeout, not
7
+ * on non-zero exit code — a `cat` on a missing file exits 1 and is a
8
+ * legitimate result the caller inspects.
9
+ */
10
+ export interface SpawnResult {
11
+ stdout: string;
12
+ stderr: string;
13
+ code: number;
14
+ }
15
+ export type SpawnFn = (command: string, argv: readonly string[], options: {
16
+ timeoutMs: number;
17
+ }) => Promise<SpawnResult>;
18
+ /** Where a shell keeps its human-entered command history. */
19
+ export interface ShellHistorySource {
20
+ shell: ShellId | string;
21
+ /** Absolute host path; for WSL this is a `wsl:<distro>:<in-distro-path>` pseudo-URI. */
22
+ path: string;
23
+ hint: "psreadline" | "bash_history";
24
+ }
25
+ /** One command line, already parsed and (where applicable) joined across continuations. */
26
+ export interface ShellHistoryLine {
27
+ command: string;
28
+ shell: ShellId | string;
29
+ source: string;
30
+ }
31
+ /**
32
+ * A closed terminal session's screen tail. The `tail` field has already
33
+ * gone through ANSI stripping and credential redaction; the `truncated`
34
+ * flag says whether the buffer was clipped to fit `maxBytes`.
35
+ */
36
+ export interface ScreenHistoryEntry {
37
+ id: string;
38
+ shell: ShellId | string;
39
+ cwd: string;
40
+ startedAt: number;
41
+ endedAt: number;
42
+ exitCode: number | null;
43
+ tail: string;
44
+ truncated: boolean;
45
+ }
46
+ /**
47
+ * Replace credential-shaped substrings with `***`. Idempotent — running
48
+ * twice on already-redacted text produces the same output. Never throws.
49
+ */
50
+ export declare function redactCommand(command: string): string;
51
+ /** Strip xterm escape sequences so the tail is plain text. */
52
+ export declare function stripAnsi(input: string): string;
53
+ /**
54
+ * PSReadLine's `ConsoleHost_history.txt` writes one command per line
55
+ * with CRLF endings. Multi-statement commands joined with `;` stay on
56
+ * one physical line — we do NOT try to split them, because that would
57
+ * mis-attribute side effects.
58
+ */
59
+ export declare function parsePsReadLine(text: string): string[];
60
+ /**
61
+ * bash_history lines are either `#<epoch>` timestamps (present when
62
+ * HISTTIMEFORMAT is set) or the command itself; a command may span
63
+ * multiple physical lines joined by a trailing backslash.
64
+ */
65
+ export declare function parseBashHistory(text: string): string[];
66
+ /**
67
+ * Enumerate plausible history files for one shell, without claiming any of
68
+ * them exists. WSL entries use a `wsl:<distro>:<path>` pseudo-URI so
69
+ * `readShellHistory` can distinguish them and route via `wsl.exe` instead
70
+ * of trying to hit a UNC path that needs a per-distro username.
71
+ */
72
+ export declare function historyCandidates(shell: ShellId | string, paths: ResolvedPaths, env?: NodeJS.ProcessEnv): ShellHistorySource[];
73
+ export interface ReadShellHistoryOptions {
74
+ maxBytes: number;
75
+ timeoutMs: number;
76
+ /** Injectable for tests; defaults to a `node:child_process.spawn` wrapper. */
77
+ spawn?: SpawnFn;
78
+ }
79
+ export interface ReadShellHistoryResult {
80
+ lines: ShellHistoryLine[];
81
+ sources: Array<ShellHistorySource & {
82
+ readable: boolean;
83
+ bytes?: number;
84
+ reason?: string;
85
+ }>;
86
+ }
87
+ /**
88
+ * Read every candidate for one shell, tolerating per-file errors. A
89
+ * missing file or an unreadable path is recorded on `sources[]` with a
90
+ * `reason`, not thrown. WSL pseudo-URIs go through `wsl -d <distro> -e
91
+ * sh -c 'cat ~/.bash_history'` (or `sh -c 'cat <path>'` when the path is
92
+ * absolute in-distro). The `spawn` parameter exists so tests can inject
93
+ * a fake without touching `node:child_process`.
94
+ */
95
+ export declare function readShellHistory(shell: ShellId | string, paths: ResolvedPaths, env: NodeJS.ProcessEnv, options: ReadShellHistoryOptions): Promise<ReadShellHistoryResult>;
96
+ /**
97
+ * Bucket commands by their approximate working directory. The returned
98
+ * array preserves file order; commands before any cd fall under a
99
+ * `cwd: ""` group meaning "unknown / default".
100
+ */
101
+ export declare function groupByCwd(lines: ShellHistoryLine[]): Array<{
102
+ cwd: string;
103
+ commands: string[];
104
+ }>;
105
+ export interface ScreenHistoryStoreOptions {
106
+ size: number;
107
+ path: string;
108
+ maxBytes: number;
109
+ /** Injectable for tests. Defaults to `node:fs/promises`. */
110
+ fs?: {
111
+ readFile: typeof readFile;
112
+ writeFile: (p: string, data: string) => Promise<void>;
113
+ rename: typeof rename;
114
+ mkdir: typeof mkdir;
115
+ };
116
+ }
117
+ /**
118
+ * Bounded, in-memory LRU of recently closed terminal sessions with an
119
+ * optional on-disk mirror. Persist is best-effort: a failed write logs
120
+ * nothing and does not throw, since a corrupted history file must never
121
+ * be the reason the `terminal` tool stops returning data.
122
+ */
123
+ export declare class ScreenHistoryStore {
124
+ private readonly size;
125
+ private readonly path;
126
+ private readonly maxBytes;
127
+ private readonly fsAdapter;
128
+ private readonly entries;
129
+ constructor(options: ScreenHistoryStoreOptions);
130
+ /** Record a closed session. Redacts + truncates before storing. */
131
+ record(entry: Omit<ScreenHistoryEntry, "tail" | "truncated"> & {
132
+ tail: string;
133
+ }): void;
134
+ list(filter?: {
135
+ pattern?: string;
136
+ cwd?: string;
137
+ limit?: number;
138
+ }): ScreenHistoryEntry[];
139
+ load(): Promise<void>;
140
+ persist(): Promise<void>;
141
+ dispose(): void;
142
+ get count(): number;
143
+ }
144
+ /** Re-export the union so `terminal.ts` can pick a single import source. */
145
+ export type HistoryShellId = ShellId;