@narumitw/pi-starship 0.55.1 → 0.55.2

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.
Files changed (99) hide show
  1. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  2. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  3. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  4. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  5. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  6. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  7. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  8. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  9. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  10. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  11. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  12. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  13. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  14. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  15. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  16. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  17. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  18. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  19. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  20. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  21. package/dist/index.ts +20 -55
  22. package/dist/index.ts.map +2 -2
  23. package/package.json +60 -61
  24. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  25. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  26. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  27. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  28. package/src/command-configuration.ts +267 -286
  29. package/src/command-contract.ts +6 -6
  30. package/src/command-inspector.ts +27 -27
  31. package/src/command-preset-picker.ts +45 -50
  32. package/src/command-preview.ts +153 -166
  33. package/src/commands.ts +588 -618
  34. package/src/config.ts +580 -660
  35. package/src/effective-config.ts +46 -48
  36. package/src/format/formatter.ts +211 -227
  37. package/src/format/style.ts +205 -216
  38. package/src/modules/activity.ts +74 -74
  39. package/src/modules/brand.ts +9 -9
  40. package/src/modules/cache.ts +18 -18
  41. package/src/modules/catalog.ts +79 -83
  42. package/src/modules/cloud.ts +54 -54
  43. package/src/modules/context.ts +27 -27
  44. package/src/modules/cost.ts +23 -23
  45. package/src/modules/deployment.ts +45 -45
  46. package/src/modules/development.ts +80 -81
  47. package/src/modules/directory.ts +89 -113
  48. package/src/modules/display.ts +9 -9
  49. package/src/modules/execution.ts +62 -69
  50. package/src/modules/extension-status.ts +59 -64
  51. package/src/modules/fill.ts +10 -10
  52. package/src/modules/git/branch.ts +26 -26
  53. package/src/modules/git/commit.ts +21 -23
  54. package/src/modules/git/metrics.ts +22 -22
  55. package/src/modules/git/runtime.ts +299 -334
  56. package/src/modules/git/state.ts +17 -17
  57. package/src/modules/git/status.ts +77 -79
  58. package/src/modules/git/worktree.ts +10 -12
  59. package/src/modules/github-pr.ts +20 -20
  60. package/src/modules/helpers.ts +3 -3
  61. package/src/modules/index.ts +21 -21
  62. package/src/modules/inspection.ts +101 -108
  63. package/src/modules/languages.ts +52 -59
  64. package/src/modules/model.ts +57 -67
  65. package/src/modules/package.ts +12 -12
  66. package/src/modules/provider.ts +22 -24
  67. package/src/modules/render.ts +124 -140
  68. package/src/modules/thinking.ts +27 -26
  69. package/src/modules/time.ts +10 -13
  70. package/src/modules/tokens.ts +13 -13
  71. package/src/modules/truncation.ts +14 -17
  72. package/src/modules/turn.ts +9 -9
  73. package/src/modules/types.ts +125 -132
  74. package/src/modules/workspace-helpers.ts +4 -7
  75. package/src/pi-starship.ts +567 -603
  76. package/src/presets/catalog.ts +113 -113
  77. package/src/runtime/cloud.ts +122 -150
  78. package/src/runtime/command.ts +106 -108
  79. package/src/runtime/deployment.ts +150 -179
  80. package/src/runtime/development.ts +107 -124
  81. package/src/runtime/execution.ts +110 -124
  82. package/src/runtime/github-pr.ts +223 -252
  83. package/src/runtime/helpers.ts +186 -199
  84. package/src/runtime/languages.ts +149 -180
  85. package/src/runtime/package.ts +74 -87
  86. package/src/runtime/refresh-controller.ts +82 -86
  87. package/src/runtime/types.ts +38 -38
  88. package/src/runtime/workspace.ts +108 -116
  89. package/src/usage.ts +40 -40
  90. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  91. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  92. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  93. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  94. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  95. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  96. package/dist/chunks/development-BERD42HW.js.map +0 -7
  97. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  98. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  99. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/commands.ts CHANGED
@@ -1,726 +1,696 @@
1
1
  import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
2
  import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
3
  import {
4
- type ConfigurationCommandOptions,
5
- configurationMenuScreen,
6
- configurationOverviewScreen,
7
- configurationPresentation,
8
- effectiveConfigurationScreen,
9
- reloadConfiguration,
10
- settingsDocumentScreen,
11
- type WorkflowOwner,
4
+ type ConfigurationCommandOptions,
5
+ configurationMenuScreen,
6
+ configurationOverviewScreen,
7
+ configurationPresentation,
8
+ effectiveConfigurationScreen,
9
+ reloadConfiguration,
10
+ settingsDocumentScreen,
11
+ type WorkflowOwner,
12
12
  } from "./command-configuration.js";
13
13
  import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
14
14
  import { formatFooterExplanation } from "./command-inspector.js";
15
15
  import { showPresetPicker } from "./command-preset-picker.js";
16
16
  import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
17
17
  import {
18
- atomicRestoreConfigDocument,
19
- atomicSaveConfigDocument,
20
- BUILT_IN_EXAMPLE,
21
- type LoadedStarshipConfig,
22
- removeConfigDocumentIfMatches,
23
- validateConfigDocument,
18
+ atomicRestoreConfigDocument,
19
+ atomicSaveConfigDocument,
20
+ BUILT_IN_EXAMPLE,
21
+ type LoadedStarshipConfig,
22
+ removeConfigDocumentIfMatches,
23
+ validateConfigDocument,
24
24
  } from "./config.js";
25
25
  import { inspectUnavailableModules, type StatuslineInspection } from "./modules/inspection.js";
26
- import {
27
- getStarshipPreset,
28
- presetForDocument,
29
- STARSHIP_PRESETS,
30
- type StarshipPreset,
31
- } from "./presets/catalog.js";
26
+ import { getStarshipPreset, presetForDocument, STARSHIP_PRESETS, type StarshipPreset } from "./presets/catalog.js";
32
27
 
33
28
  const MAIN_ACTIONS = {
34
- customize: "customize",
35
- presets: "presets",
36
- explain: "explain",
37
- modules: "modules",
38
- configuration: "configuration",
39
- help: "help",
40
- restore: "restore",
29
+ customize: "customize",
30
+ presets: "presets",
31
+ explain: "explain",
32
+ modules: "modules",
33
+ configuration: "configuration",
34
+ help: "help",
35
+ restore: "restore",
41
36
  } as const;
42
37
 
43
38
  const PREVIEW_ACTIONS = {
44
- continue: "continue",
45
- edit: "edit",
46
- cancel: "cancel",
39
+ continue: "continue",
40
+ edit: "edit",
41
+ cancel: "cancel",
47
42
  } as const;
