Skip to content

fix(theme-cycler): persist theme selection to settings.json#25

Open
malammar wants to merge 2 commits into
disler:mainfrom
malammar:fix/theme-cycler-persist-on-change
Open

fix(theme-cycler): persist theme selection to settings.json#25
malammar wants to merge 2 commits into
disler:mainfrom
malammar:fix/theme-cycler-persist-on-change

Conversation

@malammar
Copy link
Copy Markdown

Problem

theme-cycler.ts calls ctx.ui.setTheme() to switch themes at runtime but never writes the selection back to settings.json. This means any theme switched via /theme, Ctrl+X, or Ctrl+Q is lost on restart — pi always reverts to whatever "theme" was last set in settings.json.

Fix

Added a persistTheme() helper that writes the selected theme name to ~/.pi/agent/settings.json after every ctx.ui.setTheme() call. This mirrors how pi's own /settings command persists the theme.

function persistTheme(themeName: string): void {
    try {
        const settingsPath = path.join(os.homedir(), ".pi", "agent", "settings.json");
        const raw = fs.existsSync(settingsPath) ? fs.readFileSync(settingsPath, "utf-8") : "{}";
        const settings = JSON.parse(raw);
        settings.theme = themeName;
        fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
    } catch {
        // best-effort
    }
}

Called after all 3 occurrences of ctx.ui.setTheme() in the file:

  • cycleTheme() — Ctrl+X / Ctrl+Q
  • /theme <name> direct set
  • /theme select picker

Testing

  1. Launch pi with -e extensions/theme-cycler.ts
  2. Run /theme and select any theme
  3. Restart pi — theme is now preserved

…ssion_start

The previous fix persisted theme changes correctly but they still reverted
on reload because all extensions call applyExtensionDefaults on session_start,
and the last one to fire would overwrite the restored theme.

Fix at the source: applyExtensionTheme() in themeMap.ts now checks
settings.json first and honours the saved preference over themeMap defaults.
This makes ALL extensions respect the user's saved theme automatically,
with no timing hacks or per-extension workarounds needed.
jetnet pushed a commit to jetnet/pi-coms that referenced this pull request May 23, 2026
Add persistTheme() helper that writes theme name to
~/.pi/agent/settings.json after every setTheme() call:
- cycleTheme() — Ctrl+X / Ctrl+Q
- /theme <name> — direct set
- /theme — select picker

Addresses PR disler#25.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant