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

+57 -4
View File
@@ -1,12 +1,65 @@
// Minimal electron stub for bundling src/main/pty.ts under plain Node
// (tests/ssh-session-e2e.mjs). Only what broadcast.ts touches.
// Minimal electron stub for bundling src/main/*.ts under plain Node
// (tests/ssh-session-e2e.mjs, tests/commands-store.mjs). Only what the bundled
// modules touch.
//
// `app.getPath('userData')` is configurable via `__setUserData` so a test can
// point the settings store at a temp dir and exercise settings-driven behavior.
let userDataPath = process.env.OT_STUB_USERDATA || ''
module.exports = {
BrowserWindow: {
getAllWindows: () => []
},
app: {},
ipcMain: {},
app: {
getPath: (name) => {
if (name === 'userData' && userDataPath) return userDataPath
throw new Error(`electron stub: app.getPath(${name}) is not configured`)
},
setLoginItemSettings: () => {},
isPackaged: false
},
ipcMain: {
handle: () => {},
on: () => {}
},
globalShortcut: {
register: () => true,
unregister: () => {},
unregisterAll: () => {},
isRegistered: () => false
},
webContents: {},
powerSaveBlocker: {
start: () => 1,
stop: () => {},
isStarted: () => false
},
shell: {
openPath: async () => ''
},
safeStorage: {
isEncryptionAvailable: () => false
},
nativeTheme: {
shouldUseDarkColors: true,
on: () => {}
},
Menu: {
buildFromTemplate: () => ({ popup: () => {} }),
setApplicationMenu: () => {}
},
Tray: class {
setToolTip() {}
setContextMenu() {}
on() {}
destroy() {}
static getBounds() {
return { x: 0, y: 0, width: 0, height: 0 }
}
},
nativeImage: {
createFromPath: () => ({ isEmpty: () => true, resize: () => ({}) })
},
__setUserData: (p) => {
userDataPath = p
}
}