feat(commands): whole-history dedupe + switchable, capped history

历史命令去重从「只跟最新一条比」改为「全历史去重」:重敲任意一条已有命令
时把原条目提到最前(刷新 lastUsedAt)而不是新插一条,历史里每个命令只出现一次。

新增两个设置(设置 → 终端):
- 记录命令历史:关闭后不再记录新命令;已有历史保留,不清空
- 历史条数上限:默认 100,可配 1..500;写入按上限截断,读取也按当前
  上限截断(调低立即生效)

顺修一个暴露的既有 bug:logWrite 用 async appendFile,两次快速追加会
乱序落盘(line two 先于 line one)。改为按文件串行化追加。

测试:tests/commands-store.mjs 全历史去重 / 提到最前 / 上限生效 /
开关关闭不记录 / 关闭保留已有 / 恢复记录 / 越界上限夹紧,全部通过。
This commit is contained in:
Bill committed 2026-09-14 12:01:23 +08:00
1 parent beeb32a76b
commit 277d8bb117
5 files changed
+254 -29

No files matched your search

+6
View File
@@ -36,6 +36,10 @@ export interface TerminalSettings {
pasteRiskConfirm: boolean
/** inline command suggestion popup while typing (history + library) */
suggestEnabled: boolean
/** record executed commands into the history panel */
historyEnabled: boolean
/** max entries kept in command history */
historyLimit: number
/** accent color for the active tab outline, rail indicator and SSH badges */
tabAccentColor: string
}
@@ -114,6 +118,8 @@ export const DEFAULT_SETTINGS: AppSettings = {
copyOnSelect: false,
pasteRiskConfirm: true,
suggestEnabled: true,
historyEnabled: true,
historyLimit: 100,
tabAccentColor: '#3fb950'
},
customThemes: [],