@narumitw/pi-starship 0.51.5 → 0.52.1

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.
@@ -2,96 +2,25 @@
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  BUILT_IN_EXAMPLE,
5
+ MODULE_DEFINITIONS,
5
6
  STARSHIP_SUBCOMMANDS,
6
7
  atomicRestoreConfigDocument,
7
8
  atomicSaveConfigDocument,
8
9
  completeStarshipArguments,
9
10
  inspectUnavailableModules,
11
+ loadStarshipConfig,
10
12
  removeConfigDocumentIfMatches,
11
13
  validateConfigDocument
12
- } from "./chunk-T2EFPJMB.js";
14
+ } from "./chunk-GS2UE7CF.js";
13
15
 
14
16
  // src/commands.ts
15
17
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
16
18
 
17
- // src/command-inspector.ts
18
- import { stripVTControlCharacters } from "node:util";
19
- function formatFooterExplanation(inspection) {
20
- if (!inspection) {
21
- return safeLines([
22
- "Footer inspection is unavailable until the TUI footer is ready.",
23
- "No collection work was started."
24
- ]);
25
- }
26
- if (inspection.showing.length === 0) {
27
- return safeLines([
28
- "No modules are currently showing.",
29
- "Open Modules to inspect empty, disabled, or unreachable modules."
30
- ]);
31
- }
32
- return safeLines(
33
- inspection.showing.flatMap((module, index) => [
34
- ...index > 0 ? [""] : [],
35
- module.name,
36
- ...previewLines(module.preview),
37
- module.description
38
- ])
39
- );
40
- }
41
- function previewLines(preview) {
42
- const lines = preview ? preview.split("\n") : ["(no text)"];
43
- return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
44
- }
45
- function safeLines(lines) {
46
- return lines.map(safeDisplayText).join("\n");
47
- }
48
- function safeDisplayText(value) {
49
- return Array.from(stripVTControlCharacters(value), (character) => {
50
- const codePoint = character.codePointAt(0) ?? 0;
51
- return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 ? "" : character;
52
- }).join("");
53
- }
54
-
55
- // src/command-preset-picker.ts
56
- import { runLiveChoice } from "@narumitw/pi-tui-kit";
57
- async function showPresetPicker(ctx, options) {
58
- const current = options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? "Custom configuration";
59
- const result = await runLiveChoice(ctx, {
60
- title: `Presets \xB7 current: ${current}`,
61
- items: options.presets.map((preset) => ({
62
- id: preset.id,
63
- label: preset.label,
64
- description: preset.id === options.activePresetId ? `Currently applied \xB7 ${preset.description}` : preset.description,
65
- details: [
66
- `Selected: ${preset.label} \xB7 ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`
67
- ],
68
- confirmationDisabled: preset.id === options.activePresetId,
69
- confirmationDisabledReason: "Already applied; press e to customize"
70
- })),
71
- currentItemId: options.activePresetId,
72
- initialItemId: options.initialPresetId ?? options.activePresetId,
73
- viewportSize: Math.min(options.presets.length, 10),
74
- hint: "back",
75
- navigationLabel: "live preview",
76
- confirmLabel: "apply",
77
- shortcuts: [{ id: "customize", keys: ["e", "shift+e"], label: "customize" }],
78
- onSelectionChange: ({ item }) => {
79
- const preset = options.presets.find((candidate) => candidate.id === item.id);
80
- if (preset) options.preview(preset);
81
- },
82
- signal: options.signal,
83
- isCurrent: options.isCurrent
84
- });
85
- if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
86
- if (result.kind === "shortcut") {
87
- return { kind: "customize", presetId: result.itemId };
88
- }
89
- if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
90
- return { kind: "close" };
91
- }
19
+ // src/command-configuration.ts
20
+ import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
92
21
 
93
22
  // src/command-preview.ts
94
- import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
23
+ import { stripVTControlCharacters } from "node:util";
95
24
  import { Key, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
96
25
  import { runCustomInteraction } from "@narumitw/pi-tui-kit";
97
26
  var RESERVED_HOST_ROWS = 3;
@@ -136,12 +65,12 @@ async function showPreviewActionMenu(ctx, title, body, items, signal, isCurrent
136
65
  const prefix = absoluteIndex === selectedIndex ? "\u2192 " : " ";
137
66
  return theme.fg(
138
67
  absoluteIndex === selectedIndex ? "accent" : "text",
139
- `${prefix}${safeDisplayText2(item.label)}`
68
+ `${prefix}${safeDisplayText(item.label)}`
140
69
  );
141
70
  });
142
71
  const position = layout.positionRows ? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))] : [];
143
72
  const lines = [
144
- ...layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText2(title)))] : [],
73
+ ...layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : [],
145
74
  ...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
146
75
  ...position,
147
76
  ...actionLines,