48
43
 
49
44
  export interface StarshipCommandOptions extends ConfigurationCommandOptions {
50
- getInspection?(): StatuslineInspection | undefined;
51
- preview?(loaded: LoadedStarshipConfig | undefined, ctx: ExtensionCommandContext): void;
52
- save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
53
- restore?: (settingsPath: string, rawDocument: string) => void;
54
- validate?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
55
- getMenuOwner?(): WorkflowOwner;
45
+ getInspection?(): StatuslineInspection | undefined;
46
+ preview?(loaded: LoadedStarshipConfig | undefined, ctx: ExtensionCommandContext): void;
47
+ save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
48
+ restore?: (settingsPath: string, rawDocument: string) => void;
49
+ validate?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
50
+ getMenuOwner?(): WorkflowOwner;
56
51
  }
57
52
 
58
- type ReviewIntent =
59
- | { kind: "customize" }
60
- | { kind: "restore" }
61
- | { kind: "preset"; preset: StarshipPreset };
53
+ type ReviewIntent = { kind: "customize" } | { kind: "restore" } | { kind: "preset"; preset: StarshipPreset };
62
54
 
63
55
  export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
64
- pi.registerCommand("starship", {
65
- description: "Customize or inspect the native Starship-style footer",
66
- getArgumentCompletions: completeStarshipArguments,
67
- handler: (args, ctx) => handleStarshipCommand(args, ctx, options),
68
- });
56
+ pi.registerCommand("starship", {
57
+ description: "Customize or inspect the native Starship-style footer",
58
+ getArgumentCompletions: completeStarshipArguments,
59
+ handler: (args, ctx) => handleStarshipCommand(args, ctx, options),
60
+ });
69
61
  }
70
62
 
71
63
  export async function handleStarshipCommand(
72
- args: string,
73
- ctx: ExtensionCommandContext,
74
- options: StarshipCommandOptions,
64
+ args: string,
65
+ ctx: ExtensionCommandContext,
66
+ options: StarshipCommandOptions,
75
67
  ) {
76
- const normalized = args.trim();
77
- if (!normalized) {
78
- if (ctx.mode === "tui") await showMainMenu(ctx, options);
79
- else showHelp(ctx, options.settingsPath);
80
- return;
81
- }
82
-
83
- const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
84
- const route = subcommand.toLowerCase();
85
- if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {
86
- if (canNotify(ctx)) {
87
- const reason =
88
- trailing.length > 0
89
- ? `Unexpected arguments for /starship ${safeText(route)}.`
90
- : `Unknown /starship subcommand: ${safeText(route)}.`;
91
- ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
92
- }
93
- return;
94
- }
95
- switch (route) {
96
- case "settings":
97
- await editSettings(ctx, options);
98
- return;
99
- case "status":
100
- showStatus(ctx, options);
101
- return;
102
- case "help":
103
- showHelp(ctx, options.settingsPath);
104
- return;
105
- }
68
+ const normalized = args.trim();
69
+ if (!normalized) {
70
+ if (ctx.mode === "tui") await showMainMenu(ctx, options);
71
+ else showHelp(ctx, options.settingsPath);
72
+ return;
73
+ }
74
+
75
+ const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
76
+ const route = subcommand.toLowerCase();
77
+ if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {
78
+ if (canNotify(ctx)) {
79
+ const reason =
80
+ trailing.length > 0
81
+ ? `Unexpected arguments for /starship ${safeText(route)}.`
82
+ : `Unknown /starship subcommand: ${safeText(route)}.`;
83
+ ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
84
+ }
85
+ return;
86
+ }
87
+ switch (route) {
88
+ case "settings":
89
+ await editSettings(ctx, options);
90
+ return;
91
+ case "status":
92
+ showStatus(ctx, options);
93
+ return;
94
+ case "help":
95
+ showHelp(ctx, options.settingsPath);
96
+ return;
97
+ }
106
98
  }
107
99
 
108
100
  async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
