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