dsh-bash-terminal-ts 0.9.7 → 0.9.8-rc.1
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 +9 -0
- package/dsh.plugin.json +1 -1
- package/lib/history.d.ts +4 -0
- package/lib/history.js +45 -3
- package/package.json +1 -1
- package/src/history.ts +44 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.8-rc.1 (2026-11-29)
|
|
4
|
+
|
|
5
|
+
**R2 体验收尾:groupByCwd 启发式微调 + persist 竞态收敛 + dispose 后拒写。**
|
|
6
|
+
|
|
7
|
+
- `groupByCwd` 的 `CD_RE` 重写:支持 PowerShell 的 `Set-Location -Path X` / `-LiteralPath 'X'` / `-PSPath "X"` 命名参数形式,与 bash 的 `cd X` / `cd "X"` / `cd 'X'` 位置形同存。命名参数优先匹配,避免 `-Path foo` 被当成目录名。`test/history.ts` 开第 3 个 `groupByCwd` 例验证。归属 v0.9.6 计划 S1 项目。
|
|
8
|
+
- `ScreenHistoryStore.persist()` 加 coalesce:一个写正在进行时,后续 `persist()` 只会排队一次重试,而不是同时开 N 个临时文件 + `rename`。实际开发中连续 `open→close` 会触发多次 fire-and-forget persist,旧行实现容易写坏同一 `path`。`test/history.ts` 开 coalesce 例 + dispose 例验证。
|
|
9
|
+
- `ScreenHistoryStore.dispose()` 现会设 `disposed = true`,后续 `persist()` 直接 no-op:插件卸载后任何异步回调不会重建已删除的目录或落盘。
|
|
10
|
+
- **API 冻结**:本版本后 `history` 动作的 schema、`redactCommand` 正则集、`ScreenHistoryStore` LRU + 落盘行为、`groupByCwd` 启发式不再变。新能力属 v0.10.0+ 独立计划。剩余 7 语 README 本计划不承诺(spec.md 约束 6),属发布技能。
|
|
11
|
+
|
|
3
12
|
## 0.9.7 (2026-11-29)
|
|
4
13
|
|
|
5
14
|
**R2 实战补丁:redactCommand 补洞 + msys2 /etc/passwd 回退 + WSL 超时抬升。**
|
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.8-rc.1",
|
|
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.d.ts
CHANGED
|
@@ -126,6 +126,9 @@ export declare class ScreenHistoryStore {
|
|
|
126
126
|
private readonly maxBytes;
|
|
127
127
|
private readonly fsAdapter;
|
|
128
128
|
private readonly entries;
|
|
129
|
+
private persistInFlight;
|
|
130
|
+
private persistQueued;
|
|
131
|
+
private disposed;
|
|
129
132
|
constructor(options: ScreenHistoryStoreOptions);
|
|
130
133
|
/** Record a closed session. Redacts + truncates before storing. */
|
|
131
134
|
record(entry: Omit<ScreenHistoryEntry, "tail" | "truncated"> & {
|
|
@@ -138,6 +141,7 @@ export declare class ScreenHistoryStore {
|
|
|
138
141
|
}): ScreenHistoryEntry[];
|
|
139
142
|
load(): Promise<void>;
|
|
140
143
|
persist(): Promise<void>;
|
|
144
|
+
private doPersist;
|
|
141
145
|
dispose(): void;
|
|
142
146
|
get count(): number;
|
|
143
147
|
}
|
package/lib/history.js
CHANGED
|
@@ -414,7 +414,14 @@ export async function readShellHistory(shell, paths, env, options) {
|
|
|
414
414
|
// model `cd` inside a `;` chain as a boundary — that would produce
|
|
415
415
|
// wrong groupings when a caller runs `cd X; ./build` on one line.
|
|
416
416
|
// Users get a best-effort view; README states the approximation.
|
|
417
|
-
|
|
417
|
+
// v0.9.8 widened to catch PowerShell's named-parameter form
|
|
418
|
+
// (`Set-Location -Path X`, `-LiteralPath X`, `-PSPath X`) alongside the plain
|
|
419
|
+
// positional `cd X` / `cd "X"` / `cd 'X'` forms. Named variants are matched
|
|
420
|
+
// first so `-Path foo` cannot be captured as a directory literally called
|
|
421
|
+
// `-Path`. Multi-statement lines (`cd X; ls`) fall through on the trailing
|
|
422
|
+
// `\S+` capture — the caller still sees the first path token, which is what
|
|
423
|
+
// `groupByCwd` needs to update the bucket.
|
|
424
|
+
const CD_RE = /^\s*(?:cd|Set-Location|sl|Push-Location|pushd)\s+(?:-(?:Path|LiteralPath|PSPath)\s+(?:"([^"]+)"|'([^']+)'|(\S+))(?:\s+-[A-Za-z]+\s+\S+)*|"([^"]+)"|'([^']+)'|(\S+))(?:\s+\S+)*\s*$/i;
|
|
418
425
|
const POP_RE = /^\s*(?:Pop-Location|popd)\b/i;
|
|
419
426
|
function normalizeCwd(raw) {
|
|
420
427
|
if (!raw)
|
|
@@ -441,7 +448,10 @@ export function groupByCwd(lines) {
|
|
|
441
448
|
newCwd = stack.pop() ?? "";
|
|
442
449
|
}
|
|
443
450
|
else if (cd) {
|
|
444
|
-
|
|
451
|
+
// Groups 1-3 are the `-Path/-LiteralPath/-PSPath` named variants,
|
|
452
|
+
// groups 4-6 are the positional `"..."/'...'/bare` shapes. First non-empty
|
|
453
|
+
// wins, which is exactly what an actual `cd` command resolves to.
|
|
454
|
+
const target = normalizeCwd(cd[1] ?? cd[2] ?? cd[3] ?? cd[4] ?? cd[5] ?? cd[6]);
|
|
445
455
|
if (target) {
|
|
446
456
|
// Only push a real dir change (skip `cd -` and `cd` alone).
|
|
447
457
|
if (target !== "-" && target !== "~")
|
|
@@ -481,6 +491,12 @@ export class ScreenHistoryStore {
|
|
|
481
491
|
maxBytes;
|
|
482
492
|
fsAdapter;
|
|
483
493
|
entries = new Map();
|
|
494
|
+
// v0.9.8 coalescing state: while a write is in flight we queue a single
|
|
495
|
+
// follow-up flush instead of stacking N concurrent renames. Disposal
|
|
496
|
+
// short-circuits both paths so a plugin reload cannot leak a rename.
|
|
497
|
+
persistInFlight = null;
|
|
498
|
+
persistQueued = false;
|
|
499
|
+
disposed = false;
|
|
484
500
|
constructor(options) {
|
|
485
501
|
this.size = Math.max(1, options.size | 0);
|
|
486
502
|
this.path = options.path;
|
|
@@ -571,8 +587,33 @@ export class ScreenHistoryStore {
|
|
|
571
587
|
}
|
|
572
588
|
}
|
|
573
589
|
async persist() {
|
|
574
|
-
if (!this.path)
|
|
590
|
+
if (!this.path || this.disposed)
|
|
591
|
+
return;
|
|
592
|
+
// Coalesce: if a write is already running, mark the queue and let the
|
|
593
|
+
// in-flight one pick up the freshest snapshot when it finishes.
|
|
594
|
+
if (this.persistInFlight !== null) {
|
|
595
|
+
this.persistQueued = true;
|
|
596
|
+
await this.persistInFlight;
|
|
597
|
+
if (this.persistQueued)
|
|
598
|
+
return this.persist();
|
|
575
599
|
return;
|
|
600
|
+
}
|
|
601
|
+
this.persistInFlight = this.doPersist();
|
|
602
|
+
try {
|
|
603
|
+
await this.persistInFlight;
|
|
604
|
+
}
|
|
605
|
+
finally {
|
|
606
|
+
this.persistInFlight = null;
|
|
607
|
+
const wasQueued = this.persistQueued;
|
|
608
|
+
this.persistQueued = false;
|
|
609
|
+
if (wasQueued && !this.disposed) {
|
|
610
|
+
// A caller asked us to write while we were mid-flight — flush the
|
|
611
|
+
// latest in-memory view again.
|
|
612
|
+
return this.persist();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async doPersist() {
|
|
576
617
|
const snapshot = Array.from(this.entries.values());
|
|
577
618
|
const payload = JSON.stringify({ version: 1, entries: snapshot }, null, 2);
|
|
578
619
|
const tmpPath = `${this.path}.tmp-${process.pid}-${Date.now()}`;
|
|
@@ -586,6 +627,7 @@ export class ScreenHistoryStore {
|
|
|
586
627
|
}
|
|
587
628
|
}
|
|
588
629
|
dispose() {
|
|
630
|
+
this.disposed = true;
|
|
589
631
|
this.entries.clear();
|
|
590
632
|
}
|
|
591
633
|
get count() {
|
package/package.json
CHANGED
package/src/history.ts
CHANGED
|
@@ -482,7 +482,14 @@ export async function readShellHistory(
|
|
|
482
482
|
// wrong groupings when a caller runs `cd X; ./build` on one line.
|
|
483
483
|
// Users get a best-effort view; README states the approximation.
|
|
484
484
|
|
|
485
|
-
|
|
485
|
+
// v0.9.8 widened to catch PowerShell's named-parameter form
|
|
486
|
+
// (`Set-Location -Path X`, `-LiteralPath X`, `-PSPath X`) alongside the plain
|
|
487
|
+
// positional `cd X` / `cd "X"` / `cd 'X'` forms. Named variants are matched
|
|
488
|
+
// first so `-Path foo` cannot be captured as a directory literally called
|
|
489
|
+
// `-Path`. Multi-statement lines (`cd X; ls`) fall through on the trailing
|
|
490
|
+
// `\S+` capture — the caller still sees the first path token, which is what
|
|
491
|
+
// `groupByCwd` needs to update the bucket.
|
|
492
|
+
const CD_RE = /^\s*(?:cd|Set-Location|sl|Push-Location|pushd)\s+(?:-(?:Path|LiteralPath|PSPath)\s+(?:"([^"]+)"|'([^']+)'|(\S+))(?:\s+-[A-Za-z]+\s+\S+)*|"([^"]+)"|'([^']+)'|(\S+))(?:\s+\S+)*\s*$/i;
|
|
486
493
|
const POP_RE = /^\s*(?:Pop-Location|popd)\b/i;
|
|
487
494
|
|
|
488
495
|
function normalizeCwd(raw: string | undefined): string | null {
|
|
@@ -508,7 +515,10 @@ export function groupByCwd(lines: ShellHistoryLine[]): Array<{ cwd: string; comm
|
|
|
508
515
|
if (pop) {
|
|
509
516
|
newCwd = stack.pop() ?? "";
|
|
510
517
|
} else if (cd) {
|
|
511
|
-
|
|
518
|
+
// Groups 1-3 are the `-Path/-LiteralPath/-PSPath` named variants,
|
|
519
|
+
// groups 4-6 are the positional `"..."/'...'/bare` shapes. First non-empty
|
|
520
|
+
// wins, which is exactly what an actual `cd` command resolves to.
|
|
521
|
+
const target = normalizeCwd(cd[1] ?? cd[2] ?? cd[3] ?? cd[4] ?? cd[5] ?? cd[6]);
|
|
512
522
|
if (target) {
|
|
513
523
|
// Only push a real dir change (skip `cd -` and `cd` alone).
|
|
514
524
|
if (target !== "-" && target !== "~") stack.push(current);
|
|
@@ -563,6 +573,12 @@ export class ScreenHistoryStore {
|
|
|
563
573
|
private readonly maxBytes: number;
|
|
564
574
|
private readonly fsAdapter: NonNullable<ScreenHistoryStoreOptions["fs"]>;
|
|
565
575
|
private readonly entries: Map<string, ScreenHistoryEntry> = new Map();
|
|
576
|
+
// v0.9.8 coalescing state: while a write is in flight we queue a single
|
|
577
|
+
// follow-up flush instead of stacking N concurrent renames. Disposal
|
|
578
|
+
// short-circuits both paths so a plugin reload cannot leak a rename.
|
|
579
|
+
private persistInFlight: Promise<void> | null = null;
|
|
580
|
+
private persistQueued = false;
|
|
581
|
+
private disposed = false;
|
|
566
582
|
|
|
567
583
|
constructor(options: ScreenHistoryStoreOptions) {
|
|
568
584
|
this.size = Math.max(1, options.size | 0);
|
|
@@ -649,7 +665,31 @@ export class ScreenHistoryStore {
|
|
|
649
665
|
}
|
|
650
666
|
|
|
651
667
|
async persist(): Promise<void> {
|
|
652
|
-
if (!this.path) return;
|
|
668
|
+
if (!this.path || this.disposed) return;
|
|
669
|
+
// Coalesce: if a write is already running, mark the queue and let the
|
|
670
|
+
// in-flight one pick up the freshest snapshot when it finishes.
|
|
671
|
+
if (this.persistInFlight !== null) {
|
|
672
|
+
this.persistQueued = true;
|
|
673
|
+
await this.persistInFlight;
|
|
674
|
+
if (this.persistQueued) return this.persist();
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
this.persistInFlight = this.doPersist();
|
|
678
|
+
try {
|
|
679
|
+
await this.persistInFlight;
|
|
680
|
+
} finally {
|
|
681
|
+
this.persistInFlight = null;
|
|
682
|
+
const wasQueued = this.persistQueued;
|
|
683
|
+
this.persistQueued = false;
|
|
684
|
+
if (wasQueued && !this.disposed) {
|
|
685
|
+
// A caller asked us to write while we were mid-flight — flush the
|
|
686
|
+
// latest in-memory view again.
|
|
687
|
+
return this.persist();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
private async doPersist(): Promise<void> {
|
|
653
693
|
const snapshot = Array.from(this.entries.values());
|
|
654
694
|
const payload = JSON.stringify({ version: 1, entries: snapshot }, null, 2);
|
|
655
695
|
const tmpPath = `${this.path}.tmp-${process.pid}-${Date.now()}`;
|
|
@@ -663,6 +703,7 @@ export class ScreenHistoryStore {
|
|
|
663
703
|
}
|
|
664
704
|
|
|
665
705
|
dispose(): void {
|
|
706
|
+
this.disposed = true;
|
|
666
707
|
this.entries.clear();
|
|
667
708
|
}
|
|
668
709
|
|