109
- const fallbackController = new AbortController();
110
- const owner = options.getMenuOwner?.() ?? {
111
- signal: fallbackController.signal,
112
- isCurrent: () => !fallbackController.signal.aborted,
113
- };
114
- type Screen =
115
- | "main"
116
- | "explain"
117
- | "modules"
118
- | "configuration"
119
- | "configuration-overview"
120
- | "configuration-effective"
121
- | "configuration-document"
122
- | "help";
123
- type Action = "customize" | "presets" | "configuration-reload" | "restore";
124
- const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
125
- start: "main",
126
- screens: {
127
- main: () => {
128
- const loaded = options.getLoaded();
129
- const presentation = configurationPresentation(loaded);
130
- return {
131
- kind: "actions",
132
- title: "pi-starship",
133
- lines: [`${presentation.state} · ${presentation.health}`],
134
- items: [
135
- {
136
- id: MAIN_ACTIONS.customize,
137
- label: "Customize footer",
138
- description: `${presentation.state} · preview before applying`,
139
- action: "customize",
140
- },
141
- {
142
- id: MAIN_ACTIONS.presets,
143
- label: "Presets",
144
- description: "Browse and live-preview bundled footer starting points",
145
- action: "presets",
146
- },
147
- {
148
- id: MAIN_ACTIONS.explain,
149
- label: "Explain footer",
150
- description: "Why each visible module appears",
151
- to: "explain",
152
- },
153
- {
154
- id: MAIN_ACTIONS.modules,
155
- label: "Modules",
156
- description: "Browse supported modules and current states",
157
- to: "modules",
158
- },
159
- {
160
- id: MAIN_ACTIONS.configuration,
161
- label: "Configuration",
162
- description: presentation.health,
163
- to: "configuration",
164
- },
165
- {
166
- id: MAIN_ACTIONS.help,
167
- label: "Help",
168
- description: "Formats, modules, and commands",
169
- to: "help",
170
- },
171
- {
172
- id: MAIN_ACTIONS.restore,
173
- label: "Restore built-in…",
174
- description: presentation.restoreDescription,
175
- disabled: presentation.restoreDisabled,
176
- action: "restore",
177
- },
178
- ],
179
- hint: "close",
180
- };
181
- },
182
- explain: () => ({
183
- kind: "review",
184
- title: "Explain footer",
185
- content: formatFooterExplanation(options.getInspection?.()),
186
- format: { kind: "text" },
187
- viewportSize: "adaptive",
188
- hint: "back",
189
- }),
190
- modules: () => {
191
- const inspection =
192
- options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
193
- return {
194
- kind: "browse",
195
- title: "Modules",
196
- items: inspection.modules.map((module) => ({
197
- id: module.name,
198
- label: module.name,
199
- statusText: module.state,
200
- description: module.description,
201
- searchText: [...module.variables, ...module.styleFields, ...module.displayRules].join(
202
- " ",
203
- ),
204
- details: [
205
- `Root: ${module.rootReferenced ? "Referenced" : "Not referenced"}`,
206
- `Reachable: ${module.reachable ? "Yes" : "No"}`,
207
- ...modulePreviewDetails(module.preview),
208
- `Reason: ${module.reason}`,
209
- `Variables: ${module.variables.join(", ") || "none"}`,
210
- `Style fields: ${module.styleFields.join(", ") || "none"}`,
211
- `Display rules: ${module.displayRules.join(" · ") || "none"}`,
212
- ],
213
- })),
214
- viewportSize: "adaptive",
215
- hint: "back",
216
- };
217
- },
218
- configuration: () => configurationMenuScreen(options.getLoaded()),
219
- "configuration-overview": () =>
220
- configurationOverviewScreen(options.getLoaded(), options.settingsPath),
221
- "configuration-effective": () => effectiveConfigurationScreen(options.getLoaded()),
222
- "configuration-document": () =>
223
- settingsDocumentScreen(options.getLoaded(), options.settingsPath),
224
- help: () => ({
225
- kind: "detail",
226
- title: "pi-starship help",
227
- lines: [
228
- "Customize footer opens the TOML editor, then previews and confirms before saving.",
229
- "Presets live-previews the cursor in the footer; Enter confirms apply and e customizes first.",
230
- "Explain footer breaks down the modules currently showing from the existing snapshot.",
231
- "Modules searches every supported module and explains its current read-only state.",
232
- "Configuration separates overview, effective TOML, loaded settings text, and safe disk reload.",
233
- `Settings: ${safeText(options.settingsPath)}`,
234
- "Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
235
- ],
236
- hint: "back",
237
- }),
238
- },
239
- actions: {
240
- customize: async () => {
241
- const result = await editSettings(ctx, options);
242
- return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
243
- },
244
- presets: async () => {
245
- const result = await choosePreset(ctx, options, owner);
246
- return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
247
- },
248
- "configuration-reload": async () => {
249
- const result = await reloadConfiguration(ctx, options, owner);
250
- return result === "close" ? { kind: "close" } : { kind: "stay" };
251
- },
252
- restore: async () => {
253
- const presentation = configurationPresentation(options.getLoaded());
254
- if (presentation.restoreDisabled) {
255
- ctx.ui.notify(presentation.restoreDescription, "info");
256
- return { kind: "stay" };
257
- }
258
- const result = await restoreBuiltIn(ctx, options);
259
- return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
260
- },
261
- },
262
- });
263
- try {
264
- await runMenu(ctx, menu, {
265
- getState: () => undefined,
266
- signal: owner.signal,
267
- isCurrent: owner.isCurrent,
268
- });
269
- } finally {
270
- fallbackController.abort(new DOMException("Starship menu closed", "AbortError"));
271
- }
101
+ const fallbackController = new AbortController();
102
+ const owner = options.getMenuOwner?.() ?? {
103
+ signal: fallbackController.signal,
104
+ isCurrent: () => !fallbackController.signal.aborted,
105
+ };
106
+ type Screen =
107
+ | "main"
108
+ | "explain"
109
+ | "modules"
110
+ | "configuration"
111
+ | "configuration-overview"
112
+ | "configuration-effective"
113
+ | "configuration-document"
114
+ | "help";
115
+ type Action = "customize" | "presets" | "configuration-reload" | "restore";
116
+ const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
117
+ start: "main",
118
+ screens: {
119
+ main: () => {
120
+ const loaded = options.getLoaded();
121
+ const presentation = configurationPresentation(loaded);
122
+ return {
123
+ kind: "actions",
124
+ title: "pi-starship",
125
+ lines: [`${presentation.state} · ${presentation.health}`],
126
+ items: [
127
+ {
128
+ id: MAIN_ACTIONS.customize,
129
+ label: "Customize footer",
130
+ description: `${presentation.state} · preview before applying`,
131
+ action: "customize",
132
+ },
133
+ {
134
+ id: MAIN_ACTIONS.presets,
135
+ label: "Presets",
136
+ description: "Browse and live-preview bundled footer starting points",
137
+ action: "presets",
138
+ },
139
+ {
140
+ id: MAIN_ACTIONS.explain,
141
+ label: "Explain footer",
142
+ description: "Why each visible module appears",
143
+ to: "explain",
144
+ },
145
+ {
146
+ id: MAIN_ACTIONS.modules,
147
+ label: "Modules",
148
+ description: "Browse supported modules and current states",
149
+ to: "modules",
150
+ },
151
+ {
152
+ id: MAIN_ACTIONS.configuration,
153
+ label: "Configuration",
154
+ description: presentation.health,
155
+ to: "configuration",
156
+ },
157
+ {
158
+ id: MAIN_ACTIONS.help,
159
+ label: "Help",
160
+ description: "Formats, modules, and commands",
161
+ to: "help",
162
+ },
163
+ {
164
+ id: MAIN_ACTIONS.restore,
165
+ label: "Restore built-in…",
166
+ description: presentation.restoreDescription,
167
+ disabled: presentation.restoreDisabled,
168
+ action: "restore",
169
+ },
170
+ ],
171
+ hint: "close",
172
+ };
173
+ },
174
+ explain: () => ({
175
+ kind: "review",
176
+ title: "Explain footer",
177
+ content: formatFooterExplanation(options.getInspection?.()),
178
+ format: { kind: "text" },
179
+ viewportSize: "adaptive",
180
+ hint: "back",
181
+ }),
182
+ modules: () => {
183
+ const inspection = options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
184
+ return {
185
+ kind: "browse",
186
+ title: "Modules",
187
+ items: inspection.modules.map((module) => ({
188
+ id: module.name,
189
+ label: module.name,
190
+ statusText: module.state,
191
+ description: module.description,
192
+ searchText: [...module.variables, ...module.styleFields, ...module.displayRules].join(" "),
193
+ details: [
194
+ `Root: ${module.rootReferenced ? "Referenced" : "Not referenced"}`,
195
+ `Reachable: ${module.reachable ? "Yes" : "No"}`,
196
+ ...modulePreviewDetails(module.preview),
197
+ `Reason: ${module.reason}`,
198
+ `Variables: ${module.variables.join(", ") || "none"}`,
199
+ `Style fields: ${module.styleFields.join(", ") || "none"}`,
200
+ `Display rules: ${module.displayRules.join(" · ") || "none"}`,
201
+ ],
202
+ })),
203
+ viewportSize: "adaptive",
204
+ hint: "back",
205
+ };
206
+ },
207
+ configuration: () => configurationMenuScreen(options.getLoaded()),
208
+ "configuration-overview": () => configurationOverviewScreen(options.getLoaded(), options.settingsPath),
209
+ "configuration-effective": () => effectiveConfigurationScreen(options.getLoaded()),
210
+ "configuration-document": () => settingsDocumentScreen(options.getLoaded(), options.settingsPath),
211
+ help: () => ({
212
+ kind: "detail",
213
+ title: "pi-starship help",
214
+ lines: [
215
+ "Customize footer opens the TOML editor, then previews and confirms before saving.",
216
+ "Presets live-previews the cursor in the footer; Enter confirms apply and e customizes first.",
217
+ "Explain footer breaks down the modules currently showing from the existing snapshot.",
218
+ "Modules searches every supported module and explains its current read-only state.",
219
+ "Configuration separates overview, effective TOML, loaded settings text, and safe disk reload.",
220
+ `Settings: ${safeText(options.settingsPath)}`,
221
+ "Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
222
+ ],
223
+ hint: "back",
224
+ }),
225
+ },
226
+ actions: {
227
+ customize: async () => {
228
+ const result = await editSettings(ctx, options);
229
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
230
+ },
231
+ presets: async () => {
232
+ const result = await choosePreset(ctx, options, owner);
233
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
234
+ },
235
+ "configuration-reload": async () => {
236
+ const result = await reloadConfiguration(ctx, options, owner);
237
+ return result === "close" ? { kind: "close" } : { kind: "stay" };
238
+ },
239
+ restore: async () => {
240
+ const presentation = configurationPresentation(options.getLoaded());
241
+ if (presentation.restoreDisabled) {
242
+ ctx.ui.notify(presentation.restoreDescription, "info");
243
+ return { kind: "stay" };
244
+ }
245
+ const result = await restoreBuiltIn(ctx, options);
246
+ return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
247
+ },
248
+ },
249
+ });
250
+ try {
251
+ await runMenu(ctx, menu, {
252
+ getState: () => undefined,
253
+ signal: owner.signal,
254
+ isCurrent: owner.isCurrent,
255
+ });
256
+ } finally {
257
+ fallbackController.abort(new DOMException("Starship menu closed", "AbortError"));
258
+ }
272
259
  }
