repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
pi/agent/lib/settings.ts
RawFile outline
- SETTINGS_PATH line 11
- Settings line 13
- lastChangelogVersion line 14
- theme line 15
- enabledModels line 16
- defaultProvider line 17
- defaultModel line 18
- defaultThinkingLevel line 19
- thinkingBudgets line 20
- quietStart line 21
- collapseChangelog line 22
- editorPaddingX line 23
- showHardwareCursor line 24
- shellPath line 25
- shellCommandPrefix line 26
- npmCommand line 27
- sessionDir line 28
- hideThinkingBlock line 29
- ui line 30
- animations line 31
- autoRename line 32
- ghost line 33
- taint line 34
- dbg line 35
- mux line 36
- sessionRecap line 37
- neko line 38
- UiSettings line 41
- icons line 42
- colors line 43
- cost line 44
- AnimSettings line 47
- working line 48
- thinking line 49
- tool line 50
- width line 51
- fps line 52
- enabled line 53
- random line 54
- AutoRenameSettings line 57
- model line 58
- GhostSettings line 61
- model line 62
- overlay line 63
- behavior line 67
- TaintSettings line 70
- taintAllowlist line 71
- DbgSettings line 74
- enabled line 75
- MuxSettings line 78
- cooldownMs line 79
- providers line 80
- SessionRecapSettings line 83
- focusMinSeconds line 84
- disable line 85
- model line 86
- NekoSettings line 89
- enabled line 90
- loadRaw line 94
- saveRaw line 101
- getSettings line 105
- updateSettings line 110
- setSettings line 117
/**
* Shared settings utilities for pi extensions.
*
* All extension settings live as namespaced keys in ~/.pi/agent/settings.json.
*/
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { getAgentDir } from "@mariozechner/pi-coding-agent";
const SETTINGS_PATH = join(getAgentDir(), "settings.json");
export interface Settings {
lastChangelogVersion?: string;
theme?: string;
enabledModels?: string[];
defaultProvider?: string;
defaultModel?: string;
defaultThinkingLevel?: string;
thinkingBudgets?: Record<string, number>;
quietStart?: boolean;
collapseChangelog?: boolean;
editorPaddingX?: number;
showHardwareCursor?: boolean;
shellPath?: string;
shellCommandPrefix?: string;
npmCommand?: string[];
sessionDir?: string;
hideThinkingBlock?: boolean;
ui?: UiSettings;
animations?: AnimSettings;
autoRename?: AutoRenameSettings;
ghost?: GhostSettings;
taint?: TaintSettings;
dbg?: DbgSettings;
mux?: MuxSettings;
sessionRecap?: SessionRecapSettings;
neko?: NekoSettings;
}
export interface UiSettings {
icons?: Record<string, string>;
colors?: Record<string, string>;
cost?: { showProvider?: boolean };
}
export interface AnimSettings {
working?: string;
thinking?: string;
tool?: string;
width?: "full" | "default" | number;
fps?: number;
enabled?: boolean;
random?: boolean;
}
export interface AutoRenameSettings {
model?: string;
}
export interface GhostSettings {
model?: { provider?: string; id?: string };
overlay?: {
anchor?: string; width?: string; maxHeight?: string;
margin?: { top?: number; bottom?: number; left?: number; right?: number };
};
behavior?: { autoOpen?: boolean; hideOnClose?: boolean };
}
export interface TaintSettings {
taintAllowlist?: string[];
}
export interface DbgSettings {
enabled: boolean;
}
export interface MuxSettings {
cooldownMs?: number;
providers?: Record<string, { keys?: string[]; cooldownMs?: number }>;
}
export interface SessionRecapSettings {
focusMinSeconds?: number;
disable?: boolean;
model?: string;
}
export interface NekoSettings {
enabled?: boolean;
}
function loadRaw(): Settings {
try {
if (!existsSync(SETTINGS_PATH)) return {};
return JSON.parse(readFileSync(SETTINGS_PATH, "utf-8"));
} catch { return {}; }
}
function saveRaw(s: Settings): void {
try { writeFileSync(SETTINGS_PATH, JSON.stringify(s, null, 2) + "\n", "utf-8"); } catch {}
}
export function getSettings<T extends object>(namespace: keyof Settings): T {
const s = loadRaw();
return (s[namespace] ?? {}) as T;
}
export function updateSettings<T extends object>(namespace: keyof Settings, values: Partial<T>): void {
const s = loadRaw();
const existing = (s[namespace] ?? {}) as Record<string, unknown>;
s[namespace] = { ...existing, ...values };
saveRaw(s);
}
export function setSettings<T extends object>(namespace: keyof Settings, values: T): void {
const s = loadRaw();
s[namespace] = values;
saveRaw(s);
}