Skip to main content

agentmux_srv_core/migrations/
m0051_palette_12_snap.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Move the colours stored for the 16-slot palette to the 14 slots that
5//! replace it: 12 hues, Black and White
6//! (`docs/specs/SPEC_SHARED_PALETTE_12_HUES_BLACK_WHITE_2026_11_16.md` ยง5).
7//!
8//! The same two stores as `m0045_palette_snap`, by the same code: every
9//! agent's `ui:color` (`agent_content`) and every browser profile's colour
10//! (`browser-profiles.json`). What changed is what the palette says a colour
11//! means (`backend::palette::snap_hex`): one of the 16 slots' own hexes goes to
12//! the slot the palette file's `retired` table names (four pairs merge, Azure
13//! becomes Blue and Pink becomes Rose), a grey is Black or White, and any other
14//! colour goes to the hue nearest it. `m0045` is recorded as done on every
15//! store that has the 16, so the move needs a migration of its own.
16//!
17//! A window tab's `tab:color`, a pane's `frame:color` / `frame:hue`,
18//! `pane:colors` and a backdrop's built-in id are left as they are: they are
19//! read as their slot, a retired id through the `retired` table, and become
20//! current values the next time they are written.
21//!
22//! Idempotent: a value that is already one of the 14 hexes (Black and White
23//! among them) is left alone, and keeps its `updated_at`.
24
25use super::m0045_palette_snap::{snap_agent_colors, snap_profiles_file};
26use super::{Migration, MigrationContext, MigrationError, MigrationScope};
27use crate::backend::browser_profiles_store::profiles_file_path;
28
29pub struct M0051Palette12Snap;
30
31impl Migration for M0051Palette12Snap {
32    fn id(&self) -> &'static str {
33        "0051_palette_12_snap"
34    }
35    fn scope(&self) -> MigrationScope {
36        MigrationScope::Channel
37    }
38    fn description(&self) -> &'static str {
39        "Move agent and browser profile colours from the 16-slot palette to its 12 hues, Black and White"
40    }
41
42    fn up(&self, ctx: &MigrationContext) -> Result<(), MigrationError> {
43        if ctx.channel_store_path.exists() {
44            snap_agent_colors(&ctx.channel_store_path)?;
45        }
46        if let Some(path) = profiles_file_path() {
47            // A corrupt or hand-edited profiles file must not block this migration and every later one.
48            if let Err(e) = snap_profiles_file(&path) {
49                tracing::warn!(error = %e, "palette_12_snap: leaving browser profiles as they are");
50            }
51        }
52        Ok(())
53    }
54}
55
56#[cfg(test)]
57#[path = "m0051_palette_12_snap_tests.rs"]
58mod tests;