@narumitw/pi-starship 0.49.2 → 0.49.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +6 -4
  2. package/dist/chunks/chunk-CKNSOLSW.ts +10 -0
  3. package/dist/chunks/chunk-CKNSOLSW.ts.map +7 -0
  4. package/dist/chunks/chunk-G2GG2V6Q.ts +218 -0
  5. package/dist/chunks/chunk-G2GG2V6Q.ts.map +7 -0
  6. package/dist/chunks/chunk-Q6DLIM7H.ts +2492 -0
  7. package/dist/chunks/chunk-Q6DLIM7H.ts.map +7 -0
  8. package/dist/chunks/cloud-JBSZWTB6.ts +142 -0
  9. package/dist/chunks/cloud-JBSZWTB6.ts.map +7 -0
  10. package/dist/chunks/commands-BSQZ2R4M.ts +757 -0
  11. package/dist/chunks/commands-BSQZ2R4M.ts.map +7 -0
  12. package/dist/chunks/deployment-ZNYM4B6W.ts +172 -0
  13. package/dist/chunks/deployment-ZNYM4B6W.ts.map +7 -0
  14. package/dist/chunks/development-TNWZ5SRC.ts +132 -0
  15. package/dist/chunks/development-TNWZ5SRC.ts.map +7 -0
  16. package/dist/chunks/execution-QHAP4U33.ts +132 -0
  17. package/dist/chunks/execution-QHAP4U33.ts.map +7 -0
  18. package/dist/chunks/languages-DPWDCH6Q.ts +184 -0
  19. package/dist/chunks/languages-DPWDCH6Q.ts.map +7 -0
  20. package/dist/chunks/package-MXN2YFLX.ts +104 -0
  21. package/dist/chunks/package-MXN2YFLX.ts.map +7 -0
  22. package/dist/pi-starship.ts +1350 -0
  23. package/dist/pi-starship.ts.map +7 -0
  24. package/package.json +9 -5
  25. package/src/index.ts +1 -1
  26. package/src/command-contract.ts +0 -13
  27. package/src/command-inspector.ts +0 -198
  28. package/src/command-preview.ts +0 -206
  29. package/src/commands.ts +0 -575
  30. package/src/config.ts +0 -794
  31. package/src/format/formatter.ts +0 -275
  32. package/src/format/style.ts +0 -278
  33. package/src/modules/activity.ts +0 -38
  34. package/src/modules/brand.ts +0 -13
  35. package/src/modules/cache.ts +0 -23
  36. package/src/modules/catalog.ts +0 -124
  37. package/src/modules/cloud.ts +0 -74
  38. package/src/modules/context.ts +0 -33
  39. package/src/modules/cost.ts +0 -31
  40. package/src/modules/deployment.ts +0 -61
  41. package/src/modules/development.ts +0 -112
  42. package/src/modules/directory.ts +0 -151
  43. package/src/modules/display.ts +0 -14
  44. package/src/modules/execution.ts +0 -84
  45. package/src/modules/extension-status.ts +0 -93
  46. package/src/modules/fill.ts +0 -14
  47. package/src/modules/git/branch.ts +0 -31
  48. package/src/modules/git/commit.ts +0 -29
  49. package/src/modules/git/metrics.ts +0 -26
  50. package/src/modules/git/runtime.ts +0 -415
  51. package/src/modules/git/state.ts +0 -21
  52. package/src/modules/git/status.ts +0 -87
  53. package/src/modules/git/worktree.ts +0 -16
  54. package/src/modules/github-pr.ts +0 -24
  55. package/src/modules/helpers.ts +0 -5
  56. package/src/modules/index.ts +0 -31
  57. package/src/modules/inspection.ts +0 -138
  58. package/src/modules/languages.ts +0 -87
  59. package/src/modules/model.ts +0 -85
  60. package/src/modules/package.ts +0 -17
  61. package/src/modules/provider.ts +0 -13
  62. package/src/modules/render.ts +0 -166
  63. package/src/modules/terminal.ts +0 -60
  64. package/src/modules/thinking.ts +0 -13
  65. package/src/modules/time.ts +0 -20
  66. package/src/modules/tokens.ts +0 -18
  67. package/src/modules/truncation.ts +0 -37
  68. package/src/modules/turn.ts +0 -13
  69. package/src/modules/types.ts +0 -189
  70. package/src/modules/workspace-helpers.ts +0 -10
  71. package/src/pi-starship.ts +0 -609
  72. package/src/runtime/cloud.ts +0 -166
  73. package/src/runtime/command.ts +0 -123
  74. package/src/runtime/deployment.ts +0 -201
  75. package/src/runtime/development.ts +0 -153
  76. package/src/runtime/execution.ts +0 -151
  77. package/src/runtime/github-pr.ts +0 -332
  78. package/src/runtime/helpers.ts +0 -274
  79. package/src/runtime/languages.ts +0 -205
  80. package/src/runtime/package.ts +0 -112
  81. package/src/runtime/refresh-controller.ts +0 -107
  82. package/src/runtime/types.ts +0 -63
  83. package/src/runtime/workspace.ts +0 -147
  84. package/src/usage.ts +0 -53