@@ -232,17 +161,76 @@ function bindingText(keybindings, binding, excluded) {
232
161
  if (key === "down") return "\u2193";
233
162
  if (key === "escape") return "esc";
234
163
  if (key === "return") return "enter";
235
- return safeDisplayText2(key);
164
+ return safeDisplayText(key);
236
165
  }).join("/");
237
166
  }
238
- function safeDisplayText2(value) {
239
- return Array.from(stripVTControlCharacters2(value), (character) => {
167
+ function safeDisplayText(value) {
168
+ return Array.from(stripVTControlCharacters(value), (character) => {
240
169
  const codePoint = character.codePointAt(0) ?? 0;
241
170
  const control = codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
242
171
  return control ? "" : character;
243
172
  }).join("");
244
173
  }
245
174
 
175
+ // src/effective-config.ts
176
+ import { stringify } from "smol-toml";
177
+ function projectEffectiveConfig(config) {
178
+ const projected = {
179
+ format: config.format
180
+ };
181
+ if (config.palette !== void 0) projected.palette = config.palette;
182
+ projected.palettes = Object.fromEntries(
183
+ sortedEntries(config.palettes).map(([name, colors]) => [name, sortedRecord(colors)])
184
+ );
185
+ for (const definition of MODULE_DEFINITIONS) {
186
+ const module = config.modules[definition.name];
187
+ const table = {
188
+ format: module.format,
189
+ symbol: module.symbol
190
+ };
191
+ if (definition.styleDefaults) {
192
+ for (const field of Object.keys(definition.styleDefaults)) {
193
+ table[field] = module.styles[field] ?? "";
194
+ }
195
+ } else if (!definition.displayDefaults) {
196
+ table.style = module.style;
197
+ }
198
+ if (definition.displayDefaults) {
199
+ table.display = module.display.map((entry) => ({ ...entry }));
200
+ }
201
+ table.disabled = module.disabled;
202
+ for (const key of Object.keys(definition.options ?? {})) {
203
+ table[key] = cloneOptionValue(module.options[key]);
204
+ }
205
+ if (definition.name === "extension_status") {
206
+ table.separator = config.extensionStatus.separator;
207
+ table.max_statuses = config.extensionStatus.maxStatuses;
208
+ table.icons = sortedRecord(config.extensionStatus.icons);
209
+ }
210
+ projected[definition.name] = table;
211
+ }
212
+ return projected;
213
+ }
214
+ function serializeEffectiveConfig(config) {
215
+ return stringify(projectEffectiveConfig(config));
216
+ }
217
+ function cloneOptionValue(value) {
218
+ if (value === void 0) throw new Error("Missing normalized module option");
219
+ if (Array.isArray(value)) return [...value];
220
+ if (typeof value === "object") {
221
+ return sortedRecord(value);
222
+ }
223
+ return value;
224
+ }
225
+ function sortedRecord(values) {
226
+ return Object.fromEntries(sortedEntries(values));
227
+ }
228
+ function sortedEntries(values) {
229
+ return Object.entries(values).sort(
230
+ ([left], [right]) => left < right ? -1 : left > right ? 1 : 0
231
+ );
232
+ }
233
+
246
234
  // src/presets/bracketed-segments.ts
247
235
  var BRACKETED_SEGMENTS_PRESET = String.raw`# Font-safe bracketed segments inspired by Starship.
248
236
  format = "$brand$model$thinking$directory$git_branch$git_status$activity$context$time"
@@ -1037,6 +1025,333 @@ function presetForDocument(rawDocument) {
1037
1025
  return STARSHIP_PRESETS.find((preset) => preset.rawDocument === rawDocument);
1038
1026
  }
1039
1027
 
1028
+ // src/command-configuration.ts
1029
+ var RELOAD_ACTIONS = {
1030
+ apply: "apply",
1031
+ cancel: "cancel"
1032
+ };
1033
+ function configurationPresentation(loaded) {
1034
+ const healthyMissing = isHealthyMissing(loaded);
1035
+ const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
1036
+ const activePreset = presetForDocument(loaded.rawDocument);
1037
+ const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
1038
+ return {
1039
+ state: healthyMissing ? "Built-in defaults" : savedBuiltIn ? "Saved built-in configuration" : activePreset ? `${activePreset.label} preset` : fallback ? "Built-in fallback" : "Custom configuration",
1040
+ source: healthyMissing ? "No settings file" : activePreset ? "Bundled preset" : loaded.source === "user" ? "User file" : "Built-in fallback",
1041
+ health: configurationHealth(loaded),
1042
+ restoreDisabled: healthyMissing || savedBuiltIn,
1043
+ restoreDescription: healthyMissing ? "Already using defaults \xB7 no file to replace" : savedBuiltIn ? "Built-in configuration already saved" : fallback ? "Preview before replacing invalid settings" : "Preview before replacing the document"
1044
+ };
1045
+ }
1046
+ function configurationMenuScreen(loaded) {
1047
+ const presentation = configurationPresentation(loaded);
1048
+ return {
1049
+ kind: "actions",
1050
+ title: "Configuration",
1051
+ lines: [`${presentation.state} \xB7 ${presentation.health}`],
1052
+ items: [
1053
+ {
1054
+ id: "configuration-overview",
1055
+ label: "Overview",
1056
+ description: "State, source, path, health, and warnings",
1057
+ to: "configuration-overview"
1058
+ },
1059
+ {
1060
+ id: "configuration-effective",
1061
+ label: "Effective configuration",
1062
+ description: "Normalized public TOML currently in use",
1063
+ to: "configuration-effective"
1064
+ },
1065
+ {
1066
+ id: "configuration-document",
1067
+ label: "Settings document",
1068
+ description: isHealthyMissing(loaded) ? "No settings file \xB7 built-in defaults are active" : "Exact loaded UTF-8 text \xB7 read-only",
1069
+ to: "configuration-document"
1070
+ },
1071
+ {
1072
+ id: "configuration-reload",
1073
+ label: "Reload from disk\u2026",
1074
+ description: "Validate and preview external changes",
1075
+ action: "configuration-reload"
1076
+ }
1077
+ ],
1078
+ hint: "back"
1079
+ };
1080
+ }
1081
+ function configurationOverviewScreen(loaded, settingsPath) {
1082
+ const presentation = configurationPresentation(loaded);
1083
+ return {
1084
+ kind: "detail",
1085
+ title: "Configuration overview",
1086
+ lines: [
1087
+ `State: ${presentation.state}`,
1088
+ `Source: ${presentation.source}`,
1089
+ `Path: ${sanitizeTerminalText(settingsPath)}`,
1090
+ ...diagnosticLines(loaded, true)
1091
+ ],
1092
+ hint: "back"
1093
+ };
1094
+ }
1095
+ function effectiveConfigurationScreen(loaded) {
1096
+ const presentation = configurationPresentation(loaded);
1097
+ return {
1098
+ kind: "review",
1099
+ title: "Effective configuration",
1100
+ lines: [
1101
+ `${presentation.state} \xB7 ${presentation.health}`,
1102
+ "Normalized public TOML; comments and unknown fields are intentionally excluded."
1103
+ ],
1104
+ content: serializeEffectiveConfig(loaded.config),
1105
+ format: { kind: "code", language: "toml" },
1106
+ viewportSize: "adaptive",
1107
+ hint: "back"
1108
+ };
1109
+ }
1110
+ function settingsDocumentScreen(loaded, settingsPath) {
1111
+ const path = sanitizeTerminalText(settingsPath);
1112
+ if (loaded.rawDocument !== void 0) {
1113
+ return {
1114
+ kind: "review",
1115
+ title: "Settings document",
1116
+ lines: ["Exact loaded UTF-8 text \xB7 display controls sanitized \xB7 read-only", `Path: ${path}`],
1117
+ content: loaded.rawDocument,
1118
+ format: { kind: "code", language: "toml" },
1119
+ viewportSize: "adaptive",
1120
+ hint: "back"
1121
+ };
1122
+ }
1123
+ return {
1124
+ kind: "detail",
1125
+ title: "Settings document",
1126
+ lines: [
1127
+ ...isHealthyMissing(loaded) ? [
1128
+ "No settings document exists.",
1129
+ "Built-in defaults are active; this read created no file."
1130
+ ] : ["The settings document could not be loaded.", ...diagnosticLines(loaded, false)],
1131
+ `Path: ${path}`
1132
+ ],
1133
+ hint: "back"
1134
+ };
1135
+ }
1136
+ async function reloadConfiguration(ctx, options, owner) {
1137
+ if (!isCurrentOwner(owner)) return "stay";
1138
+ const previous = options.getLoaded();
1139
+ const revision = options.getLoadedRevision?.();
1140
+ const candidate = readReloadCandidate(options);
1141
+ if (!candidate.ok) {
1142
+ ctx.ui.notify(`Footer reload was blocked: ${safeError(candidate.error)}`, "error");
1143
+ return "stay";
1144
+ }
1145
+ if (sameLoadedDocument(previous, candidate.loaded)) {
1146
+ ctx.ui.notify("The current disk configuration is already loaded.", "info");
1147
+ return "stay";
1148
+ }
1149
+ const selection = await showPreviewActionMenu(
1150
+ ctx,
1151
+ "Reload preview",
1152
+ (width) => reloadPreviewBody(ctx, options, candidate.loaded, width),
1153
+ [
1154
+ { value: RELOAD_ACTIONS.apply, label: "Apply reloaded configuration\u2026" },
1155
+ { value: RELOAD_ACTIONS.cancel, label: "Cancel" }
1156
+ ],
1157
+ owner.signal,
1158
+ owner.isCurrent
1159
+ );
1160
+ if (!isCurrentOwner(owner) || activeRevisionChanged(options, revision)) return "stay";
1161
+ if (selection?.kind === "closed") return "close";
1162
+ if (selectedReloadAction(selection) !== RELOAD_ACTIONS.apply) return "stay";
1163
+ const confirmed = await ctx.ui.confirm(
1164
+ "Apply configuration from disk?",
1165
+ candidate.loaded.rawDocument === void 0 ? "Use built-in defaults for this session? No settings file will be created." : "Apply the validated settings document to this session without changing its bytes?"
1166
+ );
1167
+ if (!isCurrentOwner(owner) || activeRevisionChanged(options, revision) || !confirmed) {
1168
+ return "stay";
1169
+ }
1170
+ const fresh = readReloadCandidate(options);
1171
+ if (!fresh.ok) {
1172
+ ctx.ui.notify(
1173
+ `Footer reload was blocked after confirmation: ${safeError(fresh.error)}. The previous footer remains active.`,
1174
+ "error"
1175
+ );
1176
+ return "stay";
1177
+ }
1178
+ if (!sameLoadedDocument(candidate.loaded, fresh.loaded)) {
1179
+ ctx.ui.notify(
1180
+ "The settings document changed after preview. The previous footer remains active; reload again to review the latest version.",
1181
+ "warning"
1182
+ );
1183
+ return "stay";
1184
+ }
1185
+ try {
1186
+ options.apply(fresh.loaded, ctx);
1187
+ } catch (error) {
1188
+ let rollbackError;
1189
+ try {
1190
+ options.apply(previous, ctx);
1191
+ } catch (rollback) {
1192
+ rollbackError = rollback;
1193
+ }
1194
+ ctx.ui.notify(
1195
+ rollbackError ? `Footer reload failed: ${safeError(error)}. Restoring the previous configuration also failed: ${safeError(rollbackError)}.` : `Footer reload failed: ${safeError(error)}. The previous configuration was restored.`,
1196
+ "error"
1197
+ );
1198
+ return "stay";
1199
+ }
1200
+ const warnings = fresh.loaded.diagnostics.length;
1201
+ ctx.ui.notify(
1202
+ warnings === 0 ? "Footer configuration reloaded and applied." : `Footer configuration reloaded and applied with ${warnings} warning${warnings === 1 ? "" : "s"}.`,
1203
+ "info"
1204
+ );
1205
+ return "applied";
1206
+ }
1207
+ function readReloadCandidate(options) {
1208
+ let loaded;
1209
+ try {
1210
+ loaded = (options.read ?? loadStarshipConfig)(options.settingsPath);
1211
+ } catch (error) {
1212
+ return { ok: false, error: formatError(error) };
1213
+ }
1214
+ const errors = loaded.diagnostics.filter((item) => item.severity === "error");
1215
+ if (errors.length > 0) {
1216
+ return { ok: false, error: errors.map((item) => item.message).join("; ") };
1217
+ }
1218
+ return { ok: true, loaded };
1219
+ }
1220
+ function reloadPreviewBody(ctx, options, loaded, width) {
1221
+ const presentation = configurationPresentation(loaded);
1222
+ let preview;
1223
+ try {
1224
+ preview = options.renderPreview?.(loaded, width, ctx) ?? [
1225
+ "Live preview is unavailable until the footer is ready."
1226
+ ];
1227
+ } catch (error) {
1228
+ preview = [`Preview unavailable: ${safeError(formatError(error))}`];
1229
+ }
1230
+ return [
1231
+ `Candidate: ${presentation.state}`,
1232
+ `Source: ${presentation.source}`,
1233
+ `Path: ${sanitizeTerminalText(options.settingsPath)}`,
1234
+ loaded.rawDocument === void 0 ? "Applying uses built-in defaults and creates no settings file." : "Applying changes only the active session; the settings document bytes stay unchanged.",
1235
+ ...diagnosticLines(loaded, true),
1236
+ "",
1237
+ ...preview
1238
+ ];
1239
+ }
1240
+ function diagnosticLines(loaded, includeSummary) {
1241
+ const diagnostics = loaded.diagnostics.slice(0, 8).map(
1242
+ (item) => `${sanitizeTerminalText(item.path || "root")}: ${sanitizeTerminalText(item.message)}`
1243
+ );
1244
+ const remaining = loaded.diagnostics.length - diagnostics.length;
1245
+ return [
1246
+ ...includeSummary ? [`Health: ${configurationHealth(loaded)}`] : [],
1247
+ ...diagnostics.length > 0 ? diagnostics : ["No configuration warnings."],
1248
+ ...remaining > 0 ? [`${remaining} additional warnings not shown.`] : []
1249
+ ];
1250
+ }
1251
+ function configurationHealth(loaded) {
1252
+ const errors = loaded.diagnostics.filter((item) => item.severity === "error").length;
1253
+ if (errors > 0) return `${errors} error${errors === 1 ? "" : "s"}`;
1254
+ const warnings = loaded.diagnostics.length;
1255
+ return warnings === 0 ? "Healthy" : `${warnings} warning${warnings === 1 ? "" : "s"}`;
1256
+ }
1257
+ function isHealthyMissing(loaded) {
1258
+ return loaded.source === "built-in" && loaded.rawDocument === void 0 && loaded.diagnostics.length === 0;
1259
+ }
1260
+ function sameLoadedDocument(left, right) {
1261
+ return left.source === right.source && left.rawDocument === right.rawDocument && JSON.stringify(left.diagnostics) === JSON.stringify(right.diagnostics);
1262
+ }
1263
+ function activeRevisionChanged(options, revision) {
1264
+ return revision !== void 0 && options.getLoadedRevision?.() !== revision;
1265
+ }
1266
+ function isCurrentOwner(owner) {
1267
+ return !owner.signal.aborted && owner.isCurrent();
1268
+ }
1269
+ function selectedReloadAction(result) {
1270
+ return result?.kind === "selected" ? result.value : null;
1271
+ }
1272
+ function safeError(value) {
1273
+ return sanitizeTerminalText(typeof value === "string" ? value : formatError(value));
1274
+ }
1275
+ function formatError(error) {
1276
+ return error instanceof Error ? error.message : String(error);
1277
+ }
1278
+
1279
+ // src/command-inspector.ts
1280
+ import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
1281
+ function formatFooterExplanation(inspection) {
1282
+ if (!inspection) {
1283
+ return safeLines([
1284
+ "Footer inspection is unavailable until the TUI footer is ready.",
1285
+ "No collection work was started."
1286
+ ]);
1287
+ }
1288
+ if (inspection.showing.length === 0) {
1289
+ return safeLines([
1290
+ "No modules are currently showing.",
1291
+ "Open Modules to inspect empty, disabled, or unreachable modules."
1292
+ ]);
1293
+ }
1294
+ return safeLines(
1295
+ inspection.showing.flatMap((module, index) => [
1296
+ ...index > 0 ? [""] : [],
1297
+ module.name,
1298
+ ...previewLines(module.preview),
1299
+ module.description
1300
+ ])
1301
+ );
1302
+ }
1303
+ function previewLines(preview) {
1304
+ const lines = preview ? preview.split("\n") : ["(no text)"];
1305
+ return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
1306
+ }
1307
+ function safeLines(lines) {
1308
+ return lines.map(safeDisplayText2).join("\n");
1309
+ }
1310
+ function safeDisplayText2(value) {
1311
+ return Array.from(stripVTControlCharacters2(value), (character) => {
1312
+ const codePoint = character.codePointAt(0) ?? 0;
1313
+ return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 ? "" : character;
1314
+ }).join("");
1315
+ }
1316
+
1317
+ // src/command-preset-picker.ts
1318
+ import { runLiveChoice } from "@narumitw/pi-tui-kit";
1319
+ async function showPresetPicker(ctx, options) {
1320
+ const current = options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? "Custom configuration";
1321
+ const result = await runLiveChoice(ctx, {
1322
+ title: `Presets \xB7 current: ${current}`,
1323
+ items: options.presets.map((preset) => ({
1324
+ id: preset.id,
1325
+ label: preset.label,
1326
+ description: preset.id === options.activePresetId ? `Currently applied \xB7 ${preset.description}` : preset.description,
1327
+ details: [
1328
+ `Selected: ${preset.label} \xB7 ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`
1329
+ ],
1330
+ confirmationDisabled: preset.id === options.activePresetId,
1331
+ confirmationDisabledReason: "Already applied; press e to customize"
1332
+ })),
1333
+ currentItemId: options.activePresetId,
1334
+ initialItemId: options.initialPresetId ?? options.activePresetId,
1335
+ viewportSize: Math.min(options.presets.length, 10),
1336
+ hint: "back",
1337
+ navigationLabel: "live preview",
1338
+ confirmLabel: "apply",
1339
+ shortcuts: [{ id: "customize", keys: ["e", "shift+e"], label: "customize" }],
1340
+ onSelectionChange: ({ item }) => {
1341
+ const preset = options.presets.find((candidate) => candidate.id === item.id);
1342
+ if (preset) options.preview(preset);
1343
+ },
1344
+ signal: options.signal,
1345
+ isCurrent: options.isCurrent
1346
+ });
1347
+ if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
1348
+ if (result.kind === "shortcut") {
1349
+ return { kind: "customize", presetId: result.itemId };
1350
+ }
1351
+ if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
1352
+ return { kind: "close" };
1353
+ }
1354
+
1040
1355
  // src/commands.ts
1041
1356
  var MAIN_ACTIONS = {
1042
1357
  customize: "customize",
@@ -1186,21 +1501,10 @@ async function showMainMenu(ctx, options) {
1186
1501
  hint: "back"
1187
1502
  };
1188
1503
  },
1189
- configuration: () => {
1190
- const loaded = options.getLoaded();
1191
- const presentation = configurationPresentation(loaded);
1192
- return {
1193
- kind: "detail",
1194
- title: "Configuration",
1195
- lines: [
1196
- `State: ${presentation.state}`,
1197
- `Source: ${presentation.source}`,
1198
- `Path: ${safeText(options.settingsPath)}`,
1199
- ...diagnosticLines(loaded, true)
1200
- ],
1201
- hint: "back"
1202
- };
1203
- },
1504
+ configuration: () => configurationMenuScreen(options.getLoaded()),
1505
+ "configuration-overview": () => configurationOverviewScreen(options.getLoaded(), options.settingsPath),
1506
+ "configuration-effective": () => effectiveConfigurationScreen(options.getLoaded()),
1507
+ "configuration-document": () => settingsDocumentScreen(options.getLoaded(), options.settingsPath),
1204
1508
  help: () => ({
1205
1509
  kind: "detail",
1206
1510
  title: "pi-starship help",
@@ -1209,7 +1513,7 @@ async function showMainMenu(ctx, options) {
1209
1513
  "Presets live-previews the cursor in the footer; Enter confirms apply and e customizes first.",
1210
1514
  "Explain footer breaks down the modules currently showing from the existing snapshot.",
1211
1515
  "Modules searches every supported module and explains its current read-only state.",
1212
- "Configuration explains state, source, path, and warnings without changing the footer.",
1516
+ "Configuration separates overview, effective TOML, loaded settings text, and safe disk reload.",
1213
1517
  `Settings: ${safeText(options.settingsPath)}`,
1214
1518
  "Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship"
1215
1519
  ],
@@ -1225,6 +1529,10 @@ async function showMainMenu(ctx, options) {
1225
1529
  const result = await choosePreset(ctx, options, owner);
1226
1530
  return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
1227
1531
  },
1532
+ "configuration-reload": async () => {
1533
+ const result = await reloadConfiguration(ctx, options, owner);
1534
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
1535
+ },
1228
1536
  restore: async () => {
1229
1537
  const presentation = configurationPresentation(options.getLoaded());
1230
1538
  if (presentation.restoreDisabled) {
@@ -1248,7 +1556,7 @@ async function showMainMenu(ctx, options) {
1248
1556
  }
1249
1557
  async function editSettings(ctx, options) {
1250
1558
  const owner = workflowOwner(options);
1251
- if (!isCurrentOwner(owner)) return "cancel";
1559
+ if (!isCurrentOwner2(owner)) return "cancel";
1252
1560
  if (ctx.mode !== "tui") {
1253
1561
  if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
1254
1562
  return "cancel";
@@ -1256,17 +1564,17 @@ async function editSettings(ctx, options) {
1256
1564
  let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
1257
1565
  while (true) {
1258
1566
  const edited = await ctx.ui.editor("Customize footer \u2014 close to preview", draft);
1259
- if (!isCurrentOwner(owner) || edited === void 0) return "cancel";
1567
+ if (!isCurrentOwner2(owner) || edited === void 0) return "cancel";
1260
1568
  draft = edited;
1261
1569
  let validated;
1262
1570
  try {
1263
1571
  validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
1264
1572
  } catch (error) {
1265
- ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, "error");
1573
+ ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError2(error))}`, "error");
1266
1574
  const action = await showPreviewActionMenu(
1267
1575
  ctx,
1268
1576
  "Configuration needs attention",
1269
- () => [safeText(formatError(error)), "The current footer has not changed."],
1577
+ () => [safeText(formatError2(error)), "The current footer has not changed."],
1270
1578
  [
1271
1579
  { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
1272
1580
  { value: PREVIEW_ACTIONS.cancel, label: "Discard draft" }
@@ -1274,7 +1582,7 @@ async function editSettings(ctx, options) {
1274
1582
  owner.signal,
1275
1583
  owner.isCurrent
1276
1584
  );
1277
- if (!isCurrentOwner(owner)) return "cancel";
1585
+ if (!isCurrentOwner2(owner)) return "cancel";
1278
1586
  if (action?.kind === "closed") return "close";
1279
1587
  if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
1280
1588
  return "cancel";
@@ -1300,7 +1608,7 @@ async function choosePreset(ctx, options, owner) {
1300
1608
  options.preview?.(loaded, ctx);
1301
1609
  }
1302
1610
  });
1303
- if (!isCurrentOwner(owner)) {
1611
+ if (!isCurrentOwner2(owner)) {
1304
1612
  options.preview?.(void 0, ctx);
1305
1613
  return "cancel";
1306
1614
  }
@@ -1322,11 +1630,11 @@ async function choosePreset(ctx, options, owner) {
1322
1630
  }
1323
1631
  async function applyPreset(ctx, options, preset, start = "review") {
1324
1632
  const owner = workflowOwner(options);
1325
- if (!isCurrentOwner(owner)) return "cancel";
1633
+ if (!isCurrentOwner2(owner)) return "cancel";
1326
1634
  let draft = preset.rawDocument;
1327
1635
  if (start === "customize") {
1328
1636
  const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
1329
- if (!isCurrentOwner(owner) || edited === void 0) return "cancel";
1637
+ if (!isCurrentOwner2(owner) || edited === void 0) return "cancel";
1330
1638
  draft = edited;
1331
1639
  }
1332
1640
  while (true) {
@@ -1334,11 +1642,11 @@ async function applyPreset(ctx, options, preset, start = "review") {
1334
1642
  try {
1335
1643
  validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
1336
1644
  } catch (error) {
1337
- ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
1645
+ ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError2(error))}`, "error");
1338
1646
  const action = await showPreviewActionMenu(
1339
1647
  ctx,
1340
1648
  "Preset needs attention",
1341
- () => [safeText(formatError(error)), "The current footer has not changed."],
1649
+ () => [safeText(formatError2(error)), "The current footer has not changed."],
1342
1650
  [
1343
1651
  { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
1344
1652
  { value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" }
@@ -1346,11 +1654,11 @@ async function applyPreset(ctx, options, preset, start = "review") {
1346
1654
  owner.signal,
1347
1655
  owner.isCurrent
1348
1656
  );
1349
- if (!isCurrentOwner(owner)) return "cancel";
1657
+ if (!isCurrentOwner2(owner)) return "cancel";
1350
1658
  if (action?.kind === "closed") return "close";
1351
1659
  if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
1352
1660
  const edited2 = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
1353
- if (!isCurrentOwner(owner) || edited2 === void 0) return "cancel";
1661
+ if (!isCurrentOwner2(owner) || edited2 === void 0) return "cancel";
1354
1662
  draft = edited2;
1355
1663
  continue;
1356
1664
  }
@@ -1364,13 +1672,13 @@ async function applyPreset(ctx, options, preset, start = "review") {
1364
1672
  );
1365
1673
  if (result !== "edit") return result;
1366
1674
  const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
1367
- if (!isCurrentOwner(owner) || edited === void 0) return "cancel";
1675
+ if (!isCurrentOwner2(owner) || edited === void 0) return "cancel";
1368
1676
  draft = edited;
1369
1677
  }
1370
1678
  }
1371
1679
  async function restoreBuiltIn(ctx, options) {
1372
1680
  const owner = workflowOwner(options);
1373
- if (!isCurrentOwner(owner)) return "cancel";
1681
+ if (!isCurrentOwner2(owner)) return "cancel";
1374
1682
  const validated = (options.validate ?? validateConfigDocument)(
1375
1683
  options.settingsPath,
1376
1684
  BUILT_IN_EXAMPLE
@@ -1403,7 +1711,7 @@ async function reviewAndApply(ctx, options, validated, intent, owner, skipReview
1403
1711
  owner.signal,
1404
1712
  owner.isCurrent
1405
1713
  );
1406
- if (!isCurrentOwner(owner)) return "cancel";
1714
+ if (!isCurrentOwner2(owner)) return "cancel";
1407
1715
  if (selection?.kind === "closed") return "close";
1408
1716
  const selected = selectedPreviewAction(selection);
1409
1717
  if (selected === PREVIEW_ACTIONS.edit) return "edit";
@@ -1414,7 +1722,7 @@ async function reviewAndApply(ctx, options, validated, intent, owner, skipReview
1414
1722
  confirmationTitle(intent),
1415
1723
  confirmationMessage(options.settingsPath, intent)
1416
1724
  );
1417
- if (!isCurrentOwner(owner)) return "cancel";
1725
+ if (!isCurrentOwner2(owner)) return "cancel";
1418
1726
  if (!confirmed) {
1419
1727
  if (directAttempt) return "cancel";
1420
1728
  continue;
@@ -1426,7 +1734,7 @@ async function reviewAndApply(ctx, options, validated, intent, owner, skipReview
1426
1734
  saved = save(options.settingsPath, validated.rawDocument ?? BUILT_IN_EXAMPLE);
1427
1735
  } catch (error) {
1428
1736
  ctx.ui.notify(
1429
- `Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
1737
+ `Footer settings were not saved: ${safeText(formatError2(error))}. The previous footer remains active.`,
1430
1738
  "error"
1431
1739
  );
1432
1740
  if (directAttempt) return "cancel";
@@ -1437,7 +1745,7 @@ async function reviewAndApply(ctx, options, validated, intent, owner, skipReview
1437
1745
  } catch (error) {
1438
1746
  const rollbackError = restorePreviousConfiguration(ctx, options, previous, saved);
1439
1747
  ctx.ui.notify(
1440
- rollbackError ? `Footer settings could not be applied: ${safeText(formatError(error))}. Restoring the previous configuration also failed: ${safeText(formatError(rollbackError))}.` : `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
1748
+ rollbackError ? `Footer settings could not be applied: ${safeText(formatError2(error))}. Restoring the previous configuration also failed: ${safeText(formatError2(rollbackError))}.` : `Footer settings could not be applied: ${safeText(formatError2(error))}. The previous configuration was restored.`,
1441
1749
  "error"
1442
1750
  );
1443
1751
  if (directAttempt) return "cancel";
@@ -1502,7 +1810,7 @@ function workflowOwner(options) {
1502
1810
  const controller = new AbortController();
1503
1811
  return { signal: controller.signal, isCurrent: () => true };
1504
1812
  }
1505
- function isCurrentOwner(owner) {
1813
+ function isCurrentOwner2(owner) {
1506
1814
  return !owner.signal.aborted && owner.isCurrent();
1507
1815
  }
1508
1816
  function restorePreviousConfiguration(ctx, options, previous, saved) {
@@ -1554,7 +1862,7 @@ function previewBody(ctx, options, loaded, width) {
1554
1862
  "The draft is valid and can still be applied."
1555
1863
  ];
1556
1864
  } catch (error) {
1557
- lines = [`Preview unavailable: ${safeText(formatError(error))}`];
1865
+ lines = [`Preview unavailable: ${safeText(formatError2(error))}`];
1558
1866
  }
1559
1867
  const warning = loaded.diagnostics.length === 0 ? "Draft validation: Healthy" : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"}`;
1560
1868
  return [...lines, "", warning];
@@ -1562,34 +1870,6 @@ function previewBody(ctx, options, loaded, width) {
1562
1870
  function selectedPreviewAction(result) {
1563
1871
  return result?.kind === "selected" ? result.value : null;
1564
1872
  }
1565
- function diagnosticLines(loaded, includeSummary) {
1566
- const diagnostics = loaded.diagnostics.slice(0, 8).map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`);
1567
- const remaining = loaded.diagnostics.length - diagnostics.length;
1568
- return [
1569
- ...includeSummary ? [`Health: ${configurationHealth(loaded)}`] : [],
1570
- ...diagnostics.length > 0 ? diagnostics : ["No configuration warnings."],
1571
- ...remaining > 0 ? [`${remaining} additional warnings not shown.`] : []
1572
- ];
1573
- }
1574
- function configurationPresentation(loaded) {
1575
- const healthyMissing = loaded.source === "built-in" && loaded.rawDocument === void 0 && loaded.diagnostics.length === 0;
1576
- const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
1577
- const activePreset = presetForDocument(loaded.rawDocument);
1578
- const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
1579
- return {
1580
- state: healthyMissing ? "Built-in defaults" : savedBuiltIn ? "Saved built-in configuration" : activePreset ? `${activePreset.label} preset` : fallback ? "Built-in fallback" : "Custom configuration",
1581
- source: healthyMissing ? "No settings file" : activePreset ? "Bundled preset" : loaded.source === "user" ? "User file" : "Built-in fallback",
1582
- health: configurationHealth(loaded),
1583
- restoreDisabled: healthyMissing || savedBuiltIn,
1584
- restoreDescription: healthyMissing ? "Already using defaults \xB7 no file to replace" : savedBuiltIn ? "Built-in configuration already saved" : fallback ? "Preview before replacing invalid settings" : "Preview before replacing the document"
1585
- };
1586
- }
1587
- function configurationHealth(loaded) {
1588
- const errors = loaded.diagnostics.filter((item) => item.severity === "error").length;
1589
- if (errors > 0) return `${errors} error${errors === 1 ? "" : "s"}`;
1590
- const warnings = loaded.diagnostics.length;
1591
- return warnings === 0 ? "Healthy" : `${warnings} warning${warnings === 1 ? "" : "s"}`;
1592
- }
1593
1873
  function showStatus(ctx, options) {
1594
1874
  if (!canNotify(ctx)) return;
1595
1875
  const loaded = options.getLoaded();
@@ -1627,11 +1907,11 @@ function safeText(value) {
1627
1907
  return unsafe ? `\\u${codePoint.toString(16).padStart(4, "0")}` : character;
1628
1908
  }).join("");
1629
1909
  }
1630
- function formatError(error) {
1910
+ function formatError2(error) {
1631
1911
  return error instanceof Error ? error.message : String(error);
1632
1912
  }
1633
1913
  export {
1634
1914
  handleStarshipCommand,
1635
1915
  registerStarshipCommand
1636
1916
  };
1637
- //# sourceMappingURL=commands-BHK5VRA5.ts.map
1917
+ //# sourceMappingURL=commands-X3VM2UGT.ts.map