herdr-gentle-shell 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,388 @@
1
+ // @ts-nocheck
2
+ // herdr-theme-sync.ts — Herdr's palette follows the active Gentle Shell / Pi
3
+ // theme (odd/tasks/theme-sync.md T3b over S3/S4/S5/S7).
4
+ //
5
+ // This is a Pi extension of its own rather than a section of
6
+ // extensions/gentle-herdr-state.ts for one concrete reason: turning a Pi theme
7
+ // colour into a Herdr hex value needs `colorToHex` from
8
+ // @earendil-works/pi-tui, and the state sidecar is loaded by every suite as a
9
+ // renamed copy with its single package import stubbed — a second host import
10
+ // there would mean a second stub in six test files. The sidecar also owns the
11
+ // pane-scoped session state machine; following a theme is independent of it.
12
+ //
13
+ // In one sentence: every tick the follower reads the persisted switch, and when
14
+ // the palette it asks for differs from the one it last applied, it pipes the
15
+ // projection to the plugin's own bin/configure-theme.js.
16
+ //
17
+ // The rules the code keeps, each of them a spec:
18
+ // S3 sync ON -> Herdr's palette is the palette of the theme Pi is showing
19
+ // right now, and a theme recoloured in place (same name, new
20
+ // colours) is noticed without restarting the session;
21
+ // S4 sync OFF -> the one theme the user assigned, resolved by name; a name
22
+ // this install does not have applies nothing;
23
+ // S5 turning the sync off keeps the palette Herdr already has: nothing here
24
+ // ever removes a managed block;
25
+ // S7 the default install (sync off, no theme) spawns nothing and writes
26
+ // nothing.
27
+ //
28
+ // There is deliberately NO Herdr pane gate. Herdr's config is the user's own and
29
+ // outlives any pane, so a Pi session started outside Herdr still keeps Herdr's
30
+ // palette in sync; gating on HERDR_ENV would make the feature work only in the
31
+ // one pane the user already has open.
32
+ //
33
+ // Plain JavaScript with a .ts extension (// @ts-nocheck, no type annotations),
34
+ // exactly like the other extensions, so the rename-and-stub test loading works
35
+ // under plain node.
36
+
37
+ import { colorToHex } from "@earendil-works/pi-tui";
38
+ import { spawnSync } from "node:child_process";
39
+ import { existsSync } from "node:fs";
40
+ import { createRequire } from "node:module";
41
+ import { fileURLToPath } from "node:url";
42
+ import { dirname, join, isAbsolute as pathIsAbsolute, resolve as resolvePath } from "node:path";
43
+
44
+ const require = createRequire(import.meta.url);
45
+
46
+ const TICK_MS = 500;
47
+ const APPLY_TIMEOUT_MS = 60000;
48
+ const PLUGIN_LIST_TIMEOUT_MS = 15000;
49
+ // A refusal is explained in one line; anything longer is noise in a transcript.
50
+ const FAILURE_TAIL_MAX = 300;
51
+
52
+ const HERDR_PLUGIN_ACTIVE_ID = "herdr-gentle-shell";
53
+ const HERDR_PLUGIN_LEGACY_ID = "herdr-gentle-agents";
54
+ const CONFIGURE_BASENAME = "configure.js";
55
+ const THEME_CONFIGURE_BASENAME = "configure-theme.js";
56
+
57
+ // Package-side helpers live in lib/. Tests copy this file out of the repository,
58
+ // so the override points at the real lib/ exactly like GENTLE_CUSTOMIZE_LIB_DIR
59
+ // does for the state sidecar; production resolves relative to this file.
60
+ function libRequire(name) {
61
+ const override = process.env.GENTLE_THEME_SYNC_LIB_DIR;
62
+ const dir = typeof override === "string" && override.length > 0
63
+ ? override
64
+ : join(dirname(fileURLToPath(import.meta.url)), "..", "lib");
65
+ return require(join(dir, name));
66
+ }
67
+
68
+ function themeStore() {
69
+ return libRequire("theme-store.js");
70
+ }
71
+
72
+ function themeProjection() {
73
+ return libRequire("theme-projection.js");
74
+ }
75
+
76
+ /* --------------------------------------------------------- script lookup */
77
+
78
+ // bin/configure-theme.js lives in the Herdr plugin (installed as its own
79
+ // package), so the Pi side resolves that root exactly like
80
+ // lib/gentle-sidebar.js and the state sidecar do: a read-only
81
+ // `herdr plugin list --json`, with GENTLE_HERDR_PLUGIN_ROOT as the documented
82
+ // override for isolated runs. The active (renamed) id is queried first; a zero
83
+ // match falls through to one explicit lookup by the retired id. Ambiguous roots
84
+ // fail closed on either id.
85
+ function herdrPluginRoots(id) {
86
+ let result;
87
+ try {
88
+ result = spawnSync(
89
+ process.env.HERDR_BIN_PATH || "herdr",
90
+ ["plugin", "list", "--plugin", id, "--json"],
91
+ { encoding: "utf8", timeout: PLUGIN_LIST_TIMEOUT_MS, windowsHide: true },
92
+ );
93
+ } catch (error) {
94
+ return { ok: false, note: `could not resolve the installed plugin root: ${error?.message ?? error}.` };
95
+ }
96
+ if (result.error) {
97
+ return { ok: false, note: `could not resolve the installed plugin root: ${result.error.message}.` };
98
+ }
99
+ if (result.status !== 0) {
100
+ return { ok: false, note: `could not resolve the installed plugin root (plugin list exited ${result.status}).` };
101
+ }
102
+ try {
103
+ const doc = JSON.parse(result.stdout || "");
104
+ const arr = (doc && doc.result && doc.result.plugins) || doc.plugins || [];
105
+ if (!Array.isArray(arr)) throw new Error("no plugins array");
106
+ const hits = arr.filter((p) => p && (p.plugin_id === id || p.id === id));
107
+ const roots = [...new Set(hits.map((hit) => hit.plugin_root).filter((root) => typeof root === "string" && root.length > 0))];
108
+ return { ok: true, roots };
109
+ } catch (error) {
110
+ return { ok: false, note: `could not resolve the installed plugin root: malformed plugin list (${error?.message ?? error}).` };
111
+ }
112
+ }
113
+
114
+ function checkConfigureScript(roots) {
115
+ if (roots.length !== 1 || !pathIsAbsolute(roots[0])) {
116
+ const why = roots.length === 0 ? "no match" : "ambiguous or non-absolute";
117
+ return { ok: false, note: `could not resolve the installed plugin root (${why}).` };
118
+ }
119
+ const script = join(roots[0], "bin", CONFIGURE_BASENAME);
120
+ if (!existsSync(script)) {
121
+ return { ok: false, note: `could not resolve the installed plugin root (${roots[0]} has no bin/${CONFIGURE_BASENAME}).` };
122
+ }
123
+ return { ok: true, script };
124
+ }
125
+
126
+ function resolveConfigureScript() {
127
+ const override = process.env.GENTLE_HERDR_PLUGIN_ROOT;
128
+ if (typeof override === "string" && override.length > 0) {
129
+ return { ok: true, script: join(resolvePath(override), "bin", CONFIGURE_BASENAME) };
130
+ }
131
+ const active = herdrPluginRoots(HERDR_PLUGIN_ACTIVE_ID);
132
+ if (!active.ok) return active;
133
+ if (active.roots.length > 0) return checkConfigureScript(active.roots);
134
+ const legacy = herdrPluginRoots(HERDR_PLUGIN_LEGACY_ID);
135
+ if (!legacy.ok) return legacy;
136
+ if (legacy.roots.length > 0) return checkConfigureScript(legacy.roots);
137
+ return {
138
+ ok: false,
139
+ note: `could not resolve the installed plugin root (no match for ${HERDR_PLUGIN_ACTIVE_ID} or ${HERDR_PLUGIN_LEGACY_ID}).`,
140
+ };
141
+ }
142
+
143
+ // The theme writer is the sidebar writer's SIBLING, not the same file: each owns
144
+ // a different managed block, so the resolved path only tells us where the plugin
145
+ // lives. Swapping the last segment keeps the override and both id lookups on one
146
+ // code path instead of re-deriving the root three times.
147
+ function resolveThemeScript() {
148
+ const resolved = resolveConfigureScript();
149
+ if (!resolved.ok) return resolved;
150
+ return { ok: true, script: join(dirname(resolved.script), THEME_CONFIGURE_BASENAME) };
151
+ }
152
+
153
+ /* ------------------------------------------------------------ projection */
154
+
155
+ // Pi's `Theme.colors` resolves every token to a `Color` (the terminal default is
156
+ // already substituted), so `colorToHex` is the whole conversion. Anything that is
157
+ // not a concrete hex afterwards is dropped rather than defaulted: projectPalette
158
+ // omits it, and Herdr keeps the base-theme colour for that surface instead of
159
+ // painting a guess.
160
+ function convertColors(colors, projection) {
161
+ const converted = {};
162
+ // `muted` paints two Herdr tokens (subtext0 and overlay0), so the source roles
163
+ // are visited once each: one conversion, one emitted pair, never half-applied.
164
+ for (const piToken of new Set(Object.values(projection.HERDR_ROLE_SOURCES))) {
165
+ let raw;
166
+ try {
167
+ raw = colors[piToken];
168
+ } catch {
169
+ continue;
170
+ }
171
+ // "" is Pi's "terminal default" in a theme document: it has no hex spelling.
172
+ if (raw === "" || raw === undefined || raw === null) continue;
173
+ let hex;
174
+ try {
175
+ hex = colorToHex(raw);
176
+ } catch {
177
+ // One unconvertible token must not cost the rest of the palette.
178
+ continue;
179
+ }
180
+ if (projection.isConcreteHex(hex)) converted[piToken] = hex;
181
+ }
182
+ return converted;
183
+ }
184
+
185
+ // A theme whose palette cannot be read at all is NOT evidence that the user has
186
+ // no palette, so the tick is skipped instead of stripping Herdr's custom block.
187
+ function themeColors(theme) {
188
+ if (!theme || typeof theme !== "object") return null;
189
+ let colors;
190
+ try {
191
+ colors = theme.colors;
192
+ } catch {
193
+ return null;
194
+ }
195
+ if (!colors || typeof colors !== "object") return null;
196
+ return colors;
197
+ }
198
+
199
+ // The last non-empty stderr line, capped: the CLI names its refusal there, and a
200
+ // tick-by-tick wall of text is exactly what must not happen.
201
+ function stderrTail(text) {
202
+ const lines = String(text ?? "")
203
+ .split(/\r?\n/)
204
+ .map((line) => line.trim())
205
+ .filter((line) => line.length > 0);
206
+ if (lines.length === 0) return "";
207
+ return lines[lines.length - 1].slice(0, FAILURE_TAIL_MAX);
208
+ }
209
+
210
+ /* ---------------------------------------------------------------- factory */
211
+
212
+ export default function (pi) {
213
+ if (!pi || typeof pi.on !== "function") return;
214
+
215
+ // Everything the follower remembers for ONE session. The notices are
216
+ // per-session: a tick must never nag, and a new session is a new conversation.
217
+ const seen = {
218
+ stateKey: null, // the last requested {sync, theme} that was acted on
219
+ fingerprint: null, // the last palette that was acted on
220
+ failure: null, // the last failure text already reported
221
+ missingTheme: false, // the unavailable-theme notice was shown
222
+ unresolvable: false, // the plugin-root refusal was shown
223
+ busy: false, // an apply is in flight
224
+ };
225
+ let timer = null;
226
+
227
+ function notify(ctx, message, level = "warning") {
228
+ try {
229
+ if (ctx && ctx.ui && typeof ctx.ui.notify === "function") ctx.ui.notify(message, level);
230
+ } catch {
231
+ // A UI that cannot notify must not break the follower.
232
+ }
233
+ }
234
+
235
+ // The CLI repeats its refusal on every attempt; the user is told once per
236
+ // distinct failure. `seen.failure` is cleared by a success, so the same refusal
237
+ // after a good apply is news again.
238
+ function reportFailure(ctx, text) {
239
+ if (seen.failure === text) return;
240
+ seen.failure = text;
241
+ notify(ctx, text);
242
+ }
243
+
244
+ function applyPalette(ctx, projection, paletteInput) {
245
+ let payload;
246
+ try {
247
+ payload = projection.projectPalette(paletteInput);
248
+ } catch {
249
+ // projectPalette only throws on a malformed input this file built; there is
250
+ // nothing honest to apply, and guessing would paint a palette nobody chose.
251
+ return;
252
+ }
253
+ const resolved = resolveThemeScript();
254
+ if (!resolved.ok) {
255
+ if (!seen.unresolvable) {
256
+ seen.unresolvable = true;
257
+ notify(ctx, `Could not apply the palette to Herdr: ${resolved.note} The palette Herdr has was left untouched.`);
258
+ }
259
+ return;
260
+ }
261
+ let result;
262
+ try {
263
+ result = spawnSync(process.execPath, [resolved.script, "--apply", "--json", "--reload"], {
264
+ input: JSON.stringify(payload),
265
+ encoding: "utf8",
266
+ timeout: APPLY_TIMEOUT_MS,
267
+ windowsHide: true,
268
+ });
269
+ } catch (error) {
270
+ reportFailure(ctx, `Could not apply the palette to Herdr: ${resolved.script} could not start (${error?.message ?? error}).`);
271
+ return;
272
+ }
273
+ if (result.error) {
274
+ reportFailure(ctx, `Could not apply the palette to Herdr: ${resolved.script} could not start (${result.error.message}).`);
275
+ return;
276
+ }
277
+ if (result.status !== 0) {
278
+ const tail = stderrTail(result.stderr);
279
+ reportFailure(ctx, `Could not apply the palette to Herdr: configure-theme exited ${result.status}${tail ? `: ${tail}` : "."}`);
280
+ return;
281
+ }
282
+ seen.failure = null;
283
+ }
284
+
285
+ // One evaluation: read the switch, decide what palette it asks for, and apply it
286
+ // only when that answer is new.
287
+ function step(ctx) {
288
+ const store = themeStore();
289
+ let snapshot;
290
+ try {
291
+ snapshot = store.readThemeState(process.env);
292
+ } catch {
293
+ return;
294
+ }
295
+ // A switch this package cannot read is a refusal (an unparsable or
296
+ // unreadable document): do nothing, and never write.
297
+ if (!snapshot || snapshot.ok !== true) return;
298
+
299
+ const projection = themeProjection();
300
+ const sync = snapshot.sync === true;
301
+ const chosen = sync ? null : projection.normalizeThemeName(snapshot.theme);
302
+ // S7 + S5: sync off with nothing assigned is the default install. No spawn, no
303
+ // write, no removal — Herdr keeps the palette it already has.
304
+ if (!sync && chosen === null) return;
305
+
306
+ let theme;
307
+ let name;
308
+ if (sync) {
309
+ theme = ctx && ctx.ui ? ctx.ui.theme : undefined;
310
+ name = theme && typeof theme.name === "string" ? theme.name : null;
311
+ } else {
312
+ name = chosen;
313
+ theme = undefined;
314
+ try {
315
+ theme = ctx && ctx.ui && typeof ctx.ui.getTheme === "function" ? ctx.ui.getTheme(chosen) : undefined;
316
+ } catch {
317
+ theme = undefined;
318
+ }
319
+ if (!theme) {
320
+ // S4: a selection for a theme this install does not have applies nothing.
321
+ // Recording nothing keeps the tick cheap and lets a later install of that
322
+ // exact theme be picked up without a restart, while the notice is once.
323
+ if (!seen.missingTheme) {
324
+ seen.missingTheme = true;
325
+ notify(
326
+ ctx,
327
+ `The Pi theme "${chosen}" is not installed, so Herdr's palette was left unchanged; pick an installed theme in /herdr-gentle:customize.`,
328
+ );
329
+ }
330
+ return;
331
+ }
332
+ }
333
+
334
+ const rawColors = themeColors(theme);
335
+ if (rawColors === null) return;
336
+
337
+ const colors = convertColors(rawColors, projection);
338
+ const observed = JSON.stringify([sync, chosen]);
339
+ const fingerprint = projection.paletteFingerprint({ name, colors });
340
+ const changed = observed !== seen.stateKey || fingerprint !== seen.fingerprint;
341
+ // Recorded BEFORE the apply on purpose: a failed or refused apply must not be
342
+ // retried on the next tick, and it must not block the next observed change
343
+ // either, which is exactly what "the last observed request" means.
344
+ seen.stateKey = observed;
345
+ seen.fingerprint = fingerprint;
346
+ if (!changed) return;
347
+ applyPalette(ctx, projection, { name, colors });
348
+ }
349
+
350
+ function evaluate(ctx) {
351
+ if (seen.busy) return; // never stack applies
352
+ seen.busy = true;
353
+ try {
354
+ step(ctx);
355
+ } catch {
356
+ // A tick runs from a timer: an escaping error would take Pi down with it.
357
+ } finally {
358
+ seen.busy = false;
359
+ }
360
+ }
361
+
362
+ function stop() {
363
+ if (timer !== null) {
364
+ clearInterval(timer);
365
+ timer = null;
366
+ }
367
+ }
368
+
369
+ pi.on("session_start", (event, ctx) => {
370
+ stop();
371
+ seen.stateKey = null;
372
+ seen.fingerprint = null;
373
+ seen.failure = null;
374
+ seen.missingTheme = false;
375
+ seen.unresolvable = false;
376
+ seen.busy = false;
377
+ // One immediate evaluation, so the palette is right before the first tick
378
+ // instead of up to half a second later — or never, in a short-lived session.
379
+ evaluate(ctx);
380
+ timer = setInterval(() => evaluate(ctx), TICK_MS);
381
+ // An idle follower must never keep Pi (or a scripted session) alive.
382
+ if (timer && typeof timer.unref === "function") timer.unref();
383
+ });
384
+
385
+ pi.on("session_shutdown", () => {
386
+ stop();
387
+ });
388
+ }
@@ -19,6 +19,19 @@
19
19
  // repaint; Esc finishes with done(null) and Enter (or a row click) with