273
260
 
274
261
  async function editSettings(
275
- ctx: ExtensionCommandContext,
276
- options: StarshipCommandOptions,
262
+ ctx: ExtensionCommandContext,
263
+ options: StarshipCommandOptions,
277
264
  ): Promise<"applied" | "cancel" | "close"> {
278
- const owner = workflowOwner(options);
279
- if (!isCurrentOwner(owner)) return "cancel";
280
- if (ctx.mode !== "tui") {
281
- if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
282
- return "cancel";
283
- }
284
- let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
285
- while (true) {
286
- const edited = await ctx.ui.editor("Customize footer — close to preview", draft);
287
- if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
288
- draft = edited;
289
- let validated: LoadedStarshipConfig;
290
- try {
291
- validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
292
- } catch (error) {
293
- ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, "error");
294
- const action = await showPreviewActionMenu(
295
- ctx,
296
- "Configuration needs attention",
297
- () => [safeText(formatError(error)), "The current footer has not changed."],
298
- [
299
- { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
300
- { value: PREVIEW_ACTIONS.cancel, label: "Discard draft" },
301
- ],
302
- owner.signal,
303
- owner.isCurrent,
304
- );
305
- if (!isCurrentOwner(owner)) return "cancel";
306
- if (action?.kind === "closed") return "close";
307
- if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
308
- return "cancel";
309
- }
310
-
311
- const result = await reviewAndApply(ctx, options, validated, { kind: "customize" }, owner);
312
- if (result === "edit") continue;
313
- return result;
314
- }
265
+ const owner = workflowOwner(options);
266
+ if (!isCurrentOwner(owner)) return "cancel";
267
+ if (ctx.mode !== "tui") {
268
+ if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
269
+ return "cancel";
270
+ }
271
+ let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
272
+ while (true) {
273
+ const edited = await ctx.ui.editor("Customize footer — close to preview", draft);
274
+ if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
275
+ draft = edited;
276
+ let validated: LoadedStarshipConfig;
277
+ try {
278
+ validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
279
+ } catch (error) {
280
+ ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, "error");
281
+ const action = await showPreviewActionMenu(
282
+ ctx,
283
+ "Configuration needs attention",
284
+ () => [safeText(formatError(error)), "The current footer has not changed."],
285
+ [
286
+ { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
287
+ { value: PREVIEW_ACTIONS.cancel, label: "Discard draft" },
288
+ ],
289
+ owner.signal,
290
+ owner.isCurrent,
291
+ );
292
+ if (!isCurrentOwner(owner)) return "cancel";
293
+ if (action?.kind === "closed") return "close";
294
+ if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
295
+ return "cancel";
296
+ }
297
+
298
+ const result = await reviewAndApply(ctx, options, validated, { kind: "customize" }, owner);
299
+ if (result === "edit") continue;
300
+ return result;
301
+ }
315
302
  }
316
303
 
317
304
  async function choosePreset(
318
- ctx: ExtensionCommandContext,
319
- options: StarshipCommandOptions,
320
- owner: WorkflowOwner,
305
+ ctx: ExtensionCommandContext,
306
+ options: StarshipCommandOptions,
307
+ owner: WorkflowOwner,
321
308
  ): Promise<"applied" | "cancel" | "close"> {
322
- const activePreset = presetForDocument(options.getLoaded().rawDocument);
323
- const selection = await showPresetPicker(ctx, {
324
- presets: STARSHIP_PRESETS,
325
- activePresetId: activePreset?.id,
326
- initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,
327
- signal: owner.signal,
328
- isCurrent: owner.isCurrent,
329
- preview(preset) {
330
- const loaded = (options.validate ?? validateConfigDocument)(
331
- options.settingsPath,
332
- preset.rawDocument,
333
- );
334
- options.preview?.(loaded, ctx);
335
- },
336
- });
337
- if (!isCurrentOwner(owner)) {
338
- options.preview?.(undefined, ctx);
339
- return "cancel";
340
- }
341
- if (selection.kind === "back" || selection.kind === "close") {
342
- options.preview?.(undefined, ctx);
343
- return selection.kind === "close" ? "close" : "cancel";
344
- }
345
-
346
- const preset = getStarshipPreset(selection.presetId);
347
- try {
348
- return await applyPreset(
349
- ctx,
350
- options,
351
- preset,
352
- selection.kind === "customize" ? "customize" : "confirm",
353
- );
354
- } finally {
355
- options.preview?.(undefined, ctx);
356
- }
309
+ const activePreset = presetForDocument(options.getLoaded().rawDocument);
310
+ const selection = await showPresetPicker(ctx, {
311
+ presets: STARSHIP_PRESETS,
312
+ activePresetId: activePreset?.id,
313
+ initialPresetId: activePreset?.id ?? STARSHIP_PRESETS[0]?.id,
314
+ signal: owner.signal,
315
+ isCurrent: owner.isCurrent,
316
+ preview(preset) {
317
+ const loaded = (options.validate ?? validateConfigDocument)(options.settingsPath, preset.rawDocument);
318
+ options.preview?.(loaded, ctx);
319
+ },
320
+ });
321
+ if (!isCurrentOwner(owner)) {
322
+ options.preview?.(undefined, ctx);
323
+ return "cancel";
324
+ }
325
+ if (selection.kind === "back" || selection.kind === "close") {
326
+ options.preview?.(undefined, ctx);
327
+ return selection.kind === "close" ? "close" : "cancel";
328
+ }
329
+
330
+ const preset = getStarshipPreset(selection.presetId);
331
+ try {
332
+ return await applyPreset(ctx, options, preset, selection.kind === "customize" ? "customize" : "confirm");
333
+ } finally {
334
+ options.preview?.(undefined, ctx);
335
+ }
357
336
  }
