@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.
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +20 -55
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -603
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
continue: "continue",
|
|
40
|
+
edit: "edit",
|
|
41
|
+
cancel: "cancel",
|
|
47
42
|
} as const;
|
|
48
43
|
|
|
49
44
|
export interface StarshipCommandOptions extends ConfigurationCommandOptions {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
args: string,
|
|
65
|
+
ctx: ExtensionCommandContext,
|
|
66
|
+
options: StarshipCommandOptions,
|
|
75
67
|
) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
276
|
-
|
|
262
|
+
ctx: ExtensionCommandContext,
|
|
263
|
+
options: StarshipCommandOptions,
|
|
277
264
|
): Promise<"applied" | "cancel" | "close"> {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
|
|
305
|
+
ctx: ExtensionCommandContext,
|
|
306
|
+
options: StarshipCommandOptions,
|
|
307
|
+
owner: WorkflowOwner,
|
|
321
308
|
): Promise<"applied" | "cancel" | "close"> {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
339
|
+
ctx: ExtensionCommandContext,
|
|
340
|
+
options: StarshipCommandOptions,
|
|
341
|
+
preset: StarshipPreset,
|
|
342
|
+
start: "review" | "confirm" | "customize" = "review",
|
|
364
343
|
): Promise<"applied" | "cancel" | "close"> {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
416
|
-
|
|
394
|
+
ctx: ExtensionCommandContext,
|
|
395
|
+
options: StarshipCommandOptions,
|
|
417
396
|
): Promise<"applied" | "cancel" | "close"> {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
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
|
-
|
|
576
|
-
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
-
|
|
560
|
+
return !owner.signal.aborted && owner.isCurrent();
|
|
587
561
|
}
|
|
588
562
|
|
|
589
563
|
function restorePreviousConfiguration(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
564
|
+
ctx: ExtensionCommandContext,
|
|
565
|
+
options: StarshipCommandOptions,
|
|
566
|
+
previous: LoadedStarshipConfig,
|
|
567
|
+
saved: LoadedStarshipConfig,
|
|
594
568
|
): unknown {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
585
|
+
ctx: ExtensionCommandContext,
|
|
586
|
+
options: StarshipCommandOptions,
|
|
587
|
+
loaded: LoadedStarshipConfig,
|
|
588
|
+
width: number,
|
|
589
|
+
intent: ReviewIntent,
|
|
616
590
|
): string[] {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
607
|
+
ctx: ExtensionCommandContext,
|
|
608
|
+
options: StarshipCommandOptions,
|
|
609
|
+
loaded: LoadedStarshipConfig,
|
|
610
|
+
width: number,
|
|
637
611
|
): string[] {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
624
|
+
ctx: ExtensionCommandContext,
|
|
625
|
+
options: StarshipCommandOptions,
|
|
626
|
+
loaded: LoadedStarshipConfig,
|
|
627
|
+
width: number,
|
|
654
628
|
): string[] {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
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
|
-
|
|
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
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
682
|
+
return ctx.mode === "tui" || ctx.hasUI;
|
|
711
683
|
}
|
|
712
684
|
|
|
713
685
|
function safeText(value: string): string {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
695
|
+
return error instanceof Error ? error.message : String(error);
|
|
726
696
|
}
|