@narumitw/pi-starship 0.44.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +188 -65
  2. package/package.json +2 -2
  3. package/src/command-inspector.ts +470 -0
  4. package/src/command-preview.ts +206 -0
  5. package/src/commands.ts +168 -158
  6. package/src/config.ts +177 -68
  7. package/src/format/style.ts +64 -45
  8. package/src/modules/activity.ts +1 -1
  9. package/src/modules/brand.ts +1 -1
  10. package/src/modules/cache.ts +1 -1
  11. package/src/modules/catalog.ts +62 -3
  12. package/src/modules/context.ts +13 -1
  13. package/src/modules/cost.ts +12 -1
  14. package/src/modules/development.ts +1 -1
  15. package/src/modules/directory.ts +1 -1
  16. package/src/modules/display.ts +14 -0
  17. package/src/modules/execution.ts +12 -1
  18. package/src/modules/extension-status.ts +1 -1
  19. package/src/modules/fill.ts +1 -1
  20. package/src/modules/git/branch.ts +1 -1
  21. package/src/modules/git/commit.ts +1 -1
  22. package/src/modules/git/metrics.ts +8 -2
  23. package/src/modules/git/state.ts +1 -1
  24. package/src/modules/git/status.ts +1 -1
  25. package/src/modules/git/worktree.ts +1 -1
  26. package/src/modules/github-pr.ts +1 -1
  27. package/src/modules/index.ts +13 -1
  28. package/src/modules/inspection.ts +138 -0
  29. package/src/modules/model.ts +1 -1
  30. package/src/modules/provider.ts +1 -1
  31. package/src/modules/render.ts +22 -3
  32. package/src/modules/thinking.ts +1 -1
  33. package/src/modules/time.ts +1 -1
  34. package/src/modules/tokens.ts +1 -1
  35. package/src/modules/turn.ts +1 -1
  36. package/src/modules/types.ts +19 -0
  37. package/src/pi-starship.ts +21 -0
  38. package/src/runtime/execution.ts +15 -3
  39. package/src/runtime/types.ts +2 -0
  40. package/src/runtime/workspace.ts +21 -7
@@ -1,3 +1,4 @@
1
+ import { resolveDisplayStyle } from "./display.js";
1
2
  import { defineModule } from "./types.js";
2
3
 