358
337
 
359
338
  async function applyPreset(
360
- ctx: ExtensionCommandContext,
361
- options: StarshipCommandOptions,
362
- preset: StarshipPreset,
363
- start: "review" | "confirm" | "customize" = "review",
339
+ ctx: ExtensionCommandContext,
340
+ options: StarshipCommandOptions,
341
+ preset: StarshipPreset,
342
+ start: "review" | "confirm" | "customize" = "review",
364
343
  ): Promise<"applied" | "cancel" | "close"> {
365
- const owner = workflowOwner(options);
366
- if (!isCurrentOwner(owner)) return "cancel";
367
- let draft = preset.rawDocument;
368
- if (start === "customize") {
369
- const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
370
- if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
371
- draft = edited;
372
- }
373
- while (true) {
374
- let validated: LoadedStarshipConfig;
375
- try {
376
- validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
377
- } catch (error) {
378
- ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
379
- const action = await showPreviewActionMenu(
380
- ctx,
381
- "Preset needs attention",
382
- () => [safeText(formatError(error)), "The current footer has not changed."],
383
- [
384
- { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
385
- { value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" },
386
- ],
387
- owner.signal,
388
- owner.isCurrent,
389
- );
390
- if (!isCurrentOwner(owner)) return "cancel";
391
- if (action?.kind === "closed") return "close";
392
- if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
393
- const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
394
- if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
395
- draft = edited;
396
- continue;
397
- }
398
-
399
- const result = await reviewAndApply(
400
- ctx,
401
- options,
402
- validated,
403
- { kind: "preset", preset },
404
- owner,
405
- start === "confirm",
406
- );
407
- if (result !== "edit") return result;
408
- const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
409
- if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
410
- draft = edited;
411
- }
344
+ const owner = workflowOwner(options);
345
+ if (!isCurrentOwner(owner)) return "cancel";
346
+ let draft = preset.rawDocument;
347
+ if (start === "customize") {
348
+ const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
349
+ if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
350
+ draft = edited;
351
+ }
352
+ while (true) {
353
+ let validated: LoadedStarshipConfig;
354
+ try {
355
+ validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
356
+ } catch (error) {
357
+ ctx.ui.notify(`Preset draft is invalid: ${safeText(formatError(error))}`, "error");
358
+ const action = await showPreviewActionMenu(
359
+ ctx,
360
+ "Preset needs attention",
361
+ () => [safeText(formatError(error)), "The current footer has not changed."],
362
+ [
363
+ { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
364
+ { value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" },
365
+ ],
366
+ owner.signal,
367
+ owner.isCurrent,
368
+ );
369
+ if (!isCurrentOwner(owner)) return "cancel";
370
+ if (action?.kind === "closed") return "close";
371
+ if (selectedPreviewAction(action) !== PREVIEW_ACTIONS.edit) return "cancel";
372
+ const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
373
+ if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
374
+ draft = edited;
375
+ continue;
376
+ }
377
+
378
+ const result = await reviewAndApply(
379
+ ctx,
380
+ options,
381
+ validated,
382
+ { kind: "preset", preset },
383
+ owner,
384
+ start === "confirm",
385
+ );
386
+ if (result !== "edit") return result;
387
+ const edited = await ctx.ui.editor(`Customize ${preset.label} preset`, draft);
388
+ if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
389
+ draft = edited;
390
+ }
412
391
  }
413
392
 
414
393
  async function restoreBuiltIn(
415
- ctx: ExtensionCommandContext,
416
- options: StarshipCommandOptions,
394
+ ctx: ExtensionCommandContext,
395
+ options: StarshipCommandOptions,
417
396
  ): Promise<"applied" | "cancel" | "close"> {
418
- const owner = workflowOwner(options);
419
- if (!isCurrentOwner(owner)) return "cancel";
420
- const validated = (options.validate ?? validateConfigDocument)(
421
- options.settingsPath,
422
- BUILT_IN_EXAMPLE,
423
- );
424
- const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
425
- return result === "edit" ? "cancel" : result;
397
+ const owner = workflowOwner(options);
398
+ if (!isCurrentOwner(owner)) return "cancel";
399
+ const validated = (options.validate ?? validateConfigDocument)(options.settingsPath, BUILT_IN_EXAMPLE);
400
+ const result = await reviewAndApply(ctx, options, validated, { kind: "restore" }, owner);
401
+ return result === "edit" ? "cancel" : result;
426
402
  }
427
403
 
428
404
  async function reviewAndApply(
429
- ctx: ExtensionCommandContext,
430
- options: StarshipCommandOptions,
431
- validated: LoadedStarshipConfig,
432
- intent: ReviewIntent,
433
- owner: WorkflowOwner,
434
- skipReview = false,
405
+ ctx: ExtensionCommandContext,
406
+ options: StarshipCommandOptions,
407
+ validated: LoadedStarshipConfig,
408
+ intent: ReviewIntent,
409
+ owner: WorkflowOwner,
410
+ skipReview = false,
435
411
  ): Promise<"applied" | "edit" | "cancel" | "close"> {
436
- let reviewRequired = !skipReview;
437
- while (true) {
438
- const directAttempt = !reviewRequired;
439
- if (reviewRequired) {
440
- const selection = await showPreviewActionMenu(
441
- ctx,
442
- reviewTitle(intent),
443
- (width) => reviewPreviewBody(ctx, options, validated, width, intent),
444
- [
445
- { value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },
446
- ...(intent.kind === "restore"
447
- ? []
448
- : [
449
- {
450
- value: PREVIEW_ACTIONS.edit,
451
- label:
452
- intent.kind === "preset" ? "Customize before applying" : "Continue editing",
453
- },
454
- ]),
455
- {
456
- value: PREVIEW_ACTIONS.cancel,
457
- label:
458
- intent.kind === "restore"
459
- ? "Cancel"
460
- : intent.kind === "preset"
461
- ? "Choose another preset"
462
- : "Discard draft",
463
- },
464
- ],
465
- owner.signal,
466
- owner.isCurrent,
467
- );
468
- if (!isCurrentOwner(owner)) return "cancel";
469
- if (selection?.kind === "closed") return "close";
470
- const selected = selectedPreviewAction(selection);
471
- if (selected === PREVIEW_ACTIONS.edit) return "edit";
472
- if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
473
- }
474
- reviewRequired = true;
475
-
476
- const confirmed = await ctx.ui.confirm(
477
- confirmationTitle(intent),
478
- confirmationMessage(options.settingsPath, intent),
479
- );
480
- if (!isCurrentOwner(owner)) return "cancel";
481
- if (!confirmed) {
482
- if (directAttempt) return "cancel";
483
- continue;
484
- }
485
-
486
- const save = options.save ?? atomicSaveConfigDocument;
487
- const previous = options.getLoaded();
488
- let saved: LoadedStarshipConfig;
489
- try {
490
- saved = save(options.settingsPath, validated.rawDocument ?? BUILT_IN_EXAMPLE);
491
- } catch (error) {
492
- ctx.ui.notify(
493
- `Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
494
- "error",
495
- );
496
- if (directAttempt) return "cancel";
497
- continue;
498
- }
499
-
500
- try {
501
- options.apply(saved, ctx);
502
- } catch (error) {
503
- const rollbackError = restorePreviousConfiguration(ctx, options, previous, saved);
504
- ctx.ui.notify(
505
- rollbackError
506
- ? `Footer settings could not be applied: ${safeText(formatError(error))}. Restoring the previous configuration also failed: ${safeText(formatError(rollbackError))}.`
507
- : `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
508
- "error",
509
- );
510
- if (directAttempt) return "cancel";
511
- continue;
512
- }
513
-
514
- const warningSuffix =
515
- saved.diagnostics.length > 0
516
- ? ` (${saved.diagnostics.length} warning${saved.diagnostics.length === 1 ? "" : "s"})`
517
- : "";
518
- ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, "info");
519
- return "applied";
520
- }
412
+ let reviewRequired = !skipReview;
413
+ while (true) {
414
+ const directAttempt = !reviewRequired;
415
+ if (reviewRequired) {
416
+ const selection = await showPreviewActionMenu(
417
+ ctx,
418
+ reviewTitle(intent),
419
+ (width) => reviewPreviewBody(ctx, options, validated, width, intent),
420
+ [
421
+ { value: PREVIEW_ACTIONS.continue, label: continueLabel(intent) },
422
+ ...(intent.kind === "restore"
423
+ ? []
424
+ : [
425
+ {
426
+ value: PREVIEW_ACTIONS.edit,
427
+ label: intent.kind === "preset" ? "Customize before applying" : "Continue editing",
428
+ },
429
+ ]),
430
+ {
431
+ value: PREVIEW_ACTIONS.cancel,
432
+ label:
433
+ intent.kind === "restore"
434
+ ? "Cancel"
435
+ : intent.kind === "preset"
436
+ ? "Choose another preset"
437
+ : "Discard draft",
438
+ },
439
+ ],
440
+ owner.signal,
441
+ owner.isCurrent,
442
+ );
443
+ if (!isCurrentOwner(owner)) return "cancel";
444
+ if (selection?.kind === "closed") return "close";
445
+ const selected = selectedPreviewAction(selection);
446
+ if (selected === PREVIEW_ACTIONS.edit) return "edit";
447
+ if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
448
+ }
449
+ reviewRequired = true;
450
+
451
+ const confirmed = await ctx.ui.confirm(
452
+ confirmationTitle(intent),
453
+ confirmationMessage(options.settingsPath, intent),
454
+ );
455
+ if (!isCurrentOwner(owner)) return "cancel";
456
+ if (!confirmed) {
457
+ if (directAttempt) return "cancel";
458
+ continue;
459
+ }
460
+
461
+ const save = options.save ?? atomicSaveConfigDocument;
462
+ const previous = options.getLoaded();
463
+ let saved: LoadedStarshipConfig;
464
+ try {
465
+ saved = save(options.settingsPath, validated.rawDocument ?? BUILT_IN_EXAMPLE);
466
+ } catch (error) {
467
+ ctx.ui.notify(
468
+ `Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
469
+ "error",
470
+ );
471
+ if (directAttempt) return "cancel";
472
+ continue;
473
+ }
474
+
475
+ try {
476
+ options.apply(saved, ctx);
477
+ } catch (error) {
478
+ const rollbackError = restorePreviousConfiguration(ctx, options, previous, saved);
479
+ ctx.ui.notify(
480
+ rollbackError
481
+ ? `Footer settings could not be applied: ${safeText(formatError(error))}. Restoring the previous configuration also failed: ${safeText(formatError(rollbackError))}.`
482
+ : `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
483
+ "error",
484
+ );
485
+ if (directAttempt) return "cancel";
486
+ continue;
487
+ }
488
+
489
+ const warningSuffix =
490
+ saved.diagnostics.length > 0
491
+ ? ` (${saved.diagnostics.length} warning${saved.diagnostics.length === 1 ? "" : "s"})`
492
+ : "";
493
+ ctx.ui.notify(`${successMessage(intent)}${warningSuffix}.`, "info");
494
+ return "applied";
495
+ }
521
496
  }
522
497
 
523
498
  function reviewTitle(intent: ReviewIntent): string {
524
- switch (intent.kind) {
525
- case "customize":
526
- return "Footer preview";
527
- case "restore":
528
- return "Restore preview";
529
- case "preset":
530
- return `${intent.preset.label} preset preview`;
531
- }
499
+ switch (intent.kind) {
500
+ case "customize":
501
+ return "Footer preview";
502
+ case "restore":
503
+ return "Restore preview";
504
+ case "preset":
505
+ return `${intent.preset.label} preset preview`;
506
+ }
532
507
  }
533
508
 
534
509
  function continueLabel(intent: ReviewIntent): string {
535
- switch (intent.kind) {
536
- case "customize":
537
- return "Apply changes…";
538
- case "restore":
539
- return "Replace with built-in…";
540
- case "preset":
541
- return `Apply ${intent.preset.label} preset…`;
542
- }
510
+ switch (intent.kind) {
511
+ case "customize":
512
+ return "Apply changes…";
513
+ case "restore":
514
+ return "Replace with built-in…";
515
+ case "preset":
516
+ return `Apply ${intent.preset.label} preset…`;
517
+ }
543
518
  }
544
519
 
545
520
  function confirmationTitle(intent: ReviewIntent): string {
546
- switch (intent.kind) {
547
- case "customize":
548
- return "Apply footer changes?";
549
- case "restore":
550
- return "Restore built-in footer?";
551
- case "preset":
552
- return `Apply ${intent.preset.label} preset?`;
553
- }
521
+ switch (intent.kind) {
522
+ case "customize":
523
+ return "Apply footer changes?";
524
+ case "restore":
525
+ return "Restore built-in footer?";
526
+ case "preset":
527
+ return `Apply ${intent.preset.label} preset?`;
528
+ }
554
529
  }
555
530
 
556
531
  function confirmationMessage(settingsPath: string, intent: ReviewIntent): string {
557
- if (intent.kind === "customize") return "Save this configuration and apply it immediately?";
558
- const replacement =
559
- intent.kind === "restore" ? "the built-in configuration" : `the ${intent.preset.label} preset`;
560
- return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`;
532
+ if (intent.kind === "customize") return "Save this configuration and apply it immediately?";
533
+ const replacement = intent.kind === "restore" ? "the built-in configuration" : `the ${intent.preset.label} preset`;
534
+ return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`;
561
535
  }
562
536
 
563
537
  function successMessage(intent: ReviewIntent): string {
564
- switch (intent.kind) {
565
- case "customize":
566
- return "Footer settings saved and applied";
567
- case "restore":
568
- return "Built-in footer restored and applied";
569
- case "preset":
570
- return `${intent.preset.label} preset saved and applied`;
571
- }
538
+ switch (intent.kind) {
539
+ case "customize":
540
+ return "Footer settings saved and applied";
541
+ case "restore":
542
+ return "Built-in footer restored and applied";
543
+ case "preset":
544
+ return `${intent.preset.label} preset saved and applied`;
545
+ }
572
546
  }
573
547
 
574
548
  function modulePreviewDetails(preview: string): string[] {
575
- const lines = preview ? preview.split("\n") : ["(no current preview)"];
576
- return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
549
+ const lines = preview ? preview.split("\n") : ["(no current preview)"];
550
+ return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
577
551
  }
578
552
 
579
553
  function workflowOwner(options: StarshipCommandOptions): WorkflowOwner {
580
- if (options.getMenuOwner) return options.getMenuOwner();
581
- const controller = new AbortController();
582
- return { signal: controller.signal, isCurrent: () => true };
554
+ if (options.getMenuOwner) return options.getMenuOwner();
555
+ const controller = new AbortController();
556
+ return { signal: controller.signal, isCurrent: () => true };
583
557
  }
584
558
 
585
559
  function isCurrentOwner(owner: WorkflowOwner): boolean {
586
- return !owner.signal.aborted && owner.isCurrent();
560
+ return !owner.signal.aborted && owner.isCurrent();
587
561
  }
588
562
 
589
563
  function restorePreviousConfiguration(
590
- ctx: ExtensionCommandContext,
591
- options: StarshipCommandOptions,
592
- previous: LoadedStarshipConfig,
593
- saved: LoadedStarshipConfig,
564
+ ctx: ExtensionCommandContext,
565
+ options: StarshipCommandOptions,
566
+ previous: LoadedStarshipConfig,
567
+ saved: LoadedStarshipConfig,
594
568
  ): unknown {
595
- try {
596
- if (saved.rawDocument === undefined || saved.fileIdentity === undefined) {
597
- throw new Error("The saved settings document identity is unavailable");
598
- }
599
- removeConfigDocumentIfMatches(options.settingsPath, saved.rawDocument, saved.fileIdentity);
600
- if (previous.rawDocument !== undefined) {
601
- (options.restore ?? atomicRestoreConfigDocument)(options.settingsPath, previous.rawDocument);
602
- }
603
- options.apply(previous, ctx);
604
- return undefined;
605
- } catch (error) {
606
- return error;
607
- }
569
+ try {
570
+ if (saved.rawDocument === undefined || saved.fileIdentity === undefined) {
571
+ throw new Error("The saved settings document identity is unavailable");
572
+ }
573
+ removeConfigDocumentIfMatches(options.settingsPath, saved.rawDocument, saved.fileIdentity);
574
+ if (previous.rawDocument !== undefined) {
575
+ (options.restore ?? atomicRestoreConfigDocument)(options.settingsPath, previous.rawDocument);
576
+ }
577
+ options.apply(previous, ctx);
578
+ return undefined;
579
+ } catch (error) {
580
+ return error;
581
+ }
608
582
  }
609
583
 
610
584
  function reviewPreviewBody(
611
- ctx: ExtensionCommandContext,
612
- options: StarshipCommandOptions,
613
- loaded: LoadedStarshipConfig,
614
- width: number,
615
- intent: ReviewIntent,
585
+ ctx: ExtensionCommandContext,
586
+ options: StarshipCommandOptions,
587
+ loaded: LoadedStarshipConfig,
588
+ width: number,
589
+ intent: ReviewIntent,
616
590
  ): string[] {
617
- if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
618
- if (intent.kind === "customize") return previewBody(ctx, options, loaded, width);
619
- const current = configurationPresentation(options.getLoaded());
620
- return [
621
- `Preset: ${intent.preset.label}`,
622
- `Requirement: ${intent.preset.requiresNerdFont ? "Nerd Font" : "No special font"}`,
623
- `Current: ${current.state}`,
624
- `Path: ${safeText(options.settingsPath)}`,
625
- "Applying replaces the entire settings document, including custom settings, unknown fields, and comments.",
626
- "No backup is kept after a successful apply.",
627
- "",
628
- ...previewBody(ctx, options, loaded, width),
629
- ];
591
+ if (intent.kind === "restore") return restorePreviewBody(ctx, options, loaded, width);
592
+ if (intent.kind === "customize") return previewBody(ctx, options, loaded, width);
593
+ const current = configurationPresentation(options.getLoaded());
594
+ return [
595
+ `Preset: ${intent.preset.label}`,
596
+ `Requirement: ${intent.preset.requiresNerdFont ? "Nerd Font" : "No special font"}`,
597
+ `Current: ${current.state}`,
598
+ `Path: ${safeText(options.settingsPath)}`,
599
+ "Applying replaces the entire settings document, including custom settings, unknown fields, and comments.",
600
+ "No backup is kept after a successful apply.",
601
+ "",
602
+ ...previewBody(ctx, options, loaded, width),
603
+ ];
630
604
  }
631
605
 
632
606
  function restorePreviewBody(
633
- ctx: ExtensionCommandContext,
634
- options: StarshipCommandOptions,
635
- loaded: LoadedStarshipConfig,
636
- width: number,
607
+ ctx: ExtensionCommandContext,
608
+ options: StarshipCommandOptions,
609
+ loaded: LoadedStarshipConfig,
610
+ width: number,
637
611
  ): string[] {
638
- const current = configurationPresentation(options.getLoaded());
639
- return [
640
- `Current: ${current.state}`,
641
- `Path: ${safeText(options.settingsPath)}`,
642
- "The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
643
- "No backup is kept after a successful restore.",
644
- "",
645
- ...previewBody(ctx, options, loaded, width),
646
- ];
612
+ const current = configurationPresentation(options.getLoaded());
613
+ return [
614
+ `Current: ${current.state}`,
615
+ `Path: ${safeText(options.settingsPath)}`,
616
+ "The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
617
+ "No backup is kept after a successful restore.",
618
+ "",
619
+ ...previewBody(ctx, options, loaded, width),
620
+ ];
647
621
  }
648
622
 
649
623
  function previewBody(
650
- ctx: ExtensionCommandContext,
651
- options: StarshipCommandOptions,
652
- loaded: LoadedStarshipConfig,
653
- width: number,
624
+ ctx: ExtensionCommandContext,
625
+ options: StarshipCommandOptions,
626
+ loaded: LoadedStarshipConfig,
627
+ width: number,
654
628
  ): string[] {
655
- let lines: string[];
656
- try {
657
- lines = options.renderPreview?.(loaded, width, ctx) ?? [
658
- "Live preview is unavailable until the footer is ready.",
659
- "The draft is valid and can still be applied.",
660
- ];
661
- } catch (error) {
662
- lines = [`Preview unavailable: ${safeText(formatError(error))}`];
663
- }
664
- const warning =
665
- loaded.diagnostics.length === 0
666
- ? "Draft validation: Healthy"
667
- : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"}`;
668
- return [...lines, "", warning];
629
+ let lines: string[];
630
+ try {
631
+ lines = options.renderPreview?.(loaded, width, ctx) ?? [
632
+ "Live preview is unavailable until the footer is ready.",
633
+ "The draft is valid and can still be applied.",
634
+ ];
635
+ } catch (error) {
636
+ lines = [`Preview unavailable: ${safeText(formatError(error))}`];
637
+ }
638
+ const warning =
639
+ loaded.diagnostics.length === 0
640
+ ? "Draft validation: Healthy"
641
+ : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"}`;
642
+ return [...lines, "", warning];
669
643
  }
670
644
 
671
- function selectedPreviewAction<Value extends string>(
672
- result: PreviewMenuResult<Value> | undefined,
673
- ): Value | null {
674
- return result?.kind === "selected" ? result.value : null;
645
+ function selectedPreviewAction<Value extends string>(result: PreviewMenuResult<Value> | undefined): Value | null {
646
+ return result?.kind === "selected" ? result.value : null;
675
647
  }
676
648
 
677
649
  function showStatus(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
678
- if (!canNotify(ctx)) return;
679
- const loaded = options.getLoaded();
680
- const diagnostics = loaded.diagnostics
681
- .slice(0, 5)
682
- .map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`)
683
- .join("; ");
684
- ctx.ui.notify(
685
- [
686
- `pi-starship source: ${loaded.source}`,
687
- `path: ${options.settingsPath}`,
688
- diagnostics ? `warnings: ${diagnostics}` : "warnings: none",
689
- ].join("\n"),
690
- loaded.diagnostics.length > 0 ? "warning" : "info",
691
- );
650
+ if (!canNotify(ctx)) return;
651
+ const loaded = options.getLoaded();
652
+ const diagnostics = loaded.diagnostics
653
+ .slice(0, 5)
654
+ .map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`)
655
+ .join("; ");
656
+ ctx.ui.notify(
657
+ [
658
+ `pi-starship source: ${loaded.source}`,
659
+ `path: ${options.settingsPath}`,
660
+ diagnostics ? `warnings: ${diagnostics}` : "warnings: none",
661
+ ].join("\n"),
662
+ loaded.diagnostics.length > 0 ? "warning" : "info",
663
+ );
692
664
  }
693
665
 
694
666
  function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
695
- if (!canNotify(ctx)) return;
696
- ctx.ui.notify(
697
- [
698
- "/starship — customize, live-preview presets, explain, or inspect the footer in TUI mode",
699
- "/starship settings — customize, preview, and apply TOML",
700
- "/starship status — show source, path, and warnings",
701
- "/starship help — show this help",
702
- `Settings: ${settingsPath}`,
703
- "Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
704
- ].join("\n"),
705
- "info",
706
- );
667
+ if (!canNotify(ctx)) return;
668
+ ctx.ui.notify(
669
+ [
670
+ "/starship — customize, live-preview presets, explain, or inspect the footer in TUI mode",
671
+ "/starship settings — customize, preview, and apply TOML",
672
+ "/starship status — show source, path, and warnings",
673
+ "/starship help — show this help",
674
+ `Settings: ${settingsPath}`,
675
+ "Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
676
+ ].join("\n"),
677
+ "info",
678
+ );
707
679
  }
708
680
 
709
681
  function canNotify(ctx: ExtensionCommandContext): boolean {
710
- return ctx.mode === "tui" || ctx.hasUI;
682
+ return ctx.mode === "tui" || ctx.hasUI;
711
683
  }
712
684
 
713
685
  function safeText(value: string): string {
714
- return Array.from(value, (character) => {
715
- const codePoint = character.codePointAt(0) ?? 0;
716
- const unsafe =
717
- codePoint <= 0x08 ||
718
- (codePoint >= 0x0b && codePoint <= 0x1f) ||
719
- (codePoint >= 0x7f && codePoint <= 0x9f);
720
- return unsafe ? `\\u${codePoint.toString(16).padStart(4, "0")}` : character;
721
- }).join("");
686
+ return Array.from(value, (character) => {
687
+ const codePoint = character.codePointAt(0) ?? 0;
688
+ const unsafe =
689
+ codePoint <= 0x08 || (codePoint >= 0x0b && codePoint <= 0x1f) || (codePoint >= 0x7f && codePoint <= 0x9f);
690
+ return unsafe ? `\\u${codePoint.toString(16).padStart(4, "0")}` : character;
691
+ }).join("");
722
692
  }
723
693
 
724
694
  function formatError(error: unknown): string {
725
- return error instanceof Error ? error.message : String(error);
695
+ return error instanceof Error ? error.message : String(error);
726
696
  }