package/src/commands.ts DELETED
@@ -1,575 +0,0 @@
1
- import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
3
- import { completeStarshipArguments, STARSHIP_SUBCOMMANDS } from "./command-contract.js";
4
- import { showFooterExplanation } from "./command-inspector.js";
5
- import { type PreviewMenuResult, showPreviewActionMenu } from "./command-preview.js";
6
- import {
7
- atomicRestoreConfigDocument,
8
- atomicSaveConfigDocument,
9
- BUILT_IN_EXAMPLE,
10
- type LoadedStarshipConfig,
11
- removeConfigDocumentIfMatches,
12
- validateConfigDocument,
13
- } from "./config.js";
14
- import { inspectUnavailableModules, type StatuslineInspection } from "./modules/inspection.js";
15
-
16
- const MAIN_ACTIONS = {
17
- customize: "customize",
18
- explain: "explain",
19
- modules: "modules",
20
- configuration: "configuration",
21
- help: "help",
22
- restore: "restore",
23
- } as const;
24
-
25
- const PREVIEW_ACTIONS = {
26
- continue: "continue",
27
- edit: "edit",
28
- cancel: "cancel",
29
- } as const;
30
-
31
- export interface StarshipCommandOptions {
32
- getLoaded(): LoadedStarshipConfig;
33
- getInspection?(): StatuslineInspection | undefined;
34
- apply(loaded: LoadedStarshipConfig, ctx: ExtensionCommandContext): void;
35
- settingsPath: string;
36
- renderPreview?(
37
- loaded: LoadedStarshipConfig,
38
- width: number,
39
- ctx: ExtensionCommandContext,
40
- ): string[];
41
- save?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
42
- restore?: (settingsPath: string, rawDocument: string) => void;
43
- validate?: (settingsPath: string, rawDocument: string) => LoadedStarshipConfig;
44
- getMenuOwner?(): { signal: AbortSignal; isCurrent(): boolean };
45
- }
46
-
47
- interface WorkflowOwner {
48
- signal: AbortSignal;
49
- isCurrent(): boolean;
50
- }
51
-
52
- export function registerStarshipCommand(pi: ExtensionAPI, options: StarshipCommandOptions) {
53
- pi.registerCommand("starship", {
54
- description: "Customize or inspect the native Starship-style footer",
55
- getArgumentCompletions: completeStarshipArguments,
56
- handler: (args, ctx) => handleStarshipCommand(args, ctx, options),
57
- });
58
- }
59
-
60
- export async function handleStarshipCommand(
61
- args: string,
62
- ctx: ExtensionCommandContext,
63
- options: StarshipCommandOptions,
64
- ) {
65
- const normalized = args.trim();
66
- if (!normalized) {
67
- if (ctx.mode === "tui") await showMainMenu(ctx, options);
68
- else showHelp(ctx, options.settingsPath);
69
- return;
70
- }
71
-
72
- const [subcommand = "", ...trailing] = normalized.split(/\s+/u);
73
- const route = subcommand.toLowerCase();
74
- if (trailing.length > 0 || !STARSHIP_SUBCOMMANDS.some((item) => item.value === route)) {
75
- if (canNotify(ctx)) {
76
- const reason =
77
- trailing.length > 0
78
- ? `Unexpected arguments for /starship ${safeText(route)}.`
79
- : `Unknown /starship subcommand: ${safeText(route)}.`;
80
- ctx.ui.notify(`${reason} Usage: /starship [settings|status|help]`, "warning");
81
- }
82
- return;
83
- }
84
- switch (route) {
85
- case "settings":
86
- await editSettings(ctx, options);
87
- return;
88
- case "status":
89
- showStatus(ctx, options);
90
- return;
91
- case "help":
92
- showHelp(ctx, options.settingsPath);
93
- return;
94
- }
95
- }
96
-
97
- async function showMainMenu(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
98
- const fallbackController = new AbortController();
99
- const owner = options.getMenuOwner?.() ?? {
100
- signal: fallbackController.signal,
101
- isCurrent: () => !fallbackController.signal.aborted,
102
- };
103
- type Screen = "main" | "modules" | "configuration" | "help";
104
- type Action = "customize" | "explain" | "restore";
105
- const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({
106
- start: "main",
107
- screens: {
108
- main: () => {
109
- const loaded = options.getLoaded();
110
- const presentation = configurationPresentation(loaded);
111
- return {
112
- kind: "actions",
113
- title: "pi-starship",
114
- lines: [`${presentation.state} · ${presentation.health}`],
115
- items: [
116
- {
117
- id: MAIN_ACTIONS.customize,
118
- label: "Customize footer",
119
- description: `${presentation.state} · preview before applying`,
120
- action: "customize",
121
- },
122
- {
123
- id: MAIN_ACTIONS.explain,
124
- label: "Explain footer",
125
- description: "Why each visible module appears",
126
- action: "explain",
127
- },
128
- {
129
- id: MAIN_ACTIONS.modules,
130
- label: "Modules",
131
- description: "Browse supported modules and current states",
132
- to: "modules",
133
- },
134
- {
135
- id: MAIN_ACTIONS.configuration,
136
- label: "Configuration",
137
- description: presentation.health,
138
- to: "configuration",
139
- },
140
- {
141
- id: MAIN_ACTIONS.help,
142
- label: "Help",
143
- description: "Formats, modules, and commands",
144
- to: "help",
145
- },
146
- {
147
- id: MAIN_ACTIONS.restore,
148
- label: "Restore built-in…",
149
- description: presentation.restoreDescription,
150
- disabled: presentation.restoreDisabled,
151
- action: "restore",
152
- },
153
- ],
154
- hint: "close",
155
- };
156
- },
157
- modules: () => {
158
- const inspection =
159
- options.getInspection?.() ?? inspectUnavailableModules(options.getLoaded().config);
160
- return {
161
- kind: "browse",
162
- title: "Modules",
163
- items: inspection.modules.map((module) => ({
164
- id: module.name,
165
- label: module.name,
166
- statusText: module.state,
167
- description: module.description,
168
- searchText: [...module.variables, ...module.styleFields, ...module.displayRules].join(
169
- " ",
170
- ),
171
- details: [
172
- `Root: ${module.rootReferenced ? "Referenced" : "Not referenced"}`,
173
- `Reachable: ${module.reachable ? "Yes" : "No"}`,
174
- ...modulePreviewDetails(module.preview),
175
- `Reason: ${module.reason}`,
176
- `Variables: ${module.variables.join(", ") || "none"}`,
177
- `Style fields: ${module.styleFields.join(", ") || "none"}`,
178
- `Display rules: ${module.displayRules.join(" · ") || "none"}`,
179
- ],
180
- })),
181
- viewportSize: "adaptive",
182
- hint: "back",
183
- };
184
- },
185
- configuration: () => {
186
- const loaded = options.getLoaded();
187
- const presentation = configurationPresentation(loaded);
188
- return {
189
- kind: "detail",
190
- title: "Configuration",
191
- lines: [
192
- `State: ${presentation.state}`,
193
- `Source: ${presentation.source}`,
194
- `Path: ${safeText(options.settingsPath)}`,
195
- ...diagnosticLines(loaded, true),
196
- ],
197
- hint: "back",
198
- };
199
- },
200
- help: () => ({
201
- kind: "detail",
202
- title: "pi-starship help",
203
- lines: [
204
- "Customize footer opens the TOML editor, then previews and confirms before saving.",
205
- "Explain footer breaks down the modules currently showing from the existing snapshot.",
206
- "Modules searches every supported module and explains its current read-only state.",
207
- "Configuration explains state, source, path, and warnings without changing the footer.",
208
- `Settings: ${safeText(options.settingsPath)}`,
209
- "Docs: https://github.com/narumiruna/pi-extensions/tree/main/extensions/pi-starship",
210
- ],
211
- hint: "back",
212
- }),
213
- },
214
- actions: {
215
- customize: async () => {
216
- const result = await editSettings(ctx, options);
217
- return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
218
- },
219
- explain: async () => {
220
- const result = await showFooterExplanation(ctx, options.getInspection?.(), owner.signal);
221
- if (!isCurrentOwner(owner)) return { kind: "stay" };
222
- return result?.kind === "back" ? { kind: "stay" } : { kind: "close" };
223
- },
224
- restore: async () => {
225
- const presentation = configurationPresentation(options.getLoaded());
226
- if (presentation.restoreDisabled) {
227
- ctx.ui.notify(presentation.restoreDescription, "info");
228
- return { kind: "stay" };
229
- }
230
- const result = await restoreBuiltIn(ctx, options);
231
- return result === "applied" || result === "close" ? { kind: "close" } : { kind: "stay" };
232
- },
233
- },
234
- });
235
- try {
236
- await runMenu(ctx, menu, {
237
- getState: () => undefined,
238
- signal: owner.signal,
239
- isCurrent: owner.isCurrent,
240
- });
241
- } finally {
242
- fallbackController.abort(new DOMException("Starship menu closed", "AbortError"));
243
- }
244
- }
245
-
246
- async function editSettings(
247
- ctx: ExtensionCommandContext,
248
- options: StarshipCommandOptions,
249
- ): Promise<"applied" | "cancel" | "close"> {
250
- const owner = workflowOwner(options);
251
- if (!isCurrentOwner(owner)) return "cancel";
252
- if (ctx.mode !== "tui") {
253
- if (ctx.hasUI) ctx.ui.notify(`Edit settings manually: ${options.settingsPath}`, "info");
254
- return "cancel";
255
- }
256
- let draft = options.getLoaded().rawDocument ?? BUILT_IN_EXAMPLE;
257
- while (true) {
258
- const edited = await ctx.ui.editor("Customize footer — close to preview", draft);
259
- if (!isCurrentOwner(owner) || edited === undefined) return "cancel";
260
- draft = edited;
261
- let validated: LoadedStarshipConfig;
262
- try {
263
- validated = (options.validate ?? validateConfigDocument)(options.settingsPath, draft);
264
- } catch (error) {
265
- ctx.ui.notify(`Footer draft is invalid: ${safeText(formatError(error))}`, "error");
266
- const action = await showPreviewActionMenu(
267
- ctx,
268
- "Configuration needs attention",
269
- () => [safeText(formatError(error)), "The current footer has not changed."],
270
- [
271
- { value: PREVIEW_ACTIONS.edit, label: "Continue editing" },
272
- { value: PREVIEW_ACTIONS.cancel, label: "Discard draft" },
273
- ],
274
- owner.signal,
275
- );
276
- if (!isCurrentOwner(owner)) return "cancel";
277
- if (action?.kind === "closed") return "close";
278
- if (selectedPreviewAction(action) === PREVIEW_ACTIONS.edit) continue;
279
- return "cancel";
280
- }
281
-
282
- const result = await reviewAndApply(ctx, options, validated, "Footer preview", false, owner);
283
- if (result === "edit") continue;
284
- return result;
285
- }
286
- }
287
-
288
- async function restoreBuiltIn(
289
- ctx: ExtensionCommandContext,
290
- options: StarshipCommandOptions,
291
- ): Promise<"applied" | "cancel" | "close"> {
292
- const owner = workflowOwner(options);
293
- if (!isCurrentOwner(owner)) return "cancel";
294
- const validated = (options.validate ?? validateConfigDocument)(
295
- options.settingsPath,
296
- BUILT_IN_EXAMPLE,
297
- );
298
- const result = await reviewAndApply(ctx, options, validated, "Restore preview", true, owner);
299
- return result === "edit" ? "cancel" : result;
300
- }
301
-
302
- async function reviewAndApply(
303
- ctx: ExtensionCommandContext,
304
- options: StarshipCommandOptions,
305
- validated: LoadedStarshipConfig,
306
- title: string,
307
- restore: boolean,
308
- owner: WorkflowOwner,
309
- ): Promise<"applied" | "edit" | "cancel" | "close"> {
310
- while (true) {
311
- const selection = await showPreviewActionMenu(
312
- ctx,
313
- title,
314
- (width) =>
315
- restore
316
- ? restorePreviewBody(ctx, options, validated, width)
317
- : previewBody(ctx, options, validated, width),
318
- [
319
- {
320
- value: PREVIEW_ACTIONS.continue,
321
- label: restore ? "Replace with built-in…" : "Apply changes…",
322
- },
323
- ...(restore ? [] : [{ value: PREVIEW_ACTIONS.edit, label: "Continue editing" }]),
324
- {
325
- value: PREVIEW_ACTIONS.cancel,
326
- label: restore ? "Cancel" : "Discard draft",
327
- },
328
- ],
329
- owner.signal,
330
- );
331
- if (!isCurrentOwner(owner)) return "cancel";
332
- if (selection?.kind === "closed") return "close";
333
- const selected = selectedPreviewAction(selection);
334
- if (selected === PREVIEW_ACTIONS.edit) return "edit";
335
- if (selected !== PREVIEW_ACTIONS.continue) return "cancel";
336
-
337
- const confirmed = await ctx.ui.confirm(
338
- restore ? "Restore built-in footer?" : "Apply footer changes?",
339
- restore
340
- ? `Replace ${safeText(options.settingsPath)} entirely with the built-in configuration? All custom settings, unknown fields, and comments will be removed. No backup is kept after success.`
341
- : "Save this configuration and apply it immediately?",
342
- );
343
- if (!isCurrentOwner(owner)) return "cancel";
344
- if (!confirmed) continue;
345
-
346
- const save = options.save ?? atomicSaveConfigDocument;
347
- const previous = options.getLoaded();
348
- let saved: LoadedStarshipConfig;
349
- try {
350
- saved = save(options.settingsPath, validated.rawDocument ?? BUILT_IN_EXAMPLE);
351
- } catch (error) {
352
- ctx.ui.notify(
353
- `Footer settings were not saved: ${safeText(formatError(error))}. The previous footer remains active.`,
354
- "error",
355
- );
356
- continue;
357
- }
358
-
359
- try {
360
- options.apply(saved, ctx);
361
- } catch (error) {
362
- const rollbackError = restorePreviousConfiguration(ctx, options, previous, saved);
363
- ctx.ui.notify(
364
- rollbackError
365
- ? `Footer settings could not be applied: ${safeText(formatError(error))}. Restoring the previous configuration also failed: ${safeText(formatError(rollbackError))}.`
366
- : `Footer settings could not be applied: ${safeText(formatError(error))}. The previous configuration was restored.`,
367
- "error",
368
- );
369
- continue;
370
- }
371
-
372
- const warningSuffix =
373
- saved.diagnostics.length > 0
374
- ? ` (${saved.diagnostics.length} warning${saved.diagnostics.length === 1 ? "" : "s"})`
375
- : "";
376
- ctx.ui.notify(
377
- restore
378
- ? `Built-in footer restored and applied${warningSuffix}.`
379
- : `Footer settings saved and applied${warningSuffix}.`,
380
- "info",
381
- );
382
- return "applied";
383
- }
384
- }
385
-
386
- function modulePreviewDetails(preview: string): string[] {
387
- const lines = preview ? preview.split("\n") : ["(no current preview)"];
388
- return lines.map((line, index) => `${index === 0 ? "Preview: " : " "}${line}`);
389
- }
390
-
391
- function workflowOwner(options: StarshipCommandOptions): WorkflowOwner {
392
- if (options.getMenuOwner) return options.getMenuOwner();
393
- const controller = new AbortController();
394
- return { signal: controller.signal, isCurrent: () => true };
395
- }
396
-
397
- function isCurrentOwner(owner: WorkflowOwner): boolean {
398
- return !owner.signal.aborted && owner.isCurrent();
399
- }
400
-
401
- function restorePreviousConfiguration(
402
- ctx: ExtensionCommandContext,
403
- options: StarshipCommandOptions,
404
- previous: LoadedStarshipConfig,
405
- saved: LoadedStarshipConfig,
406
- ): unknown {
407
- try {
408
- if (saved.rawDocument === undefined || saved.fileIdentity === undefined) {
409
- throw new Error("The saved settings document identity is unavailable");
410
- }
411
- removeConfigDocumentIfMatches(options.settingsPath, saved.rawDocument, saved.fileIdentity);
412
- if (previous.rawDocument !== undefined) {
413
- (options.restore ?? atomicRestoreConfigDocument)(options.settingsPath, previous.rawDocument);
414
- }
415
- options.apply(previous, ctx);
416
- return undefined;
417
- } catch (error) {
418
- return error;
419
- }
420
- }
421
-
422
- function restorePreviewBody(
423
- ctx: ExtensionCommandContext,
424
- options: StarshipCommandOptions,
425
- loaded: LoadedStarshipConfig,
426
- width: number,
427
- ): string[] {
428
- const current = configurationPresentation(options.getLoaded());
429
- return [
430
- `Current: ${current.state}`,
431
- `Path: ${safeText(options.settingsPath)}`,
432
- "The entire settings document will be replaced, including custom settings, unknown fields, and comments.",
433
- "No backup is kept after a successful restore.",
434
- "",
435
- ...previewBody(ctx, options, loaded, width),
436
- ];
437
- }
438
-
439
- function previewBody(
440
- ctx: ExtensionCommandContext,
441
- options: StarshipCommandOptions,
442
- loaded: LoadedStarshipConfig,
443
- width: number,
444
- ): string[] {
445
- let lines: string[];
446
- try {
447
- lines = options.renderPreview?.(loaded, width, ctx) ?? [
448
- "Live preview is unavailable until the footer is ready.",
449
- "The draft is valid and can still be applied.",
450
- ];
451
- } catch (error) {
452
- lines = [`Preview unavailable: ${safeText(formatError(error))}`];
453
- }
454
- const warning =
455
- loaded.diagnostics.length === 0
456
- ? "Draft validation: Healthy"
457
- : `Draft validation: ${loaded.diagnostics.length} warning${loaded.diagnostics.length === 1 ? "" : "s"}`;
458
- return [...lines, "", warning];
459
- }
460
-
461
- function selectedPreviewAction<Value extends string>(
462
- result: PreviewMenuResult<Value> | undefined,
463
- ): Value | null {
464
- return result?.kind === "selected" ? result.value : null;
465
- }
466
-
467
- function diagnosticLines(loaded: LoadedStarshipConfig, includeSummary: boolean): string[] {
468
- const diagnostics = loaded.diagnostics
469
- .slice(0, 8)
470
- .map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`);
471
- const remaining = loaded.diagnostics.length - diagnostics.length;
472
- return [
473
- ...(includeSummary ? [`Health: ${configurationHealth(loaded)}`] : []),
474
- ...(diagnostics.length > 0 ? diagnostics : ["No configuration warnings."]),
475
- ...(remaining > 0 ? [`${remaining} additional warnings not shown.`] : []),
476
- ];
477
- }
478
-
479
- interface ConfigurationPresentation {
480
- state: string;
481
- source: string;
482
- health: string;
483
- restoreDisabled: boolean;
484
- restoreDescription: string;
485
- }
486
-
487
- function configurationPresentation(loaded: LoadedStarshipConfig): ConfigurationPresentation {
488
- const healthyMissing =
489
- loaded.source === "built-in" &&
490
- loaded.rawDocument === undefined &&
491
- loaded.diagnostics.length === 0;
492
- const savedBuiltIn = loaded.source === "user" && loaded.rawDocument === BUILT_IN_EXAMPLE;
493
- const fallback = loaded.source === "built-in" && loaded.diagnostics.length > 0;
494
- return {
495
- state: healthyMissing
496
- ? "Built-in defaults"
497
- : savedBuiltIn
498
- ? "Saved built-in configuration"
499
- : fallback
500
- ? "Built-in fallback"
501
- : "Custom configuration",
502
- source: healthyMissing
503
- ? "No settings file"
504
- : loaded.source === "user"
505
- ? "User file"
506
- : "Built-in fallback",
507
- health: configurationHealth(loaded),
508
- restoreDisabled: healthyMissing || savedBuiltIn,
509
- restoreDescription: healthyMissing
510
- ? "Already using defaults · no file to replace"
511
- : savedBuiltIn
512
- ? "Built-in configuration already saved"
513
- : fallback
514
- ? "Preview before replacing invalid settings"
515
- : "Preview before replacing the document",
516
- };
517
- }
518
-
519
- function configurationHealth(loaded: LoadedStarshipConfig): string {
520
- const errors = loaded.diagnostics.filter((item) => item.severity === "error").length;
521
- if (errors > 0) return `${errors} error${errors === 1 ? "" : "s"}`;
522
- const warnings = loaded.diagnostics.length;
523
- return warnings === 0 ? "Healthy" : `${warnings} warning${warnings === 1 ? "" : "s"}`;
524
- }
525
-
526
- function showStatus(ctx: ExtensionCommandContext, options: StarshipCommandOptions) {
527
- if (!canNotify(ctx)) return;
528
- const loaded = options.getLoaded();
529
- const diagnostics = loaded.diagnostics
530
- .slice(0, 5)
531
- .map((item) => `${safeText(item.path || "root")}: ${safeText(item.message)}`)
532
- .join("; ");
533
- ctx.ui.notify(
534
- [
535
- `pi-starship source: ${loaded.source}`,
536
- `path: ${options.settingsPath}`,
537
- diagnostics ? `warnings: ${diagnostics}` : "warnings: none",
538
- ].join("\n"),
539
- loaded.diagnostics.length > 0 ? "warning" : "info",
540
- );
541
- }
542
-
543
- function showHelp(ctx: ExtensionCommandContext, settingsPath: string) {
544
- if (!canNotify(ctx)) return;
545
- ctx.ui.notify(
546
- [
547
- "/starship — customize, explain, or inspect the footer in TUI mode",
548
- "/starship settings — customize, preview, and apply TOML",
549
- "/starship status — show source, path, and warnings",
550
- "/starship help — show this help",
551
- `Settings: ${settingsPath}`,
552
- "Format/module docs: https://github.com/narumiruna/pi-extensions/tree/main/extensions/pi-starship",
553
- ].join("\n"),
554
- "info",
555
- );
556
- }
557
-
558
- function canNotify(ctx: ExtensionCommandContext): boolean {
559
- return ctx.mode === "tui" || ctx.hasUI;
560
- }
561
-
562
- function safeText(value: string): string {
563
- return Array.from(value, (character) => {
564
- const codePoint = character.codePointAt(0) ?? 0;
565
- const unsafe =
566
- codePoint <= 0x08 ||
567
- (codePoint >= 0x0b && codePoint <= 0x1f) ||
568
- (codePoint >= 0x7f && codePoint <= 0x9f);
569
- return unsafe ? `\\u${codePoint.toString(16).padStart(4, "0")}` : character;
570
- }).join("");
571
- }
572
-
573
- function formatError(error: unknown): string {
574
- return error instanceof Error ? error.message : String(error);
575
- }