Skip to content

Commit 5c869f3

Browse files
authored
feat(settings): add auto compaction controls (#1346)
* feat(settings): add auto compaction controls * fix(settings): polish auto compaction
1 parent 1b44101 commit 5c869f3

24 files changed

Lines changed: 840 additions & 200 deletions

File tree

CLAUDE.md

Lines changed: 0 additions & 188 deletions
This file was deleted.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

src/main/presenter/configPresenter/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ interface IAppSettings {
8484
lastSyncTime?: number // Last sync time
8585
customSearchEngines?: string // Custom search engines JSON string
8686
copyWithCotEnabled?: boolean
87+
autoCompactionEnabled?: boolean
88+
autoCompactionTriggerThreshold?: number
89+
autoCompactionRetainRecentPairs?: number
8790
loggingEnabled?: boolean // Whether logging is enabled
8891
floatingButtonEnabled?: boolean // Whether floating button is enabled
8992
default_system_prompt?: string // Default system prompt
@@ -153,6 +156,9 @@ export class ConfigPresenter implements IConfigPresenter {
153156
syncFolderPath: path.join(this.userDataPath, 'sync'),
154157
lastSyncTime: 0,
155158
copyWithCotEnabled: true,
159+
autoCompactionEnabled: true,
160+
autoCompactionTriggerThreshold: 80,
161+
autoCompactionRetainRecentPairs: 2,
156162
loggingEnabled: false,
157163
floatingButtonEnabled: false,
158164
fontFamily: '',
@@ -941,6 +947,30 @@ export class ConfigPresenter implements IConfigPresenter {
941947
this.uiSettingsHelper.setAutoScrollEnabled(enabled)
942948
}
943949

950+
getAutoCompactionEnabled(): boolean {
951+
return this.uiSettingsHelper.getAutoCompactionEnabled()
952+
}
953+
954+
setAutoCompactionEnabled(enabled: boolean): void {
955+
this.uiSettingsHelper.setAutoCompactionEnabled(enabled)
956+
}
957+
958+
getAutoCompactionTriggerThreshold(): number {
959+
return this.uiSettingsHelper.getAutoCompactionTriggerThreshold()
960+
}
961+
962+
setAutoCompactionTriggerThreshold(threshold: number): void {
963+
this.uiSettingsHelper.setAutoCompactionTriggerThreshold(threshold)
964+
}
965+
966+
getAutoCompactionRetainRecentPairs(): number {
967+
return this.uiSettingsHelper.getAutoCompactionRetainRecentPairs()
968+
}
969+
970+
setAutoCompactionRetainRecentPairs(count: number): void {
971+
this.uiSettingsHelper.setAutoCompactionRetainRecentPairs(count)
972+
}
973+
944974
getContentProtectionEnabled(): boolean {
945975
return this.uiSettingsHelper.getContentProtectionEnabled()
946976
}

src/main/presenter/configPresenter/uiSettingsHelper.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { eventBus, SendTarget } from '@/eventbus'
22
import { CONFIG_EVENTS } from '@/events'
33
import fontList from 'font-list'
44

5+
const AUTO_COMPACTION_TRIGGER_THRESHOLD_DEFAULT = 80
6+
const AUTO_COMPACTION_TRIGGER_THRESHOLD_MIN = 5
7+
const AUTO_COMPACTION_TRIGGER_THRESHOLD_MAX = 95
8+
const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_DEFAULT = 2
9+
const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MIN = 1
10+
const AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MAX = 10
11+
512
const normalizeFontNameValue = (name: string): string => {
613
const trimmed = name
714
.replace(/\(.*?\)/g, '')
@@ -61,6 +68,42 @@ export class UiSettingsHelper {
6168
eventBus.send(CONFIG_EVENTS.AUTO_SCROLL_CHANGED, SendTarget.ALL_WINDOWS, boolValue)
6269
}
6370

71+
getAutoCompactionEnabled(): boolean {
72+
const value = this.getSetting<boolean>('autoCompactionEnabled')
73+
if (value === undefined) return true
74+
return Boolean(value)
75+
}
76+
77+
setAutoCompactionEnabled(enabled: boolean): void {
78+
this.setSetting('autoCompactionEnabled', Boolean(enabled))
79+
}
80+
81+
getAutoCompactionTriggerThreshold(): number {
82+
return this.normalizeAutoCompactionTriggerThreshold(
83+
this.getSetting<number>('autoCompactionTriggerThreshold')
84+
)
85+
}
86+
87+
setAutoCompactionTriggerThreshold(threshold: number): void {
88+
this.setSetting(
89+
'autoCompactionTriggerThreshold',
90+
this.normalizeAutoCompactionTriggerThreshold(threshold)
91+
)
92+
}
93+
94+
getAutoCompactionRetainRecentPairs(): number {
95+
return this.normalizeAutoCompactionRetainRecentPairs(
96+
this.getSetting<number>('autoCompactionRetainRecentPairs')
97+
)
98+
}
99+
100+
setAutoCompactionRetainRecentPairs(count: number): void {
101+
this.setSetting(
102+
'autoCompactionRetainRecentPairs',
103+
this.normalizeAutoCompactionRetainRecentPairs(count)
104+
)
105+
}
106+
64107
getContentProtectionEnabled(): boolean {
65108
const value = this.getSetting<boolean>('contentProtectionEnabled')
66109
return value === undefined || value === null ? false : value
@@ -186,4 +229,28 @@ export class UiSettingsHelper {
186229
private normalizeFontName(name: string): string {
187230
return normalizeFontNameValue(name)
188231
}
232+
233+
private normalizeAutoCompactionTriggerThreshold(value: unknown): number {
234+
if (typeof value !== 'number' || !Number.isFinite(value)) {
235+
return AUTO_COMPACTION_TRIGGER_THRESHOLD_DEFAULT
236+
}
237+
238+
const rounded = Math.round(value / 5) * 5
239+
return Math.min(
240+
AUTO_COMPACTION_TRIGGER_THRESHOLD_MAX,
241+
Math.max(AUTO_COMPACTION_TRIGGER_THRESHOLD_MIN, rounded)
242+
)
243+
}
244+
245+
private normalizeAutoCompactionRetainRecentPairs(value: unknown): number {
246+
if (typeof value !== 'number' || !Number.isFinite(value)) {
247+
return AUTO_COMPACTION_RETAIN_RECENT_PAIRS_DEFAULT
248+
}
249+
250+
const rounded = Math.round(value)
251+
return Math.min(
252+
AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MAX,
253+
Math.max(AUTO_COMPACTION_RETAIN_RECENT_PAIRS_MIN, rounded)
254+
)
255+
}
189256
}

0 commit comments

Comments
 (0)