@narumitw/pi-starship 0.60.1 → 0.63.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 +67 -9
- package/dist/chunks/chunk-63R6R5DH.ts +679 -0
- package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-A65IOGL6.ts} +858 -1007
- package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/chunk-Y24TJYG6.ts +1586 -0
- package/dist/chunks/chunk-Y24TJYG6.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts +147 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts.map +7 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts +1124 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
- package/dist/chunks/commands-IOG2PL67.ts +1026 -0
- package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +670 -206
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +17 -1
- package/skills/configure-pi-starship/references/configuration.md +119 -32
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/src/command-commit.ts +41 -7
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +15 -94
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +168 -0
- package/src/commands.ts +76 -124
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +23 -59
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +198 -88
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +192 -0
- package/src/settings-chat-ui.ts +526 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
package/src/commands.ts
CHANGED
|
@@ -10,34 +10,27 @@ import {
|
|
|
10
10
|
} from "./command-commit.js";
|
|
11
11
|
import {
|
|
12
12
|
type ConfigurationCommandOptions,
|
|
13
|
-
configurationMenuScreen,
|
|
14
|
-
configurationOverviewScreen,
|
|
15
13
|
configurationPresentation,
|
|
16
|
-
effectiveConfigurationScreen,
|
|
17
14
|
reloadConfiguration,
|
|
18
|
-
settingsDocumentScreen,
|
|
19
15
|
type WorkflowOwner,
|
|
20
16
|
} from "./command-configuration.js";
|
|
21
17
|
import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
|
|
22
18
|
import { importSettingsGist, shareSettingsGist } from "./command-gist.js";
|
|
23
|
-
import { formatFooterExplanation } from "./command-inspector.js";
|
|
24
19
|
import { showPresetPicker } from "./command-preset-picker.js";
|
|
25
20
|
import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
|
|
26
21
|
import { saveAsProfile, showHistory, showProfiles } from "./command-profiles.js";
|
|
27
|
-
import { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from "./config.js";
|
|
22
|
+
import { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, nativeFooterConfig, validateConfigDocument } from "./config.js";
|
|
28
23
|
import type { GhApi } from "./gist.js";
|
|
29
|
-
import {
|
|
24
|
+
import type { StatuslineInspection } from "./modules/inspection.js";
|
|
30
25
|
import { getStarshipPreset, presetForDocument, STARSHIP_PRESETS, type StarshipPreset } from "./presets/catalog.js";
|
|
31
26
|
|
|
32
27
|
const MAIN_ACTIONS = {
|
|
33
|
-
customize: "customize",
|
|
34
28
|
presets: "presets",
|
|
35
|
-
explain: "explain",
|
|
36
|
-
modules: "modules",
|
|
37
29
|
configuration: "configuration",
|
|
38
30
|
help: "help",
|
|
39
31
|
restore: "restore",
|
|
40
32
|
profiles: "profiles",
|
|
33
|
+
chat: "settings-chat",
|
|
41
34
|
} as const;
|
|
42
35
|
|
|
43
36
|
const PREVIEW_ACTIONS = {
|
|
@@ -55,6 +48,7 @@ export interface StarshipCommandOptions extends ConfigurationCommandOptions, Com
|
|
|
55
48
|
validate?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
|
|
56
49
|
getMenuOwner?(): WorkflowOwner;
|
|
57
50
|
gistApi?: GhApi;
|
|
51
|
+
registerChatCleanup?(cleanup: () => Promise<void>): () => void;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
export type ReviewIntent =
|
|
@@ -67,7 +61,7 @@ export type ReviewIntent =
|
|
|
67
61
|
|
|
68
62
|
export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
|
|
69
63
|
pi.registerCommand("starship", {
|
|
70
|
-
description: "
|
|
64
|
+
description: "Configure the footer with agent, presets, profiles, and recovery",
|
|
71
65
|
getArgumentCompletions: completeStarshipArguments,
|
|
72
66
|
handler: (args, ctx) => handleStarshipCommand(args, ctx, options),
|
|
73
67
|
});
|
|
@@ -153,24 +147,17 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
153
147
|
signal: fallbackController.signal,
|
|
154
148
|
isCurrent: () => !fallbackController.signal.aborted,
|
|
155
149
|
};
|
|
156
|
-
type Screen =
|
|
157
|
-
| "main"
|
|
158
|
-
| "explain"
|
|
159
|
-
| "modules"
|
|
160
|
-
| "configuration"
|
|
161
|
-
| "configuration-overview"
|
|
162
|
-
| "configuration-effective"
|
|
163
|
-
| "configuration-document"
|
|
164
|
-
| "help";
|
|
150
|
+
type Screen = "main" | "help";
|
|
165
151
|
type Action =
|
|
166
|
-
| "
|
|
152
|
+
| "configuration"
|
|
167
153
|
| "presets"
|
|
168
154
|
| "profiles"
|
|
169
155
|
| "history"
|
|
170
156
|
| "configuration-reload"
|
|
171
157
|
| "restore"
|
|
172
158
|
| "gist-share"
|
|
173
|
-
| "gist-import"
|
|
159
|
+
| "gist-import"
|
|
160
|
+
| "settings-chat";
|
|
174
161
|
const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
|
|
175
162
|
start: "main",
|
|
176
163
|
screens: {
|
|
@@ -180,13 +167,16 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
180
167
|
return {
|
|
181
168
|
kind: "actions",
|
|
182
169
|
title: "pi-starship",
|
|
183
|
-
lines: [
|
|
170
|
+
lines: [
|
|
171
|
+
`${presentation.state} · ${presentation.health}`,
|
|
172
|
+
"Configure with agent for edits, module questions, and footer explanations.",
|
|
173
|
+
],
|
|
184
174
|
items: [
|
|
185
175
|
{
|
|
186
|
-
id: MAIN_ACTIONS.
|
|
187
|
-
label: "
|
|
188
|
-
description:
|
|
189
|
-
action: "
|
|
176
|
+
id: MAIN_ACTIONS.chat,
|
|
177
|
+
label: "Configure with agent",
|
|
178
|
+
description: "Separate conversation · draft tools · live preview only until you save",
|
|
179
|
+
action: "settings-chat",
|
|
190
180
|
},
|
|
191
181
|
{
|
|
192
182
|
id: MAIN_ACTIONS.presets,
|
|
@@ -195,28 +185,16 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
195
185
|
action: "presets",
|
|
196
186
|
},
|
|
197
187
|
{
|
|
198
|
-
id: MAIN_ACTIONS.
|
|
199
|
-
label: "
|
|
200
|
-
description: "
|
|
201
|
-
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
id: MAIN_ACTIONS.modules,
|
|
205
|
-
label: "Modules",
|
|
206
|
-
description: "Browse supported modules and current states",
|
|
207
|
-
to: "modules",
|
|
188
|
+
id: MAIN_ACTIONS.profiles,
|
|
189
|
+
label: "Profiles",
|
|
190
|
+
description: "Save, edit, manage, and live-preview named TOML documents",
|
|
191
|
+
action: "profiles",
|
|
208
192
|
},
|
|
209
193
|
{
|
|
210
194
|
id: MAIN_ACTIONS.configuration,
|
|
211
195
|
label: "Configuration",
|
|
212
196
|
description: presentation.health,
|
|
213
|
-
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
id: MAIN_ACTIONS.help,
|
|
217
|
-
label: "Help",
|
|
218
|
-
description: "Formats, modules, and commands",
|
|
219
|
-
to: "help",
|
|
197
|
+
action: "configuration",
|
|
220
198
|
},
|
|
221
199
|
{
|
|
222
200
|
id: MAIN_ACTIONS.restore,
|
|
@@ -226,64 +204,25 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
226
204
|
action: "restore",
|
|
227
205
|
},
|
|
228
206
|
{
|
|
229
|
-
id: MAIN_ACTIONS.
|
|
230
|
-
label: "
|
|
231
|
-
description: "
|
|
232
|
-
|
|
207
|
+
id: MAIN_ACTIONS.help,
|
|
208
|
+
label: "Help",
|
|
209
|
+
description: "Settings, modules, and commands",
|
|
210
|
+
to: "help",
|
|
233
211
|
},
|
|
234
212
|
],
|
|
235
213
|
hint: "close",
|
|
236
214
|
};
|
|
237
215
|
},
|
|
238
|
-
explain: () => ({
|
|
239
|
-
kind: "review",
|
|
240
|
-
title: "Explain footer",
|
|
241
|
-
content: formatFooterExplanation(options.getInspection?.()),
|
|
242
|
-
format: { kind: "text" },
|
|
243
|
-
viewportSize: "adaptive",
|
|
244
|
-
hint: "back",
|
|
245
|
-
}),
|
|
246
|
-
modules: () => {
|
|
247
|
-
const inspection = options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
|
|
248
|
-
return {
|
|
249
|
-
kind: "browse",
|
|
250
|
-
title: "Modules",
|
|
251
|
-
items: inspection.modules.map((module) => ({
|
|
252
|
-
id: module.name,
|
|
253
|
-
label: module.name,
|
|
254
|
-
statusText: module.state,
|
|
255
|
-
description: module.description,
|
|
256
|
-
searchText: [...module.variables, ...module.styleFields, ...module.displayRules].join(" "),
|
|
257
|
-
details: [
|
|
258
|
-
`Root: ${module.rootReferenced ? "Referenced" : "Not referenced"}`,
|
|
259
|
-
`Reachable: ${module.reachable ? "Yes" : "No"}`,
|
|
260
|
-
...modulePreviewDetails(module.preview),
|
|
261
|
-
`Reason: ${module.reason}`,
|
|
262
|
-
`Variables: ${module.variables.join(", ") || "none"}`,
|
|
263
|
-
`Style fields: ${module.styleFields.join(", ") || "none"}`,
|
|
264
|
-
`Style-rule selectors: ${module.styleRuleSelectors.join(", ") || "none"}`,
|
|
265
|
-
`Style rules: ${module.styleRuleCount} configured`,
|
|
266
|
-
`Display rules: ${module.displayRules.join(" · ") || "none"}`,
|
|
267
|
-
],
|
|
268
|
-
})),
|
|
269
|
-
viewportSize: "adaptive",
|
|
270
|
-
hint: "back",
|
|
271
|
-
};
|
|
272
|
-
},
|
|
273
|
-
configuration: () => configurationMenuScreen(options.getLoaded()),
|
|
274
|
-
"configuration-overview": () => configurationOverviewScreen(options.getLoaded(), options.settingsPath),
|
|
275
|
-
"configuration-effective": () => effectiveConfigurationScreen(options.getLoaded()),
|
|
276
|
-
"configuration-document": () => settingsDocumentScreen(options.getLoaded(), options.settingsPath),
|
|
277
216
|
help: () => ({
|
|
278
217
|
kind: "detail",
|
|
279
218
|
title: "pi-starship help",
|
|
280
219
|
lines: [
|
|
281
|
-
"
|
|
220
|
+
"/starship settings retains the TOML editor with preview and confirmation.",
|
|
221
|
+
"Configure with agent opens a separate skill-backed chat; edits preview only until you explicitly save.",
|
|
282
222
|
"Presets live-previews the cursor in the footer; Enter confirms apply, e customizes, and s saves a profile when available.",
|
|
283
223
|
"Profiles manages named TOML copies; selecting a document previews it without saving.",
|
|
284
224
|
"Configuration History reviews and restores recovery copies; external edits are not fully tracked.",
|
|
285
|
-
"
|
|
286
|
-
"Modules searches every supported module and explains its current read-only state.",
|
|
225
|
+
"Ask Configure with agent about active settings and module states captured when the chat opens.",
|
|
287
226
|
"Configuration includes disk reload plus unlisted Gist sharing and reviewed Gist import through gh.",
|
|
288
227
|
`Settings: ${safeText(options.settingsPath)}`,
|
|
289
228
|
"Docs: https://github.com/narumiruna/pi-extensions/tree/main/packages/pi-starship",
|
|
@@ -292,9 +231,31 @@ async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipComma
|
|
|
292
231
|
}),
|
|
293
232
|
},
|
|
294
233
|
actions: {
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
234
|
+
"settings-chat": async () => {
|
|
235
|
+
const { showSettingsAgentChat } = await import("./command-settings-chat.js");
|
|
236
|
+
if (!isCurrentOwner(owner)) return { kind: "close" };
|
|
237
|
+
await showSettingsAgentChat(ctx, options, owner);
|
|
238
|
+
return { kind: "close" };
|
|
239
|
+
},
|
|
240
|
+
configuration: async () => {
|
|
241
|
+
const { showConfigurationMenu } = await import("./command-configuration-menu.js");
|
|
242
|
+
if (!isCurrentOwner(owner)) return { kind: "close" };
|
|
243
|
+
let selected: string | undefined;
|
|
244
|
+
while (isCurrentOwner(owner)) {
|
|
245
|
+
const result = await showConfigurationMenu(ctx, options, owner, selected);
|
|
246
|
+
if (!isCurrentOwner(owner) || result.kind !== "completed") return { kind: "close" };
|
|
247
|
+
if (result.value === "back") return { kind: "stay" };
|
|
248
|
+
if (result.value === "close") return { kind: "close" };
|
|
249
|
+
selected = result.value;
|
|
250
|
+
const transition = await menu.actions[result.value]({
|
|
251
|
+
ctx,
|
|
252
|
+
state: undefined,
|
|
253
|
+
signal: owner.signal,
|
|
254
|
+
itemId: result.value,
|
|
255
|
+
});
|
|
256
|
+
if (!isCurrentOwner(owner) || transition?.kind === "close") return { kind: "close" };
|
|
257
|
+
}
|
|
258
|
+
return { kind: "close" };
|
|
298
259
|
},
|
|
299
260
|
presets: async () => {
|
|
300
261
|
const result = await choosePreset(ctx, options, owner);
|
|
@@ -541,8 +502,8 @@ async function restoreBuiltIn(
|
|
|
541
502
|
): Promise<"applied" | "cancel" | "close"> {
|
|
542
503
|
const owner = workflowOwner(options);
|
|
543
504
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
544
|
-
const
|
|
545
|
-
const result = await reviewAndApply(ctx, options,
|
|
505
|
+
const candidate = nativeFooterConfig(options.settingsPath);
|
|
506
|
+
const result = await reviewAndApply(ctx, options, candidate, { kind: "restore" }, owner);
|
|
546
507
|
return result === "edit" ? "cancel" : result;
|
|
547
508
|
}
|
|
548
509
|
|
|
@@ -627,6 +588,7 @@ export async function reviewAndApply(
|
|
|
627
588
|
expected,
|
|
628
589
|
intent.kind === "restore" || intent.kind === "history" || intent.kind === "customize",
|
|
629
590
|
checkCandidate,
|
|
591
|
+
intent.kind === "restore",
|
|
630
592
|
);
|
|
631
593
|
if (!isSessionOwnerCurrent(owner) || result === "cancel") return "cancel";
|
|
632
594
|
} catch (error) {
|
|
@@ -667,7 +629,7 @@ function continueLabel(intent: ReviewIntent): string {
|
|
|
667
629
|
case "customize":
|
|
668
630
|
return "Apply changes…";
|
|
669
631
|
case "restore":
|
|
670
|
-
return "
|
|
632
|
+
return "Restore Pi native footer…";
|
|
671
633
|
case "import":
|
|
672
634
|
return "Replace with Gist settings…";
|
|
673
635
|
case "profile":
|
|
@@ -684,7 +646,7 @@ function confirmationTitle(intent: ReviewIntent): string {
|
|
|
684
646
|
case "customize":
|
|
685
647
|
return "Apply footer changes?";
|
|
686
648
|
case "restore":
|
|
687
|
-
return "Restore
|
|
649
|
+
return "Restore Pi native footer?";
|
|
688
650
|
case "import":
|
|
689
651
|
return "Replace settings with Gist?";
|
|
690
652
|
case "profile":
|
|
@@ -697,21 +659,21 @@ function confirmationTitle(intent: ReviewIntent): string {
|
|
|
697
659
|
}
|
|
698
660
|
|
|
699
661
|
function confirmationMessage(settingsPath: string, intent: ReviewIntent, previous: LoadedStarshipConfig): string {
|
|
662
|
+
if (intent.kind === "restore")
|
|
663
|
+
return `Remove ${safeText(settingsPath)} and show Pi's native footer? The exact previous document, including invalid settings, unknown fields, and comments, will be kept in History.`;
|
|
700
664
|
if (previous.diagnostics.some((item) => item.severity === "error")) {
|
|
701
665
|
return `Explicit recovery: replace the invalid settings file ${safeText(settingsPath)} entirely with the reviewed document? Its exact original bytes will be kept in History before replacement.`;
|
|
702
666
|
}
|
|
703
667
|
if (intent.kind === "customize")
|
|
704
668
|
return "Replace the entire settings document and apply it immediately? Its previous bytes will be kept in History.";
|
|
705
669
|
const replacement =
|
|
706
|
-
intent.kind === "
|
|
707
|
-
? "the
|
|
708
|
-
: intent.kind === "
|
|
709
|
-
?
|
|
710
|
-
: intent.kind === "
|
|
711
|
-
?
|
|
712
|
-
: intent.
|
|
713
|
-
? "the reviewed history document"
|
|
714
|
-
: `the ${intent.preset.label} preset`;
|
|
670
|
+
intent.kind === "import"
|
|
671
|
+
? "the reviewed Gist settings"
|
|
672
|
+
: intent.kind === "profile"
|
|
673
|
+
? `the ${safeText(intent.name)} profile`
|
|
674
|
+
: intent.kind === "history"
|
|
675
|
+
? "the reviewed history document"
|
|
676
|
+
: `the ${intent.preset.label} preset`;
|
|
715
677
|
return `Replace ${safeText(settingsPath)} entirely with ${replacement}? All custom settings, unknown fields, and comments will be replaced. The previous document will be kept in History.`;
|
|
716
678
|
}
|
|
717
679
|
|
|
@@ -720,7 +682,7 @@ function successMessage(intent: ReviewIntent): string {
|
|
|
720
682
|
case "customize":
|
|
721
683
|
return "Footer settings saved and applied";
|
|
722
684
|
case "restore":
|
|
723
|
-
return "
|
|
685
|
+
return "Pi native footer restored and applied";
|
|
724
686
|
case "import":
|
|
725
687
|
return "Gist settings saved and applied";
|
|
726
688
|
case "profile":
|
|
@@ -732,11 +694,6 @@ function successMessage(intent: ReviewIntent): string {
|
|
|
732
694
|
}
|
|
733
695
|
}
|
|
734
696
|
|
|
735
|
-
function modulePreviewDetails(preview: string): string[] {
|
|
736
|
-
const lines = preview ? preview.split("\n") : ["(no current preview)"];
|
|
737
|
-
return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
697
|
function workflowOwner(options: StarshipCommandOptions): WorkflowOwner {
|
|
741
698
|
if (options.getMenuOwner) return options.getMenuOwner();
|
|
742
699
|
const controller = new AbortController();
|
|
@@ -774,7 +731,7 @@ function reviewPreviewBody(
|
|
|
774
731
|
width: number,
|
|
775
732
|
intent: ReviewIntent,
|
|
776
733
|
): string[] {
|
|
777
|
-
if (intent.kind === "restore") return restorePreviewBody(
|
|
734
|
+
if (intent.kind === "restore") return restorePreviewBody(options);
|
|
778
735
|
if (intent.kind !== "preset") return previewBody(ctx, options, loaded, width);
|
|
779
736
|
const current = configurationPresentation(options.getLoaded());
|
|
780
737
|
return [
|
|
@@ -789,20 +746,15 @@ function reviewPreviewBody(
|
|
|
789
746
|
];
|
|
790
747
|
}
|
|
791
748
|
|
|
792
|
-
function restorePreviewBody(
|
|
793
|
-
ctx: ExtensionCommandContext,
|
|
794
|
-
options: StarshipCommandOptions,
|
|
795
|
-
loaded: LoadedStarshipConfig,
|
|
796
|
-
width: number,
|
|
797
|
-
): string[] {
|
|
749
|
+
function restorePreviewBody(options: StarshipCommandOptions): string[] {
|
|
798
750
|
const current = configurationPresentation(options.getLoaded());
|
|
799
751
|
return [
|
|
800
752
|
`Current: ${current.state}`,
|
|
801
753
|
`Path: ${safeText(options.settingsPath)}`,
|
|
802
|
-
"The entire settings document will be
|
|
803
|
-
"The previous document will be kept in History before
|
|
804
|
-
"",
|
|
805
|
-
|
|
754
|
+
"The entire settings document will be removed, including custom settings, unknown fields, and comments.",
|
|
755
|
+
"The previous document will be kept in History before removal.",
|
|
756
|
+
"Pi's native footer will be shown instead of the pi-starship footer.",
|
|
757
|
+
"No replacement settings file will be created.",
|
|
806
758
|
];
|
|
807
759
|
}
|
|
808
760
|
|
|
@@ -853,7 +805,7 @@ function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
|
|
|
853
805
|
if (!canNotify(ctx)) return;
|
|
854
806
|
ctx.ui.notify(
|
|
855
807
|
[
|
|
856
|
-
"/starship — manage profiles,
|
|
808
|
+
"/starship — configure with agent, manage profiles, preview presets, or recover settings in TUI mode",
|
|
857
809
|
"/starship settings — customize, preview, and apply TOML",
|
|
858
810
|
"/starship status — show source, path, and warnings",
|
|
859
811
|
"/starship help — show this help",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { validPattern } from "../format/bounded-regex.js";
|
|
2
|
+
import { isValidStyle } from "../format/style.js";
|
|
3
|
+
import { validStatusTemplate } from "../modules/git/status-templates.js";
|
|
4
|
+
import type { ModuleContextRule, ModuleOptionSchema, ModuleOptionValue, ModuleSubstitution } from "../modules/types.js";
|
|
5
|
+
|
|
6
|
+
type Result = { ok: true; value: ModuleOptionValue } | { ok: false; message: string };
|
|
7
|
+
const invalid = (expected: string): Result => ({ ok: false, message: `Expected ${expected}; using the default value` });
|
|
8
|
+
const record = (value: unknown): value is Record<string, unknown> =>
|
|
9
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
const text = (value: unknown, max = 4_096): value is string => typeof value === "string" && value.length <= max;
|
|
11
|
+
|
|
12
|
+
export function normalizeModuleOption(
|
|
13
|
+
value: unknown,
|
|
14
|
+
schema: ModuleOptionSchema,
|
|
15
|
+
palette: Readonly<Record<string, string>> = {},
|
|
16
|
+
): Result {
|
|
17
|
+
switch (schema.kind) {
|
|
18
|
+
case "string": {
|
|
19
|
+
if (typeof value !== "string" || (schema.allowEmpty === false && value.length === 0)) return invalid("a string");
|
|
20
|
+
if (schema.templateVariables && !validStatusTemplate(value, schema.templateVariables)) {
|
|
21
|
+
return invalid("a bounded template with only the documented variables");
|
|
22
|
+
}
|
|
23
|
+
return { ok: true, value };
|
|
24
|
+
}
|
|
25
|
+
case "string-enum":
|
|
26
|
+
return typeof value === "string" && schema.values.includes(value)
|
|
27
|
+
? { ok: true, value }
|
|
28
|
+
: invalid(`one of: ${schema.values.join(", ")}`);
|
|
29
|
+
case "boolean":
|
|
30
|
+
return typeof value === "boolean" ? { ok: true, value } : invalid("boolean");
|
|
31
|
+
case "integer":
|
|
32
|
+
case "number":
|
|
33
|
+
return typeof value === "number" &&
|
|
34
|
+
Number.isFinite(value) &&
|
|
35
|
+
(schema.kind !== "integer" || Number.isInteger(value)) &&
|
|
36
|
+
value >= schema.minimum &&
|
|
37
|
+
value <= schema.maximum
|
|
38
|
+
? { ok: true, value }
|
|
39
|
+
: invalid(`${schema.kind} from ${schema.minimum} through ${schema.maximum}`);
|
|
40
|
+
case "string-array":
|
|
41
|
+
return Array.isArray(value) &&
|
|
42
|
+
value.every(
|
|
43
|
+
(item) => typeof item === "string" && item.length > 0 && (schema.allowNegative || !item.startsWith("!")),
|
|
44
|
+
)
|
|
45
|
+
? { ok: true, value: [...value] as string[] }
|
|
46
|
+
: invalid("an array of valid strings");
|
|
47
|
+
case "string-map":
|
|
48
|
+
return stringMap(value);
|
|
49
|
+
case "command-alternatives": {
|
|
50
|
+
if (typeof value === "string") value = [value];
|
|
51
|
+
const argument = (item: unknown): item is string =>
|
|
52
|
+
text(item, 1_024) &&
|
|
53
|
+
item.length > 0 &&
|
|
54
|
+
![...item].some((character) => {
|
|
55
|
+
const code = character.codePointAt(0) ?? 0;
|
|
56
|
+
return code < 32 || (code >= 127 && code <= 159);
|
|
57
|
+
});
|
|
58
|
+
if (
|
|
59
|
+
!Array.isArray(value) ||
|
|
60
|
+
value.length > 16 ||
|
|
61
|
+
!value.every(
|
|
62
|
+
(item) =>
|
|
63
|
+
argument(item) || (Array.isArray(item) && item.length > 0 && item.length <= 16 && item.every(argument)),
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
return invalid("at most 16 command names or argv arrays without terminal controls");
|
|
67
|
+
return { ok: true, value: structuredClone(value) };
|
|
68
|
+
}
|
|
69
|
+
case "context-rules": {
|
|
70
|
+
if (!Array.isArray(value) || value.length > 64) return invalid("at most 64 context rules");
|
|
71
|
+
const keys = new Set(["context_pattern", "user_pattern", "symbol", "style", "context_alias", "user_alias"]);
|
|
72
|
+
for (const rule of value) {
|
|
73
|
+
if (
|
|
74
|
+
!record(rule) ||
|
|
75
|
+
!text(rule.context_pattern, 512) ||
|
|
76
|
+
!validPattern(rule.context_pattern) ||
|
|
77
|
+
Object.entries(rule).some(
|
|
78
|
+
([key, item]) =>
|
|
79
|
+
!keys.has(key) ||
|
|
80
|
+
!text(item) ||
|
|
81
|
+
((key === "context_pattern" || key === "user_pattern") && (!text(item, 512) || !validPattern(item))) ||
|
|
82
|
+
(key === "style" && !isValidStyle(item, palette)),
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
return invalid("context rules with valid bounded patterns, strings, and styles");
|
|
86
|
+
}
|
|
87
|
+
return { ok: true, value: structuredClone(value) as ModuleContextRule[] };
|
|
88
|
+
}
|
|
89
|
+
case "substitutions": {
|
|
90
|
+
if (!Array.isArray(value)) return stringMap(value);
|
|
91
|
+
if (value.length > 64) return invalid("at most 64 substitutions");
|
|
92
|
+
for (const substitution of value) {
|
|
93
|
+
if (
|
|
94
|
+
!record(substitution) ||
|
|
95
|
+
!text(substitution.from, 512) ||
|
|
96
|
+
!text(substitution.to) ||
|
|
97
|
+
Object.keys(substitution).some((key) => key !== "from" && key !== "to" && key !== "regex") ||
|
|
98
|
+
(substitution.regex !== undefined && typeof substitution.regex !== "boolean") ||
|
|
99
|
+
(substitution.regex === true && !validPattern(substitution.from))
|
|
100
|
+
)
|
|
101
|
+
return invalid("bounded from/to substitutions with an optional regex boolean");
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, value: structuredClone(value) as ModuleSubstitution[] };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function stringMap(value: unknown): Result {
|
|
109
|
+
if (!record(value) || Object.values(value).some((item) => typeof item !== "string"))
|
|
110
|
+
return invalid("a table of strings");
|
|
111
|
+
return { ok: true, value: Object.fromEntries(Object.entries(value)) as Record<string, string> };
|
|
112
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "node:fs";
|
|
15
15
|
import { dirname, join } from "node:path";
|
|
16
16
|
import { parse as parseToml, type TomlTable } from "smol-toml";
|
|
17
|
+
import { normalizeModuleOption } from "./config/module-options.js";
|
|
17
18
|
import { type FormatNode, formatVariables, parseFormat, styleVariables } from "./format/formatter.js";
|
|
18
19
|
import { type ColorPalette, isValidStyle, parseColor } from "./format/style.js";
|
|
19
20
|
import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./modules/catalog.js";
|
|
@@ -114,6 +115,11 @@ export function settingsFilePath(agentDir: string): string {
|
|
|
114
115
|
return join(agentDir, CONFIG_FILE_NAME);
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
/** No active Starship document: Pi owns the footer. Module defaults remain available for new drafts. */
|
|
119
|
+
export function nativeFooterConfig(settingsPath: string): LoadedStarshipConfig {
|
|
120
|
+
return { config: cloneBuiltInConfig(), source: "built-in", settingsPath, diagnostics: [] };
|
|
121
|
+
}
|
|
122
|
+
|
|
117
123
|
export function loadStarshipConfig(settingsPath: string): LoadedStarshipConfig {
|
|
118
124
|
let rawDocument: string;
|
|
119
125
|
let snapshot: ConfigDocumentSnapshot;
|
|
@@ -124,12 +130,7 @@ export function loadStarshipConfig(settingsPath: string): LoadedStarshipConfig {
|
|
|
124
130
|
rawDocument = rawBytes.toString("utf8");
|
|
125
131
|
} catch (error) {
|
|
126
132
|
if ((error as NodeJS.ErrnoException).code === "ENOENT" && !existsSync(settingsPath)) {
|
|
127
|
-
return
|
|
128
|
-
config: cloneBuiltInConfig(),
|
|
129
|
-
source: "built-in",
|
|
130
|
-
settingsPath,
|
|
131
|
-
diagnostics: [],
|
|
132
|
-
};
|
|
133
|
+
return nativeFooterConfig(settingsPath);
|
|
133
134
|
}
|
|
134
135
|
return {
|
|
135
136
|
config: cloneBuiltInConfig(),
|
|
@@ -393,7 +394,22 @@ function normalizeModule(
|
|
|
393
394
|
}
|
|
394
395
|
for (const [key, schema] of Object.entries(optionSchemas)) {
|
|
395
396
|
if (value[key] === undefined) continue;
|
|
396
|
-
const normalized = normalizeModuleOption(value[key], schema);
|
|
397
|
+
const normalized = normalizeModuleOption(value[key], schema, activePalette(config));
|
|
398
|
+
if (normalized.ok && name === "directory" && key === "repo_root_format" && typeof normalized.value === "string") {
|
|
399
|
+
try {
|
|
400
|
+
const ast = parseFormat(normalized.value);
|
|
401
|
+
if (
|
|
402
|
+
normalized.value.length > 4_096 ||
|
|
403
|
+
[...formatVariables(ast)].some((variable) => !definition.variables.includes(variable)) ||
|
|
404
|
+
[...styleVariables(ast)].some((variable) => !definition.styleVariables?.includes(variable))
|
|
405
|
+
)
|
|
406
|
+
throw new Error("Unknown format variable");
|
|
407
|
+
validateLiteralStyles(ast, activePalette(config), `${name}.${key}`, diagnostics);
|
|
408
|
+
} catch {
|
|
409
|
+
diagnostics.push(diagnostic("warning", `${name}.${key}`, "Invalid repository-root format; using the default"));
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
397
413
|
if (normalized.ok) module.options[key] = normalized.value;
|
|
398
414
|
else diagnostics.push(diagnostic("warning", `${name}.${key}`, normalized.message));
|
|
399
415
|
}
|
|
@@ -777,58 +793,6 @@ function validateLiteralStyles(
|
|
|
777
793
|
}
|
|
778
794
|
}
|
|
779
795
|
|
|
780
|
-
function normalizeModuleOption(
|
|
781
|
-
value: unknown,
|
|
782
|
-
schema: ModuleOptionSchema,
|
|
783
|
-
): { ok: true; value: ModuleOptionValue } | { ok: false; message: string } {
|
|
784
|
-
switch (schema.kind) {
|
|
785
|
-
case "string":
|
|
786
|
-
return typeof value === "string" && (schema.allowEmpty !== false || value.length > 0)
|
|
787
|
-
? { ok: true, value }
|
|
788
|
-
: { ok: false, message: "Expected a non-empty string; using the default value" };
|
|
789
|
-
case "string-enum":
|
|
790
|
-
return typeof value === "string" && schema.values.includes(value)
|
|
791
|
-
? { ok: true, value }
|
|
792
|
-
: {
|
|
793
|
-
ok: false,
|
|
794
|
-
message: `Expected one of: ${schema.values.join(", ")}; using the default value`,
|
|
795
|
-
};
|
|
796
|
-
case "boolean":
|
|
797
|
-
return typeof value === "boolean"
|
|
798
|
-
? { ok: true, value }
|
|
799
|
-
: { ok: false, message: "Expected boolean; using the default value" };
|
|
800
|
-
case "integer":
|
|
801
|
-
return typeof value === "number" && Number.isInteger(value) && value >= schema.minimum && value <= schema.maximum
|
|
802
|
-
? { ok: true, value }
|
|
803
|
-
: {
|
|
804
|
-
ok: false,
|
|
805
|
-
message: `Expected an integer from ${schema.minimum} through ${schema.maximum}; using the default value`,
|
|
806
|
-
};
|
|
807
|
-
case "string-array": {
|
|
808
|
-
if (
|
|
809
|
-
!Array.isArray(value) ||
|
|
810
|
-
value.some(
|
|
811
|
-
(item) => typeof item !== "string" || item.length === 0 || (!schema.allowNegative && item.startsWith("!")),
|
|
812
|
-
)
|
|
813
|
-
) {
|
|
814
|
-
return {
|
|
815
|
-
ok: false,
|
|
816
|
-
message: "Expected an array of valid strings; using the default value",
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
return { ok: true, value: [...value] as string[] };
|
|
820
|
-
}
|
|
821
|
-
case "string-map": {
|
|
822
|
-
if (!isRecord(value) || Object.values(value).some((item) => typeof item !== "string")) {
|
|
823
|
-
return { ok: false, message: "Expected a table of strings; using the default value" };
|
|
824
|
-
}
|
|
825
|
-
const result: Record<string, string> = {};
|
|
826
|
-
for (const [key, item] of Object.entries(value)) setOwn(result, key, item as string);
|
|
827
|
-
return { ok: true, value: result };
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
796
|
function cloneOptionValue(value: ModuleOptionValue): ModuleOptionValue {
|
|
833
797
|
return typeof value === "object" ? structuredClone(value) : value;
|
|
834
798
|
}
|
package/src/effective-config.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function projectEffectiveConfig(config: StarshipConfig): TomlTable {
|
|
|
33
33
|
}
|
|
34
34
|
table.disabled = module.disabled;
|
|
35
35
|
for (const key of Object.keys(definition.options ?? {})) {
|
|
36
|
-
table[key] = cloneOptionValue(module.options[key]);
|
|
36
|
+
table[key] = cloneOptionValue(module.options[key], definition.name === "directory" && key === "substitutions");
|
|
37
37
|
}
|
|
38
38
|
if (definition.name === "extension_status") {
|
|
39
39
|
table.separator = config.extensionStatus.separator;
|
|
@@ -50,11 +50,12 @@ export function serializeEffectiveConfig(config: StarshipConfig): string {
|
|
|
50
50
|
return stringify(projectEffectiveConfig(config));
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function cloneOptionValue(value: ModuleOptionValue | undefined): TomlValue {
|
|
53
|
+
function cloneOptionValue(value: ModuleOptionValue | undefined, preserveOrder = false): TomlValue {
|
|
54
54
|
if (value === undefined) throw new Error("Missing normalized module option");
|
|
55
|
-
if (Array.isArray(value)) return
|
|
55
|
+
if (Array.isArray(value)) return structuredClone(value) as TomlValue;
|
|
56
56
|
if (typeof value === "object") {
|
|
57
|
-
|
|
57
|
+
const record = value as Readonly<Record<string, string>>;
|
|
58
|
+
return preserveOrder ? { ...record } : sortedRecord(record);
|
|
58
59
|
}
|
|
59
60
|
return value;
|
|
60
61
|
}
|