@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.
- package/README.md +2 -0
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
- package/dist/chunks/chunk-SD7TUSSU.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-MJCAK6JL.js} +18 -42
- package/dist/chunks/commands-MJCAK6JL.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/SKILL.md +18 -4
- package/skills/configuring-pi-starship/references/configuration.md +70 -2
- package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
- package/skills/configuring-pi-starship/references/modules.md +2 -0
- package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
- package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
- 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 +590 -618
- package/src/config.ts +635 -660
- package/src/effective-config.ts +49 -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 +105 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +61 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +25 -24
- package/src/modules/render.ts +131 -141
- package/src/modules/style-rules.ts +21 -0
- package/src/modules/thinking.ts +31 -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 +133 -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,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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
276
|
-
|
|
264
|
+
ctx: ExtensionCommandContext,
|
|
265
|
+
options: StarshipCommandOptions,
|
|
277
266
|
): 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
|
-
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
|
|
307
|
+
ctx: ExtensionCommandContext,
|
|
308
|
+
options: StarshipCommandOptions,
|
|
309
|
+
owner: WorkflowOwner,
|
|
321
310
|
): 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
|
-
}
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
341
|
+
ctx: ExtensionCommandContext,
|
|
342
|
+
options: StarshipCommandOptions,
|
|
343
|
+
preset: StarshipPreset,
|
|
344
|
+
start: "review" | "confirm" | "customize" = "review",
|
|
364
345
|
): 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
|
-
|
|
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
|
-
|
|
416
|
-
|
|
396
|
+
ctx: ExtensionCommandContext,
|
|
397
|
+
options: StarshipCommandOptions,
|
|
417
398
|
): 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;
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
-
|
|
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.`;
|
|
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
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
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
|
-
|
|
576
|
-
|
|
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
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
-
|
|
562
|
+
return !owner.signal.aborted && owner.isCurrent();
|
|
587
563
|
}
|
|
588
564
|
|
|
589
565
|
function restorePreviousConfiguration(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
566
|
+
ctx: ExtensionCommandContext,
|
|
567
|
+
options: StarshipCommandOptions,
|
|
568
|
+
previous: LoadedStarshipConfig,
|
|
569
|
+
saved: LoadedStarshipConfig,
|
|
594
570
|
): unknown {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
587
|
+
ctx: ExtensionCommandContext,
|
|
588
|
+
options: StarshipCommandOptions,
|
|
589
|
+
loaded: LoadedStarshipConfig,
|
|
590
|
+
width: number,
|
|
591
|
+
intent: ReviewIntent,
|
|
616
592
|
): string[] {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
609
|
+
ctx: ExtensionCommandContext,
|
|
610
|
+
options: StarshipCommandOptions,
|
|
611
|
+
loaded: LoadedStarshipConfig,
|
|
612
|
+
width: number,
|
|
637
613
|
): string[] {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
626
|
+
ctx: ExtensionCommandContext,
|
|
627
|
+
options: StarshipCommandOptions,
|
|
628
|
+
loaded: LoadedStarshipConfig,
|
|
629
|
+
width: number,
|
|
654
630
|
): string[] {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
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
|
-
|
|
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
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
684
|
+
return ctx.mode === "tui" || ctx.hasUI;
|
|
711
685
|
}
|
|
712
686
|
|
|
713
687
|
function safeText(value: string): string {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
697
|
+
return error instanceof Error ? error.message : String(error);
|
|
726
698
|
}
|