mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 01:04:27 +00:00
Reorganize file structure: core/, utils/, modes/interactive/components/, modes/interactive/theme/
This commit is contained in:
parent
00982705f2
commit
83a6c26969
56 changed files with 133 additions and 128 deletions
176
packages/coding-agent/src/core/settings-manager.ts
Normal file
176
packages/coding-agent/src/core/settings-manager.ts
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
import { getAgentDir } from "../utils/config.js";
|
||||
|
||||
export interface CompactionSettings {
|
||||
enabled?: boolean; // default: true
|
||||
reserveTokens?: number; // default: 16384
|
||||
keepRecentTokens?: number; // default: 20000
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
lastChangelogVersion?: string;
|
||||
defaultProvider?: string;
|
||||
defaultModel?: string;
|
||||
defaultThinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
||||
queueMode?: "all" | "one-at-a-time";
|
||||
theme?: string;
|
||||
compaction?: CompactionSettings;
|
||||
hideThinkingBlock?: boolean;
|
||||
shellPath?: string; // Custom shell path (e.g., for Cygwin users on Windows)
|
||||
collapseChangelog?: boolean; // Show condensed changelog after update (use /changelog for full)
|
||||
}
|
||||
|
||||
export class SettingsManager {
|
||||
private settingsPath: string;
|
||||
private settings: Settings;
|
||||
|
||||
constructor(baseDir?: string) {
|
||||
const dir = baseDir || getAgentDir();
|
||||
this.settingsPath = join(dir, "settings.json");
|
||||
this.settings = this.load();
|
||||
}
|
||||
|
||||
private load(): Settings {
|
||||
if (!existsSync(this.settingsPath)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
const content = readFileSync(this.settingsPath, "utf-8");
|
||||
return JSON.parse(content);
|
||||
} catch (error) {
|
||||
console.error(`Warning: Could not read settings file: ${error}`);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
private save(): void {
|
||||
try {
|
||||
// Ensure directory exists
|
||||
const dir = dirname(this.settingsPath);
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
writeFileSync(this.settingsPath, JSON.stringify(this.settings, null, 2), "utf-8");
|
||||
} catch (error) {
|
||||
console.error(`Warning: Could not save settings file: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
getLastChangelogVersion(): string | undefined {
|
||||
return this.settings.lastChangelogVersion;
|
||||
}
|
||||
|
||||
setLastChangelogVersion(version: string): void {
|
||||
this.settings.lastChangelogVersion = version;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getDefaultProvider(): string | undefined {
|
||||
return this.settings.defaultProvider;
|
||||
}
|
||||
|
||||
getDefaultModel(): string | undefined {
|
||||
return this.settings.defaultModel;
|
||||
}
|
||||
|
||||
setDefaultProvider(provider: string): void {
|
||||
this.settings.defaultProvider = provider;
|
||||
this.save();
|
||||
}
|
||||
|
||||
setDefaultModel(modelId: string): void {
|
||||
this.settings.defaultModel = modelId;
|
||||
this.save();
|
||||
}
|
||||
|
||||
setDefaultModelAndProvider(provider: string, modelId: string): void {
|
||||
this.settings.defaultProvider = provider;
|
||||
this.settings.defaultModel = modelId;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getQueueMode(): "all" | "one-at-a-time" {
|
||||
return this.settings.queueMode || "one-at-a-time";
|
||||
}
|
||||
|
||||
setQueueMode(mode: "all" | "one-at-a-time"): void {
|
||||
this.settings.queueMode = mode;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getTheme(): string | undefined {
|
||||
return this.settings.theme;
|
||||
}
|
||||
|
||||
setTheme(theme: string): void {
|
||||
this.settings.theme = theme;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getDefaultThinkingLevel(): "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | undefined {
|
||||
return this.settings.defaultThinkingLevel;
|
||||
}
|
||||
|
||||
setDefaultThinkingLevel(level: "off" | "minimal" | "low" | "medium" | "high" | "xhigh"): void {
|
||||
this.settings.defaultThinkingLevel = level;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getCompactionEnabled(): boolean {
|
||||
return this.settings.compaction?.enabled ?? true;
|
||||
}
|
||||
|
||||
setCompactionEnabled(enabled: boolean): void {
|
||||
if (!this.settings.compaction) {
|
||||
this.settings.compaction = {};
|
||||
}
|
||||
this.settings.compaction.enabled = enabled;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getCompactionReserveTokens(): number {
|
||||
return this.settings.compaction?.reserveTokens ?? 16384;
|
||||
}
|
||||
|
||||
getCompactionKeepRecentTokens(): number {
|
||||
return this.settings.compaction?.keepRecentTokens ?? 20000;
|
||||
}
|
||||
|
||||
getCompactionSettings(): { enabled: boolean; reserveTokens: number; keepRecentTokens: number } {
|
||||
return {
|
||||
enabled: this.getCompactionEnabled(),
|
||||
reserveTokens: this.getCompactionReserveTokens(),
|
||||
keepRecentTokens: this.getCompactionKeepRecentTokens(),
|
||||
};
|
||||
}
|
||||
|
||||
getHideThinkingBlock(): boolean {
|
||||
return this.settings.hideThinkingBlock ?? false;
|
||||
}
|
||||
|
||||
setHideThinkingBlock(hide: boolean): void {
|
||||
this.settings.hideThinkingBlock = hide;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getShellPath(): string | undefined {
|
||||
return this.settings.shellPath;
|
||||
}
|
||||
|
||||
setShellPath(path: string | undefined): void {
|
||||
this.settings.shellPath = path;
|
||||
this.save();
|
||||
}
|
||||
|
||||
getCollapseChangelog(): boolean {
|
||||
return this.settings.collapseChangelog ?? false;
|
||||
}
|
||||
|
||||
setCollapseChangelog(collapse: boolean): void {
|
||||
this.settings.collapseChangelog = collapse;
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue