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

@@ -288,6 +288,33 @@ export function RenderSettingsTab(): React.JSX.Element {
/>
}
/>
<SettingRow
label="记录命令历史"
desc="关闭后不再记录新命令;已保存的历史仍然保留"
control={
<Switch
checked={settings.terminal.historyEnabled !== false}
onChange={(checked) => void updateTerminal({ historyEnabled: checked })}
/>
}
/>
<SettingRow
label="历史条数上限"
desc="命令历史最多保留多少条,重复命令只记一次"
control={
<InputNumber
min={1}
max={500}
step={10}
value={settings.terminal.historyLimit}
disabled={settings.terminal.historyEnabled === false}
onChange={(value) => {
if (typeof value === 'number') void updateTerminal({ historyLimit: value })
}}
style={{ width: 110 }}
/>
}
/>
</div>
)
}