3
4
  export const costModule = defineModule({
@@ -6,9 +7,19 @@ export const costModule = defineModule({
6
7
  defaults: {
7
8
  format: "[ $symbol \\$$cost( $subscription) ]($style)",
8
9
  symbol: "💸",
9
- style: "fg:meter_fg bg:meter",
10
+ style: "none",
10
11
  disabled: false,
11
12
  },
13
+ displayDefaults: [
14
+ { threshold: 0, style: "bold green", hidden: true },
15
+ { threshold: 1, style: "bold yellow", hidden: false },
16
+ { threshold: 5, style: "bold red", hidden: false },
17
+ ],
18
+ styleVariables: ["style"],
19
+ resolveStyleVariables: ({ runtime, display }) => {
20
+ const style = resolveDisplayStyle(display, runtime.tokenTotals.cost);
21
+ return style === undefined ? undefined : { style };
22
+ },
12
23
  values: ({ runtime }) => ({
13
24
  cost: formatCost(runtime.tokenTotals.cost),
14
25
  subscription: runtime.usingSubscription ? "(sub)" : "",
@@ -43,7 +43,7 @@ export const direnvModule = developmentModule({
43
43
  variables: ["rc_path", "allowed", "loaded"],
44
44
  format: "[$symbol$loaded]($style) ",
45
45
  symbol: "direnv ",
46
- style: "bold 208",
46
+ style: "bold bright-yellow",
47
47
  options: directDetection,
48
48
  });
49
49
 
@@ -7,7 +7,7 @@ export const directoryModule = defineModule({
7
7
  defaults: {
8
8
  format: "[ $symbol $path ]($style)",
9
9
  symbol: "📁",
10
- style: "fg:directory_fg bg:directory",
10
+ style: "cyan bold",
11
11
  disabled: false,
12
12
  },
13
13
  values: ({ runtime }) => ({
@@ -0,0 +1,14 @@
1
+ import type { ModuleDisplayConfig } from "./types.js";
2
+
3
+ export function resolveDisplayStyle(
4
+ display: readonly ModuleDisplayConfig[],
5
+ value: number | null | undefined,
6
+ ): string | undefined {
7
+ if (value === null || value === undefined || !Number.isFinite(value)) return undefined;
8
+ let selected: ModuleDisplayConfig | undefined;
9
+ for (const entry of display) {
10
+ if (entry.threshold > value) continue;
11
+ if (!selected || entry.threshold >= selected.threshold) selected = entry;
12
+ }
13
+ return selected && !selected.hidden ? selected.style : undefined;
14
+ }
@@ -54,9 +54,20 @@ export const usernameModule = defineModule({
54
54
  defaults: {
55
55
  format: "[$user]($style) in ",
56
56
  symbol: "",
57
- style: "yellow bold",
57
+ style: "none",
58
58
  disabled: false,
59
59
  },
60
+ styleDefaults: {
61
+ style_user: "yellow bold",
62
+ style_root: "red bold",
63
+ },
64
+ styleVariables: ["style"],
65
+ resolveStyleVariables: ({ runtime, styles }) => ({
66
+ style:
67
+ runtime.workspace?.styleSelectors?.username === "root"
68
+ ? (styles.style_root ?? "")
69
+ : (styles.style_user ?? ""),
70
+ }),
60
71
  options: {
61
72
  show_always: { kind: "boolean", default: false },
62
73
  aliases: { kind: "string-map", default: {} },
@@ -6,7 +6,7 @@ export const extensionStatusModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$statuses]($style)",
8
8
  symbol: "",
9
- style: "fg:extension",
9
+ style: "dimmed white",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime, extensionStatus }) => {
@@ -6,7 +6,7 @@ export const fillModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$symbol]($style)",
8
8
  symbol: " ",
9
- style: "none",
9
+ style: "bold black",
10
10
  disabled: false,
11
11
  },
12
12
  layout: "fill",
@@ -6,7 +6,7 @@ export const gitBranchModule = defineModule({
6
6
  defaults: {
7
7
  format: "[ $symbol $branch ]($style)",
8
8
  symbol: "🌿",
9
- style: "fg:git_fg bg:git",
9
+ style: "bold purple",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => {
@@ -8,7 +8,7 @@ export const gitCommitModule = defineModule({
8
8
  defaults: {
9
9
  format: "[ ($hash) ]($style)",
10
10
  symbol: "",
11
- style: "fg:git_fg bg:git",
11
+ style: "green bold",
12
12
  disabled: false,
13
13
  },
14
14
  values: ({ runtime }) => {
@@ -4,11 +4,17 @@ export const gitMetricsModule = defineModule({
4
4
  name: "git_metrics",
5
5
  variables: ["symbol", "added", "deleted"],
6
6
  defaults: {
7
- format: "[(+$added)( -$deleted) ]($style)",
7
+ format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
8
8
  symbol: "",
9
- style: "fg:git_fg bg:git",
9
+ style: "none",
10
10
  disabled: true,
11
11
  },
12
+ styleDefaults: {
13
+ added_style: "bold green",
14
+ deleted_style: "bold red",
15
+ },
16
+ styleVariables: ["added_style", "deleted_style"],
17
+ resolveStyleVariables: ({ styles }) => styles,
12
18
  values: ({ runtime }) => {
13
19
  const metrics = runtime.gitMetrics;
14
20
  if (!metrics || (metrics.added === 0 && metrics.deleted === 0)) return undefined;
@@ -6,7 +6,7 @@ export const gitStateModule = defineModule({
6
6
  defaults: {
7
7
  format: "[ ($state( $progress_current/$progress_total)) ]($style)",
8
8
  symbol: "",
9
- style: "bold yellow bg:git",
9
+ style: "bold yellow",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => {
@@ -31,7 +31,7 @@ export const gitStatusModule = defineModule({
31
31
  defaults: {
32
32
  format: "[$all_status( $ahead_behind) ]($style)",
33
33
  symbol: "",
34
- style: "fg:git_fg bg:git",
34
+ style: "red bold",
35
35
  disabled: false,
36
36
  },
37
37
  values: ({ runtime }) => {
@@ -6,7 +6,7 @@ export const gitWorktreeModule = defineModule({
6
6
  defaults: {
7
7
  format: "[ $symbol $name ]($style)",
8
8
  symbol: "🌳",
9
- style: "fg:git_fg bg:git",
9
+ style: "cyan bold",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) =>
@@ -6,7 +6,7 @@ export const githubPrModule = defineModule({
6
6
  defaults: {
7
7
  format: "[ $symbol$link( · $status) ]($style)",
8
8
  symbol: "PR ",
9
- style: "fg:git_fg bg:git",
9
+ style: "bold blue",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => {
@@ -1,6 +1,18 @@
1
- export { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
1
+ export {
2
+ type CatalogModuleDefinition,
3
+ MODULE_DEFINITIONS,
4
+ MODULE_NAMES,
5
+ type ModuleName,
6
+ } from "./catalog.js";
2
7
  export { formatExtensionStatus } from "./extension-status.js";
3
8
  export { formatCount } from "./helpers.js";
9
+ export {
10
+ inspectStatuslineModules,
11
+ inspectUnavailableModules,
12
+ type ModuleInspection,
13
+ type ModuleInspectionState,
14
+ type StatuslineInspection,
15
+ } from "./inspection.js";
4
16
  export { shortenModel } from "./model.js";
5
17
  export { reachableModuleRequirements, renderStatusline } from "./render.js";
6
18
  export type {
@@ -0,0 +1,138 @@
1
+ import { stripVTControlCharacters } from "node:util";
2
+ import type { StarshipConfig } from "../config.js";
3
+ import { formatVariables } from "../format/formatter.js";
4
+ import { MODULE_DEFINITIONS, type ModuleName } from "./catalog.js";
5
+ import { reachableModuleRequirements, renderStatusline } from "./render.js";
6
+ import type { StarshipRuntimeSnapshot } from "./types.js";
7
+
8
+ export type ModuleInspectionState =
9
+ | "Showing"
10
+ | "Empty"
11
+ | "Disabled"
12
+ | "Not in format"
13
+ | "Unavailable";
14
+
15
+ export interface ModuleInspection {
16
+ name: ModuleName;
17
+ description: string;
18
+ state: ModuleInspectionState;
19
+ preview: string;
20
+ variables: readonly string[];
21
+ styleFields: readonly string[];
22
+ displayRules: readonly string[];
23
+ rootReferenced: boolean;
24
+ reachable: boolean;
25
+ reason: string;
26
+ }
27
+
28
+ export interface StatuslineInspection {
29
+ modules: readonly ModuleInspection[];
30
+ showing: readonly ModuleInspection[];
31
+ }
32
+
33
+ export function inspectStatuslineModules(
34
+ config: StarshipConfig,
35
+ runtime: StarshipRuntimeSnapshot,
36
+ width = 80,
37
+ ): StatuslineInspection {
38
+ const rendered = renderStatusline(config, runtime, width);
39
+ const requirements = reachableModuleRequirements(config);
40
+ const rootVariables = formatVariables(config.formatAst);
41
+ const includeAll = rootVariables.has("all");
42
+ const modules = MODULE_DEFINITIONS.map((definition): ModuleInspection => {
43
+ const module = config.modules[definition.name];
44
+ const reachable = requirements.has(definition.name);
45
+ const preview = plainPreview(
46
+ rendered.modules[definition.name].map((chunk) => chunk.text).join(""),
47
+ );
48
+ const state = module.disabled
49
+ ? "Disabled"
50
+ : !reachable
51
+ ? "Not in format"
52
+ : preview.length > 0
53
+ ? "Showing"
54
+ : "Empty";
55
+ return moduleInspection(
56
+ config,
57
+ definition,
58
+ state,
59
+ preview,
60
+ includeAll || rootVariables.has(definition.name),
61
+ reachable,
62
+ );
63
+ });
64
+ return {
65
+ modules,
66
+ showing: modules.filter((module) => module.state === "Showing"),
67
+ };
68
+ }
69
+
70
+ export function inspectUnavailableModules(config: StarshipConfig): StatuslineInspection {
71
+ const requirements = reachableModuleRequirements(config);
72
+ const rootVariables = formatVariables(config.formatAst);
73
+ const includeAll = rootVariables.has("all");
74
+ return {
75
+ modules: MODULE_DEFINITIONS.map((definition) => {
76
+ const module = config.modules[definition.name];
77
+ const reachable = requirements.has(definition.name);
78
+ const state = module.disabled ? "Disabled" : reachable ? "Unavailable" : "Not in format";
79
+ return moduleInspection(
80
+ config,
81
+ definition,
82
+ state,
83
+ "",
84
+ includeAll || rootVariables.has(definition.name),
85
+ reachable,
86
+ );
87
+ }),
88
+ showing: [],
89
+ };
90
+ }
91
+
92
+ function moduleInspection(
93
+ config: StarshipConfig,
94
+ definition: (typeof MODULE_DEFINITIONS)[number],
95
+ state: ModuleInspectionState,
96
+ preview: string,
97
+ rootReferenced: boolean,
98
+ reachable: boolean,
99
+ ): ModuleInspection {
100
+ const module = config.modules[definition.name];
101
+ return {
102
+ name: definition.name,
103
+ description: definition.description,
104
+ state,
105
+ preview,
106
+ variables: [...definition.variables],
107
+ styleFields: ["style", ...Object.keys(module.styles)],
108
+ displayRules: module.display.map(
109
+ (rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`,
110
+ ),
111
+ rootReferenced,
112
+ reachable,
113
+ reason: inspectionReason(state),
114
+ };
115
+ }
116
+
117
+ function inspectionReason(state: ModuleInspectionState): string {
118
+ switch (state) {
119
+ case "Showing":
120
+ return "Rendered in the current footer.";
121
+ case "Empty":
122
+ return "Referenced by the root format, but the current snapshot produced no output.";
123
+ case "Disabled":
124
+ return "Disabled by this module's configuration.";
125
+ case "Not in format":
126
+ return "Not referenced by the root format or $all.";
127
+ case "Unavailable":
128
+ return "Current footer inspection is unavailable; no collector failure was inferred.";
129
+ }
130
+ }
131
+
132
+ function plainPreview(value: string): string {
133
+ return Array.from(stripVTControlCharacters(value), (character) => {
134
+ const codePoint = character.codePointAt(0) ?? 0;
135
+ if (character === "\n") return character;
136
+ return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? " " : character;
137
+ }).join("");
138
+ }
@@ -10,7 +10,7 @@ export const modelModule = defineModule({
10
10
  defaults: {
11
11
  format: "[$symbol $model ]($style)",
12
12
  symbol: "🤖",
13
- style: "fg:header_fg bg:header",
13
+ style: "bold blue",
14
14
  disabled: false,
15
15
  },
16
16
  options: {
@@ -6,7 +6,7 @@ export const providerModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$symbol $provider ]($style)",
8
8
  symbol: "🔌",
9
- style: "fg:header_fg bg:header",
9
+ style: "bold blue",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => (runtime.model ? { provider: runtime.model.provider } : undefined),
@@ -24,12 +24,30 @@ export function renderStatusline(
24
24
  }
25
25
  for (const definition of MODULE_DEFINITIONS) {
26
26
  const name = definition.name;
27
+ const module = config.modules[name];
27
28
  const values = definition.values(valueContext(config, name, runtime));
28
29
  if (!values) continue;
29
- const rendered = renderModule(config.modules[name], values, palette);
30
+ const styleVariables = definition.resolveStyleVariables
31
+ ? definition.resolveStyleVariables({
32
+ runtime,
33
+ values,
34
+ style: module.style,
35
+ styles: module.styles,
36
+ display: module.display,
37
+ })
38
+ : { style: module.style };
39
+ if (!styleVariables) continue;
40
+ const contentValues = Object.fromEntries(
41
+ definition.variables.flatMap((variable) =>
42
+ variable !== "symbol" && Object.hasOwn(values, variable)
43
+ ? [[variable, values[variable]]]
44
+ : [],
45
+ ),
46
+ );
47
+ const rendered = renderModule(module, contentValues, styleVariables, palette);
30
48
  modules[name] = rendered;
31
49
  layoutModules[name] =
32
- definition.layout === "fill" && !config.modules[name].disabled
50
+ definition.layout === "fill" && !module.disabled
33
51
  ? [{ type: "fill", pattern: rendered }]
34
52
  : rendered;
35
53
  }
@@ -65,12 +83,13 @@ function valueContext(
65
83
  function renderModule(
66
84
  module: ModuleConfig,
67
85
  values: Readonly<Record<string, FormatValue>>,
86
+ styleVariables: Readonly<Record<string, string>>,
68
87
  palette: Readonly<Record<string, string>>,
69
88
  ): StyledChunk[] {
70
89
  if (module.disabled) return [];
71
90
  return renderFormat(module.formatAst, {
72
91
  variables: { symbol: module.symbol, ...values },
73
- styleVariables: { style: module.style },
92
+ styleVariables,
74
93
  palette,
75
94
  }).filter((chunk): chunk is StyledChunk => !isFillChunk(chunk));
76
95
  }
@@ -6,7 +6,7 @@ export const thinkingModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$symbol $level ]($style)",
8
8
  symbol: "🧠",
9
- style: "fg:header_fg bg:header",
9
+ style: "bold purple",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => ({ level: runtime.thinkingLevel }),
@@ -6,7 +6,7 @@ export const timeModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$symbol $time ]($style)",
8
8
  symbol: "🕒",
9
- style: "fg:meter_fg bg:meter",
9
+ style: "bold yellow",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => ({ time: formatTime(runtime.now) }),
@@ -7,7 +7,7 @@ export const tokensModule = defineModule({
7
7
  defaults: {
8
8
  format: "[$symbol ↑$input ↓$output ]($style)",
9
9
  symbol: "🔢",
10
- style: "fg:runtime_fg bg:runtime",
10
+ style: "bold cyan",
11
11
  disabled: false,
12
12
  },
13
13
  values: ({ runtime }) => ({
@@ -6,7 +6,7 @@ export const turnModule = defineModule({
6
6
  defaults: {
7
7
  format: "[$symbol #$count ]($style)",
8
8
  symbol: "🔁",
9
- style: "fg:meter_fg bg:meter",
9
+ style: "bold purple",
10
10
  disabled: false,
11
11
  },
12
12
  values: ({ runtime }) => ({ count: `${runtime.turnCount}` }),
@@ -73,6 +73,7 @@ export interface GitSnapshot {
73
73
 
74
74
  export interface WorkspaceSnapshot {
75
75
  modules: Readonly<Record<string, Readonly<Record<string, string>>>>;
76
+ styleSelectors?: Readonly<Record<string, string>>;
76
77
  }
77
78
 
78
79
  export interface StarshipRuntimeSnapshot {
@@ -138,6 +139,12 @@ export type ModuleOptionSchema =
138
139
  | { kind: "string-array"; default: readonly string[]; allowNegative?: boolean }
139
140
  | { kind: "string-map"; default: Readonly<Record<string, string>> };
140
141
 
142
+ export interface ModuleDisplayConfig {
143
+ threshold: number;
144
+ style: string;
145
+ hidden: boolean;
146
+ }
147
+
141
148
  export interface ModuleDefaults {
142
149
  format: string;
143
150
  symbol: string;
@@ -145,10 +152,22 @@ export interface ModuleDefaults {
145
152
  disabled: boolean;
146
153
  }
147
154
 
155
+ export interface ModuleStyleContext {
156
+ runtime: StarshipRuntimeSnapshot;
157
+ values: Readonly<Record<string, string>>;
158
+ style: string;
159
+ styles: Readonly<Record<string, string>>;
160
+ display: readonly ModuleDisplayConfig[];
161
+ }
162
+
148
163
  export interface ModuleDefinition<Name extends string> {
149
164
  name: Name;
150
165
  variables: readonly string[];
151
166
  defaults: ModuleDefaults;
167
+ styleDefaults?: Readonly<Record<string, string>>;
168
+ displayDefaults?: readonly ModuleDisplayConfig[];
169
+ styleVariables?: readonly string[];
170
+ resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
152
171
  options?: Readonly<Record<string, ModuleOptionSchema>>;
153
172
  layout?: "fill";
154
173
  values(context: ModuleValueContext): Record<string, string> | undefined;
@@ -17,9 +17,11 @@ import { gitSnapshotEqual, readGitSnapshot } from "./modules/git/runtime.js";
17
17
  import {
18
18
  type GithubPrSnapshot,
19
19
  type GitSnapshot,
20
+ inspectStatuslineModules,
20
21
  reachableModuleRequirements,
21
22
  renderStatusline,
22
23
  type StarshipRuntimeSnapshot,
24
+ type StatuslineInspection,
23
25
  type WorkspaceSnapshot,
24
26
  } from "./modules/index.js";
25
27
  import { execWorkspaceCommand } from "./runtime/command.js";
@@ -48,6 +50,8 @@ interface RuntimeState {
48
50
  workspace?: WorkspaceSnapshot;
49
51
  requestRender?: () => void;
50
52
  renderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];
53
+ inspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;
54
+ footerWidth?: number;
51
55
  }
52
56
 
53
57
  interface RefreshTarget {
@@ -242,6 +246,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
242
246
  runtime.workspace = undefined;
243
247
  runtime.requestRender = undefined;
244
248
  runtime.renderPreview = undefined;
249
+ runtime.inspect = undefined;
250
+ runtime.footerWidth = undefined;
245
251
  activeTarget = ctx.mode === "tui" ? target : undefined;
246
252
  ctx.ui.setStatus("starship", undefined);
247
253
  if (!activeTarget || !loaded) return;
@@ -258,6 +264,12 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
258
264
  width,
259
265
  );
260
266
  };
267
+ runtime.inspect = (current) =>
268
+ inspectStatuslineModules(
269
+ current.config,
270
+ runtimeSnapshot(ctx, footerData, runtime),
271
+ runtime.footerWidth ?? 80,
272
+ );
261
273
  const unsubscribe = footerData.onBranchChange(() => {
262
274
  if (!isActiveTarget(target)) return;
263
275
  runtime.git = undefined;
@@ -292,10 +304,13 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
292
304
  runtime.workspace = undefined;
293
305
  runtime.requestRender = undefined;
294
306
  runtime.renderPreview = undefined;
307
+ runtime.inspect = undefined;
308
+ runtime.footerWidth = undefined;
295
309
  }
296
310
  },
297
311
  invalidate() {},
298
312
  render(width: number): string[] {
313
+ runtime.footerWidth = width;
299
314
  if (!loaded) return [];
300
315
  const snapshot = runtimeSnapshot(ctx, footerData, runtime);
301
316
  return wrapFormattedStatusline(
@@ -313,6 +328,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
313
328
  registerStarshipCommand(pi, {
314
329
  settingsPath: configPath,
315
330
  getLoaded: () => loaded ?? loadStarshipConfig(configPath),
331
+ getInspection: () => {
332
+ const current = loaded ?? loadStarshipConfig(configPath);
333
+ return runtime.inspect?.(current);
334
+ },
316
335
  getMenuOwner: () => {
317
336
  const generation = sessionGeneration;
318
337
  return {
@@ -371,6 +390,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
371
390
  runtime.workspace = undefined;
372
391
  runtime.requestRender = undefined;
373
392
  runtime.renderPreview = undefined;
393
+ runtime.inspect = undefined;
394
+ runtime.footerWidth = undefined;
374
395
  ctx.ui.setFooter(undefined);
375
396
  ctx.ui.setStatus("starship", undefined);
376
397
  });
@@ -6,14 +6,23 @@ import {
6
6
  optionStrings,
7
7
  safeMetadata,
8
8
  } from "./helpers.js";
9
- import type { CollectorContext, MutableModuleSnapshot } from "./types.js";
9
+ import {
10
+ type CollectorContext,
11
+ type MutableModuleSnapshot,
12
+ PRIVATE_STYLE_SELECTOR,
13
+ } from "./types.js";
10
14
 
11
15
  export async function collectExecution(context: CollectorContext): Promise<MutableModuleSnapshot> {
12
16
  if (context.input.reason === "periodic" && context.input.previous) {
13
17
  const retained: MutableModuleSnapshot = {};
14
18
  for (const name of ["os", "container", "hostname", "username"] as const) {
15
19
  const values = context.input.previous.modules[name];
16
- if (context.needs(name) && values) retained[name] = { ...values };
20
+ if (!context.needs(name) || !values) continue;
21
+ const selector = context.input.previous.styleSelectors?.[name];
22
+ retained[name] = {
23
+ ...values,
24
+ ...(selector === undefined ? {} : { [PRIVATE_STYLE_SELECTOR]: selector }),
25
+ };
17
26
  }
18
27
  return retained;
19
28
  }
@@ -116,7 +125,10 @@ function usernameValues(context: CollectorContext): Record<string, string> | und
116
125
  ) {
117
126
  return undefined;
118
127
  }
119
- return { user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user };
128
+ return {
129
+ user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user,
130
+ [PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user",
131
+ };
120
132
  }
121
133
 
122
134
  function isSsh(context: CollectorContext): boolean {
@@ -58,4 +58,6 @@ export interface CollectorContext {
58
58
  needs(name: ModuleName, variable?: string): boolean;
59
59
  }
60
60
 
61
+ export const PRIVATE_STYLE_SELECTOR = "__pi_style_selector";
62
+
61
63
  export type MutableModuleSnapshot = Record<string, Record<string, string>>;
@@ -8,11 +8,12 @@ import { collectExecution } from "./execution.js";
8
8
  import { createFileSystem } from "./helpers.js";
9
9
  import { collectLanguages } from "./languages.js";
10
10
  import { collectPackage } from "./package.js";
11
- import type {
12
- CollectorContext,
13
- MutableModuleSnapshot,
14
- WorkspaceEntry,
15
- WorkspaceRefreshInput,
11
+ import {
12
+ type CollectorContext,
13
+ type MutableModuleSnapshot,
14
+ PRIVATE_STYLE_SELECTOR,
15
+ type WorkspaceEntry,
16
+ type WorkspaceRefreshInput,
16
17
  } from "./types.js";
17
18
 
18
19
  export { parseTerraformVersion } from "./deployment.js";
@@ -108,6 +109,19 @@ function mergeModules(target: MutableModuleSnapshot, source: MutableModuleSnapsh
108
109
  }
109
110
 
110
111
  function freezeSnapshot(modules: MutableModuleSnapshot): WorkspaceSnapshot {
111
- for (const values of Object.values(modules)) Object.freeze(values);
112
- return Object.freeze({ modules: Object.freeze(modules) });
112
+ const styleSelectors: Record<string, string> = {};
113
+ for (const [name, values] of Object.entries(modules)) {
114
+ const selector = Object.hasOwn(values, PRIVATE_STYLE_SELECTOR)
115
+ ? values[PRIVATE_STYLE_SELECTOR]
116
+ : undefined;
117
+ delete values[PRIVATE_STYLE_SELECTOR];
118
+ if (selector !== undefined) styleSelectors[name] = selector;
119
+ Object.freeze(values);
120
+ }
121
+ return Object.freeze({
122
+ modules: Object.freeze(modules),
123
+ ...(Object.keys(styleSelectors).length > 0
124
+ ? { styleSelectors: Object.freeze(styleSelectors) }
125
+ : {}),
126
+ });
113
127
  }