20
20
  // done({categoryId, switchId, valueId}). This module never writes, notifies, or
21
21
  // reloads: the extension's single apply path runs after the overlay resolves.
22
+ //
23
+ // The third category (`Herdr Theme`) belongs to theme sync (odd/tasks/theme-sync.md
24
+ // T3, S1/S2/S4/S7): the `Theme sync` switch is an ordinary pill toggle, while
25
+ // the `Gentle Shell theme` value row opens the host's theme list and is only
26
+ // available while the sync is off. That value row is the card's only
27
+ // NON-toggle row — it carries `id: "select"`, is painted dim and is denied the
28
+ // selection band while the sync is on, because the band is this card's promise
29
+ // that Enter applies the row.
30
+
31
+ // The stored theme value is spelled by lib/theme-projection.js: the label a name
32
+ // reads as and the "no theme" spelling live there, so the panel and the store
33
+ // can never disagree about what `null` means.
34
+ const { normalizeThemeName, themeChoiceLabel } = require('./theme-projection.js');
22
35
 
23
36
  const ROLE = Object.freeze({
24
37
  key: "accent",
@@ -172,11 +185,32 @@ const CUSTOMIZE_SWITCHES = [
172
185
  setting: "Notifications",
173
186
  description: "Replaces the Moshi hook with this plugin's own notification channel.",
174
187
  },
188
+ {
189
+ id: "theme-sync",
190
+ setting: "Theme sync",
191
+ description: "Keeps Herdr's palette in step with the theme that is active in Pi.",
192
+ // An unreadable store is repairable with one key press instead of blocking
193
+ // the row, so the note says what the action does rather than naming the
194
+ // managed rows the other switches repair.
195
+ unknownNote: "state unknown; Enter turns the sync on",
196
+ },
175
197
  ];
176
198
 
177
- // Two categories, one row each. `Herdr Sidebar` owns the managed agent rows the
178
- // plugin publishes and nothing else: the Moshi notification channel lives only
179
- // under `Moshi notifications`, so the sidebar switch can never toggle it.
199
+ // The theme value is deliberately NOT a toggle: its one row opens the host's
200
+ // theme list, so it carries its own row id (`select`) and the panel never paints
201
+ // it as On/Off. With the sync on the active Pi theme owns Herdr's palette (S4),
202
+ // so the row is painted dim, explains itself and is refused by the extension.
203
+ const CUSTOMIZE_THEME_ROW_ID = "select";
204
+ const CUSTOMIZE_THEME_ROW_LABEL = "Select…";
205
+ const CUSTOMIZE_THEME_ROW_DESCRIPTION =
206
+ "Applies one Gentle Shell theme to Herdr; available only while Theme sync is off.";
207
+ const CUSTOMIZE_THEME_DISABLED_NOTE = "Turn Theme sync off to pick a specific theme.";
208
+
209
+ // Three categories. `Herdr Sidebar` owns the managed agent rows the plugin
210
+ // publishes and nothing else: the Moshi notification channel lives only under
211
+ // `Moshi notifications`, so the sidebar switch can never toggle it. `Herdr
212
+ // Theme` follows Moshi for the same reason: it owns the palette Herdr draws,
213
+ // both the sync toggle and the pinned value.
180
214
  const CUSTOMIZE_CATEGORIES = [
181
215
  {
182
216
  id: "sidebar",
@@ -190,6 +224,12 @@ const CUSTOMIZE_CATEGORIES = [
190
224
  description: "The Moshi notification channel this plugin owns.",
191
225
  switches: ["moshi"],
192
226
  },
227
+ {
228
+ id: "theme",
229
+ title: "Herdr Theme",
230
+ description: "The palette Herdr draws, either following Pi or pinned to one theme.",
231
+ switches: ["theme-sync", "theme"],
232
+ },
193
233
  ];
194
234
 
195
235
  // One row per switch: it paints the stored value and carries the value Enter
@@ -206,7 +246,29 @@ function toggleRow(definition, active) {
206
246
  current,
207
247
  currentLabel: current === "on" ? "On" : current === "off" ? "Off" : "Unknown",
208
248
  otherLabel: current === "on" ? "Off" : "On",
209
- note: current === null ? "state unknown; Enter re-runs the managed rows" : undefined,
249
+ note: current === null
250
+ ? (definition.unknownNote ?? "state unknown; Enter re-runs the managed rows")
251
+ : undefined,
252
+ };
253
+ }
254
+
255
+ // The theme value row: the assigned name (or the inert `Off` label) on the
256
+ // stored pill and the list as the other one. `disabled` is exactly "the stored
257
+ // sync is on", and an unreadable store names neither a value nor a guess.
258
+ function themeRow(themeState) {
259
+ const readable = themeState.ok !== false;
260
+ const syncOn = readable && themeState.sync === true;
261
+ const assigned = readable ? normalizeThemeName(themeState.theme) : null;
262
+ return {
263
+ id: CUSTOMIZE_THEME_ROW_ID,
264
+ switchId: "theme",
265
+ setting: "Gentle Shell theme",
266
+ description: CUSTOMIZE_THEME_ROW_DESCRIPTION,
267
+ current: assigned,
268
+ currentLabel: themeChoiceLabel(assigned),
269
+ otherLabel: CUSTOMIZE_THEME_ROW_LABEL,
270
+ disabled: syncOn,
271
+ note: syncOn ? CUSTOMIZE_THEME_DISABLED_NOTE : undefined,
210
272
  };
211
273
  }
212
274
 
@@ -214,18 +276,27 @@ function toggleRow(definition, active) {
214
276
  // `unknown` (unresolvable plugin root or inconclusive `--check`) is never a
215
277
  // guessed value and never blocks the repair: the row stays selectable and a
216
278
  // note explains that On re-runs the managed rows. Notifications are always a
217
- // readable local flag.
218
- function customizePanelModel({ sidebar, moshi } = {}) {
279
+ // readable local flag. `theme` is the record `readThemeState()` returns: an
280
+ // `ok: false` read shows `Unknown` for the sync switch and no theme name.
281
+ function customizePanelModel({ sidebar, moshi, theme } = {}) {
219
282
  const stored = (value) => (value === "on" || value === "off" ? value : null);
220
- const current = { sidebar: stored(sidebar), moshi: stored(moshi) === "on" ? "on" : "off" };
283
+ const themeState = theme && typeof theme === "object"
284
+ ? theme
285
+ : { ok: false, sync: false, theme: null };
286
+ const themeSync = themeState.ok === false ? null : themeState.sync === true ? "on" : "off";
287
+ const current = {
288
+ sidebar: stored(sidebar),
289
+ moshi: stored(moshi) === "on" ? "on" : "off",
290
+ "theme-sync": themeSync,
291
+ };
292
+ const rowFor = (switchId) => (switchId === "theme"
293
+ ? themeRow(themeState)
294
+ : toggleRow(CUSTOMIZE_SWITCHES.find((entry) => entry.id === switchId), current[switchId]));
221
295
  return CUSTOMIZE_CATEGORIES.map((category) => ({
222
296
  id: category.id,
223
297
  title: category.title,
224
298
  description: category.description,
225
- rows: category.switches.map((switchId) => toggleRow(
226
- CUSTOMIZE_SWITCHES.find((entry) => entry.id === switchId),
227
- current[switchId],
228
- )),
299
+ rows: category.switches.map(rowFor),
229
300
  }));
230
301
  }
231
302
 
@@ -383,7 +454,9 @@ function customizeIsKeyRelease(helpers, data) {
383
454
  // the stored pill alone, so the narrow width keeps showing the real state.
384
455
  // `focused` marks the row Enter would apply (visible in either pane, so the
385
456
  // keyboard always shows its target) and `active` adds the band, which only the
386
- // pane that owns the focus paints.
457
+ // pane that owns the focus paints. A DISABLED row is painted in the dim role
458
+ // throughout and is never offered the band: the band is this card's promise
459
+ // that Enter applies the row, and the extension refuses this one.
387
460
  function customizeSettingLine(helpers, theme, row, nameWidth, size, focused, active) {
388
461
  const name = String(row.setting);
389
462
  const namePad = " ".repeat(Math.max(0, nameWidth - customizeMeasure(helpers, name)));
@@ -394,7 +467,9 @@ function customizeSettingLine(helpers, theme, row, nameWidth, size, focused, act
394
467
  const pair = `${stored} ${other}`;
395
468
  const showPair = customizeMeasure(helpers, `${lead}${pair}`) <= size;
396
469
  const body = showPair ? pair : stored;
397
- if (active && theme && typeof theme.bg === "function") {
470
+ const disabled = row.disabled === true;
471
+ const kind = (normal) => (disabled ? "label" : normal);
472
+ if (active && !disabled && theme && typeof theme.bg === "function") {
398
473
  try {
399
474
  const plain = customizeFit(helpers, `${lead}${body}`, Math.max(0, size));
400
475
  const band = theme.bg("selectedBg", plain + " ".repeat(Math.max(0, size - customizeMeasure(helpers, plain))));
@@ -404,11 +479,11 @@ function customizeSettingLine(helpers, theme, row, nameWidth, size, focused, act
404
479
  }
405
480
  }
406
481
  const segments = [
407
- { kind: focused ? "key" : "label", text: prefix },
408
- { kind: focused ? "value" : "description", text: `${name}${namePad} ` },
409
- { kind: row.current === null ? "error" : "accent", text: stored },
482
+ { kind: kind(focused ? "key" : "label"), text: prefix },
483
+ { kind: kind(focused ? "value" : "description"), text: `${name}${namePad} ` },
484
+ { kind: kind(row.current === null ? "error" : "accent"), text: stored },
410
485
  ];
411
- if (showPair) segments.push({ kind: "description", text: ` ${other}` });
486
+ if (showPair) segments.push({ kind: kind("description"), text: ` ${other}` });
412
487
  return customizeCompose(helpers, theme, segments, size);
413
488
  }
414
489