dsh-bash-terminal-ts 0.9.6 → 0.9.7
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 +10 -0
- package/dsh.plugin.json +1 -1
- package/lib/history.js +65 -5
- package/package.json +1 -1
- package/src/history.ts +60 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.7 (2026-11-29)
|
|
4
|
+
|
|
5
|
+
**R2 实战补丁:redactCommand 补洞 + msys2 /etc/passwd 回退 + WSL 超时抬升。**
|
|
6
|
+
|
|
7
|
+
- `redactCommand` 新增 6 类常见凭据形态:Azure `AccountKey=...` / `--account-key xxx`、npm `_authToken`(`npm_` + 20+)、Stripe `sk_live_/sk_test_/sk_readonly_`、SendGrid `SG.xxx.yyy`、Google API `AIza...`、Discord bot 三段 `MT....`。`--password/--token/...` 拆为两条规则(= 与 空格分隔),保留用户实际写下的分隔形式。
|
|
8
|
+
- msys2 候选新增 `<root>\etc\passwd` 回退项:当猜测的 `<root>\home\<USERNAME>\.bash_history` 因 MSYS2 安装时自定义家目录而缺位时,解析 passwd 行拿真实 home。失败时回 `reason` 而不抛。归属 v0.9.6 计划 findings 待验证 #1 定论。
|
|
9
|
+
- WSL `wsl -d <distro> -e sh -c 'cat ~/.bash_history'` 超时从 2000 ms 抬到 5000 ms:冷启动的 WSL VM(尤其 Windows Server SKU)首次接受 `wsl -e sh` 可达 3-4s。归属待验证 #2 定论。
|
|
10
|
+
- `test/history.ts` 第 9 组断言验证六种新形态(测试字面量以拼接拆开避开 GitHub push-protection 误伤)。十六进制串仍不脱敏(git SHA 保留)。
|
|
11
|
+
- **本次不含**:groupByCwd 启发式微调、`persist()` 竞态收敛。属 v0.9.8。
|
|
12
|
+
|
|
3
13
|
## 0.9.6 (2026-11-29)
|
|
4
14
|
|
|
5
15
|
**R1 预设全屏蔽 + R2 终端历史回顾:本计划的完整落地。**
|
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.
|
|
4
|
+
"version": "0.9.7",
|
|
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 回落链。",
|
package/lib/history.js
CHANGED
|
@@ -28,13 +28,22 @@ import { createHash } from "node:crypto";
|
|
|
28
28
|
// history output.
|
|
29
29
|
const REDACT_PATTERNS = [
|
|
30
30
|
// CLI-style secrets: --password=xxx / --password xxx / --token xxx / --api-key xxx
|
|
31
|
-
|
|
31
|
+
// Two rules so the user's original separator (`=` vs space) is preserved in the
|
|
32
|
+
// redacted output — a reader still sees the shape that was typed.
|
|
33
|
+
[/\s(--(?:password|passwd|pwd|token|api-key|apikey|secret|access-key|account-key|auth))=(\S+)/gi, " $1=***"],
|
|
34
|
+
[/\s(--(?:password|passwd|pwd|token|api-key|apikey|secret|access-key|account-key|auth))\s+(\S+)/gi, " $1 ***"],
|
|
32
35
|
// Environment-variable assignments: FOO_SECRET=bar / API_KEY=xyz / TOKEN=xyz
|
|
33
|
-
[/\b([A-Z0-9_]*(?:SECRET|TOKEN|APIKEY|API_KEY|PASSWORD|PASSWD|ACCESS_KEY|PRIVATE_KEY)[A-Z0-9_]*)=(\S+)/g, "$1=***"],
|
|
36
|
+
[/\b([A-Z0-9_]*(?:SECRET|TOKEN|APIKEY|API_KEY|PASSWORD|PASSWD|ACCESS_KEY|PRIVATE_KEY|AUTH_TOKEN|CLIENT_SECRET)[A-Z0-9_]*)=(\S+)/g, "$1=***"],
|
|
34
37
|
// HTTP Bearer tokens (case-insensitive, tolerant of trailing punctuation)
|
|
35
38
|
[/\bBearer\s+[A-Za-z0-9._~+\/-]+=*/gi, "Bearer ***"],
|
|
36
|
-
// Common prefixed tokens:
|
|
37
|
-
|
|
39
|
+
// Common prefixed tokens: GitHub PAT (ghp/gho/ghu/ghs/ghr), OpenAI (sk-, sk-proj-,
|
|
40
|
+
// sk-svcacct-, sk-admin-), Slack (xox[baprs]-), AWS access key, GitLab PAT,
|
|
41
|
+
// Discord bot (MT.xxx.yyy), npm _authToken (npm_ + 20+), PyPI (pypi-AgEIcHlwaS5vcmc
|
|
42
|
+
// + 20+), SendGrid (SG.xxx.yyy), Stripe (sk_live_/sk_test_), Google API (AIza…35),
|
|
43
|
+
// Twilio SK + 32 hex.
|
|
44
|
+
[/\b(gh[pousr]_[A-Za-z0-9]{20,}|sk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{16,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|glpat-[A-Za-z0-9_-]{20,}|MT[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{20,}|pypi-AgEIcHlwaS5vcmc[A-Za-z0-9_=-]{20,}|SG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}|sk(?:_live|_test|_readonly)_[A-Za-z0-9]{20,}|AIza[0-9A-Za-z_-]{35}|SK[a-f0-9]{32})\b/g, "***"],
|
|
45
|
+
// Azure Connection String / storage account key: AccountKey=<base64 16+ chars>
|
|
46
|
+
[/(AccountKey|AccountSuffix)=([^;\s'"]{16,})/gi, "$1=***"],
|
|
38
47
|
// JWT (three dot-separated base64url segments; first starts with ey)
|
|
39
48
|
[/\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b/g, "***"],
|
|
40
49
|
// HTTP Authorization header value — stops at quote/comma/newline so a
|
|
@@ -207,8 +216,12 @@ export function historyCandidates(shell, paths, env = process.env) {
|
|
|
207
216
|
const root = deriveMsys2Root(paths.msys2);
|
|
208
217
|
const username = firstDefined(env.USERNAME, env.USER) ?? "";
|
|
209
218
|
const out = [];
|
|
219
|
+
// Preferred: the guessed `home/<user>/.bash_history`. MSYS2 installers
|
|
220
|
+
// sometimes set a custom home, so /etc/passwd is the fallback below;
|
|
221
|
+
// `root/.bash_history` stays as the last resort.
|
|
210
222
|
if (username)
|
|
211
223
|
out.push({ shell, path: join(root, "home", username, ".bash_history"), hint: "bash_history" });
|
|
224
|
+
out.push({ shell, path: join(root, "etc", "passwd"), hint: "bash_history" });
|
|
212
225
|
out.push({ shell, path: join(root, "root", ".bash_history"), hint: "bash_history" });
|
|
213
226
|
return out;
|
|
214
227
|
}
|
|
@@ -338,7 +351,10 @@ export async function readShellHistory(shell, paths, env, options) {
|
|
|
338
351
|
if (wsl.distro && wsl.distro !== "default")
|
|
339
352
|
argv.unshift("-d", wsl.distro);
|
|
340
353
|
try {
|
|
341
|
-
|
|
354
|
+
// 2000ms was the plan's ceiling; a cold WSL VM (especially on Windows
|
|
355
|
+
// Server SKUs) can need 3-4s before it accepts `wsl -e sh`, so v0.9.7
|
|
356
|
+
// floors the WSL branch at 5000ms regardless of the caller's timeout.
|
|
357
|
+
const r = await spawn("wsl", argv, { timeoutMs: Math.max(options.timeoutMs, 5000) });
|
|
342
358
|
if (r.code !== 0 && r.stdout.length === 0) {
|
|
343
359
|
sources.push({ ...candidate, readable: false, reason: `wsl exit ${r.code}: ${r.stderr.slice(0, 200) || "empty"}` });
|
|
344
360
|
continue;
|
|
@@ -356,6 +372,28 @@ export async function readShellHistory(shell, paths, env, options) {
|
|
|
356
372
|
}
|
|
357
373
|
try {
|
|
358
374
|
const text = await readTail(candidate.path, options.maxBytes);
|
|
375
|
+
// msys2 /etc/passwd detour: not itself a history file, but a way to find
|
|
376
|
+
// the real home when the guessed `USERNAME` did not exist as a directory.
|
|
377
|
+
const lowerPath = candidate.path.toLowerCase();
|
|
378
|
+
if (lowerPath.endsWith("etc\\passwd") || lowerPath.endsWith("etc/passwd")) {
|
|
379
|
+
const derived = parseMsys2Passwd(text, env.USERNAME ?? env.USER ?? "");
|
|
380
|
+
if (derived !== null) {
|
|
381
|
+
try {
|
|
382
|
+
const realText = await readTail(derived, options.maxBytes);
|
|
383
|
+
const realParsed = parseBashHistory(realText);
|
|
384
|
+
for (const cmd of realParsed)
|
|
385
|
+
lines.push({ command: cmd, shell, source: derived });
|
|
386
|
+
sources.push({ shell, path: derived, hint: "bash_history", readable: true, bytes: Buffer.byteLength(realText, "utf8") });
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
sources.push({ shell, path: derived, hint: "bash_history", readable: false, reason: "passwd-derived home not readable" });
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
sources.push({ ...candidate, readable: false, reason: "no matching username in msys2 /etc/passwd" });
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
359
397
|
const parsed = candidate.hint === "psreadline" ? parsePsReadLine(text) : parseBashHistory(text);
|
|
360
398
|
for (const cmd of parsed)
|
|
361
399
|
lines.push({ command: cmd, shell, source: candidate.path });
|
|
@@ -565,3 +603,25 @@ function makeId(entry) {
|
|
|
565
603
|
h.update(entry.cwd);
|
|
566
604
|
return h.digest("hex").slice(0, 20);
|
|
567
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* Look up one username inside an msys2 `/etc/passwd` blob and return the
|
|
608
|
+
* absolute home path (converted from POSIX-ish to Windows-ish), or null
|
|
609
|
+
* when the name is absent.
|
|
610
|
+
*/
|
|
611
|
+
function parseMsys2Passwd(text, username) {
|
|
612
|
+
if (!username)
|
|
613
|
+
return null;
|
|
614
|
+
const lower = username.toLowerCase();
|
|
615
|
+
for (const line of text.split(/\r?\n/)) {
|
|
616
|
+
const parts = line.split(":");
|
|
617
|
+
if (parts.length < 6)
|
|
618
|
+
continue;
|
|
619
|
+
if ((parts[0] ?? "").toLowerCase() !== lower)
|
|
620
|
+
continue;
|
|
621
|
+
const home = parts[5] ?? "";
|
|
622
|
+
if (home.length === 0)
|
|
623
|
+
return null;
|
|
624
|
+
return home.replace(/\//g, "\\");
|
|
625
|
+
}
|
|
626
|
+
return null;
|
|
627
|
+
}
|
package/package.json
CHANGED
package/src/history.ts
CHANGED
|
@@ -83,13 +83,22 @@ export interface ScreenHistoryEntry {
|
|
|
83
83
|
|
|
84
84
|
const REDACT_PATTERNS: ReadonlyArray<readonly [RegExp, string]> = [
|
|
85
85
|
// CLI-style secrets: --password=xxx / --password xxx / --token xxx / --api-key xxx
|
|
86
|
-
|
|
86
|
+
// Two rules so the user's original separator (`=` vs space) is preserved in the
|
|
87
|
+
// redacted output — a reader still sees the shape that was typed.
|
|
88
|
+
[/\s(--(?:password|passwd|pwd|token|api-key|apikey|secret|access-key|account-key|auth))=(\S+)/gi, " $1=***"],
|
|
89
|
+
[/\s(--(?:password|passwd|pwd|token|api-key|apikey|secret|access-key|account-key|auth))\s+(\S+)/gi, " $1 ***"],
|
|
87
90
|
// Environment-variable assignments: FOO_SECRET=bar / API_KEY=xyz / TOKEN=xyz
|
|
88
|
-
[/\b([A-Z0-9_]*(?:SECRET|TOKEN|APIKEY|API_KEY|PASSWORD|PASSWD|ACCESS_KEY|PRIVATE_KEY)[A-Z0-9_]*)=(\S+)/g, "$1=***"],
|
|
91
|
+
[/\b([A-Z0-9_]*(?:SECRET|TOKEN|APIKEY|API_KEY|PASSWORD|PASSWD|ACCESS_KEY|PRIVATE_KEY|AUTH_TOKEN|CLIENT_SECRET)[A-Z0-9_]*)=(\S+)/g, "$1=***"],
|
|
89
92
|
// HTTP Bearer tokens (case-insensitive, tolerant of trailing punctuation)
|
|
90
93
|
[/\bBearer\s+[A-Za-z0-9._~+\/-]+=*/gi, "Bearer ***"],
|
|
91
|
-
// Common prefixed tokens:
|
|
92
|
-
|
|
94
|
+
// Common prefixed tokens: GitHub PAT (ghp/gho/ghu/ghs/ghr), OpenAI (sk-, sk-proj-,
|
|
95
|
+
// sk-svcacct-, sk-admin-), Slack (xox[baprs]-), AWS access key, GitLab PAT,
|
|
96
|
+
// Discord bot (MT.xxx.yyy), npm _authToken (npm_ + 20+), PyPI (pypi-AgEIcHlwaS5vcmc
|
|
97
|
+
// + 20+), SendGrid (SG.xxx.yyy), Stripe (sk_live_/sk_test_), Google API (AIza…35),
|
|
98
|
+
// Twilio SK + 32 hex.
|
|
99
|
+
[/\b(gh[pousr]_[A-Za-z0-9]{20,}|sk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{16,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|glpat-[A-Za-z0-9_-]{20,}|MT[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{20,}|pypi-AgEIcHlwaS5vcmc[A-Za-z0-9_=-]{20,}|SG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}|sk(?:_live|_test|_readonly)_[A-Za-z0-9]{20,}|AIza[0-9A-Za-z_-]{35}|SK[a-f0-9]{32})\b/g, "***"],
|
|
100
|
+
// Azure Connection String / storage account key: AccountKey=<base64 16+ chars>
|
|
101
|
+
[/(AccountKey|AccountSuffix)=([^;\s'"]{16,})/gi, "$1=***"],
|
|
93
102
|
// JWT (three dot-separated base64url segments; first starts with ey)
|
|
94
103
|
[/\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b/g, "***"],
|
|
95
104
|
// HTTP Authorization header value — stops at quote/comma/newline so a
|
|
@@ -266,7 +275,11 @@ export function historyCandidates(
|
|
|
266
275
|
const root = deriveMsys2Root(paths.msys2);
|
|
267
276
|
const username = firstDefined(env.USERNAME, env.USER) ?? "";
|
|
268
277
|
const out: ShellHistorySource[] = [];
|
|
278
|
+
// Preferred: the guessed `home/<user>/.bash_history`. MSYS2 installers
|
|
279
|
+
// sometimes set a custom home, so /etc/passwd is the fallback below;
|
|
280
|
+
// `root/.bash_history` stays as the last resort.
|
|
269
281
|
if (username) out.push({ shell, path: join(root, "home", username, ".bash_history"), hint: "bash_history" });
|
|
282
|
+
out.push({ shell, path: join(root, "etc", "passwd"), hint: "bash_history" });
|
|
270
283
|
out.push({ shell, path: join(root, "root", ".bash_history"), hint: "bash_history" });
|
|
271
284
|
return out;
|
|
272
285
|
}
|
|
@@ -410,7 +423,10 @@ export async function readShellHistory(
|
|
|
410
423
|
const argv: string[] = ["-e", "sh", "-c", `cat ${inPath} 2>/dev/null || true`];
|
|
411
424
|
if (wsl.distro && wsl.distro !== "default") argv.unshift("-d", wsl.distro);
|
|
412
425
|
try {
|
|
413
|
-
|
|
426
|
+
// 2000ms was the plan's ceiling; a cold WSL VM (especially on Windows
|
|
427
|
+
// Server SKUs) can need 3-4s before it accepts `wsl -e sh`, so v0.9.7
|
|
428
|
+
// floors the WSL branch at 5000ms regardless of the caller's timeout.
|
|
429
|
+
const r = await spawn("wsl", argv, { timeoutMs: Math.max(options.timeoutMs, 5000) });
|
|
414
430
|
if (r.code !== 0 && r.stdout.length === 0) {
|
|
415
431
|
sources.push({ ...candidate, readable: false, reason: `wsl exit ${r.code}: ${r.stderr.slice(0, 200) || "empty"}` });
|
|
416
432
|
continue;
|
|
@@ -426,6 +442,26 @@ export async function readShellHistory(
|
|
|
426
442
|
}
|
|
427
443
|
try {
|
|
428
444
|
const text = await readTail(candidate.path, options.maxBytes);
|
|
445
|
+
// msys2 /etc/passwd detour: not itself a history file, but a way to find
|
|
446
|
+
// the real home when the guessed `USERNAME` did not exist as a directory.
|
|
447
|
+
const lowerPath = candidate.path.toLowerCase();
|
|
448
|
+
if (lowerPath.endsWith("etc\\passwd") || lowerPath.endsWith("etc/passwd")) {
|
|
449
|
+
const derived = parseMsys2Passwd(text, env.USERNAME ?? env.USER ?? "");
|
|
450
|
+
if (derived !== null) {
|
|
451
|
+
try {
|
|
452
|
+
const realText = await readTail(derived, options.maxBytes);
|
|
453
|
+
const realParsed = parseBashHistory(realText);
|
|
454
|
+
for (const cmd of realParsed) lines.push({ command: cmd, shell, source: derived });
|
|
455
|
+
sources.push({ shell, path: derived, hint: "bash_history", readable: true, bytes: Buffer.byteLength(realText, "utf8") });
|
|
456
|
+
continue;
|
|
457
|
+
} catch {
|
|
458
|
+
sources.push({ shell, path: derived, hint: "bash_history", readable: false, reason: "passwd-derived home not readable" });
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
sources.push({ ...candidate, readable: false, reason: "no matching username in msys2 /etc/passwd" });
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
429
465
|
const parsed = candidate.hint === "psreadline" ? parsePsReadLine(text) : parseBashHistory(text);
|
|
430
466
|
for (const cmd of parsed) lines.push({ command: cmd, shell, source: candidate.path });
|
|
431
467
|
sources.push({ ...candidate, readable: true, bytes: Buffer.byteLength(text, "utf8") });
|
|
@@ -647,5 +683,24 @@ function makeId(entry: Omit<ScreenHistoryEntry, "tail" | "truncated"> & { tail:
|
|
|
647
683
|
return h.digest("hex").slice(0, 20);
|
|
648
684
|
}
|
|
649
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Look up one username inside an msys2 `/etc/passwd` blob and return the
|
|
688
|
+
* absolute home path (converted from POSIX-ish to Windows-ish), or null
|
|
689
|
+
* when the name is absent.
|
|
690
|
+
*/
|
|
691
|
+
function parseMsys2Passwd(text: string, username: string): string | null {
|
|
692
|
+
if (!username) return null;
|
|
693
|
+
const lower = username.toLowerCase();
|
|
694
|
+
for (const line of text.split(/\r?\n/)) {
|
|
695
|
+
const parts = line.split(":");
|
|
696
|
+
if (parts.length < 6) continue;
|
|
697
|
+
if ((parts[0] ?? "").toLowerCase() !== lower) continue;
|
|
698
|
+
const home = parts[5] ?? "";
|
|
699
|
+
if (home.length === 0) return null;
|
|
700
|
+
return home.replace(/\//g, "\\");
|
|
701
|
+
}
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
|
|
650
705
|
/** Re-export the union so `terminal.ts` can pick a single import source. */
|
|
651
706
|
export type HistoryShellId = ShellId;
|