@narumitw/pi-starship 0.44.0 → 0.46.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 (44) hide show
  1. package/README.md +246 -71
  2. package/package.json +2 -2
  3. package/src/command-inspector.ts +198 -0
  4. package/src/command-preview.ts +206 -0
  5. package/src/commands.ts +190 -154
  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 +24 -7
  15. package/src/modules/directory.ts +141 -7
  16. package/src/modules/display.ts +14 -0
  17. package/src/modules/execution.ts +13 -2
  18. package/src/modules/extension-status.ts +1 -1
  19. package/src/modules/fill.ts +1 -1
  20. package/src/modules/git/branch.ts +14 -5
  21. package/src/modules/git/commit.ts +10 -3
  22. package/src/modules/git/metrics.ts +8 -2
  23. package/src/modules/git/runtime.ts +3 -0
  24. package/src/modules/git/state.ts +1 -1
  25. package/src/modules/git/status.ts +1 -1
  26. package/src/modules/git/worktree.ts +1 -1
  27. package/src/modules/github-pr.ts +1 -1
  28. package/src/modules/index.ts +13 -1
  29. package/src/modules/inspection.ts +138 -0
  30. package/src/modules/model.ts +15 -65
  31. package/src/modules/provider.ts +1 -1
  32. package/src/modules/render.ts +22 -3
  33. package/src/modules/terminal.ts +60 -0
  34. package/src/modules/thinking.ts +1 -1
  35. package/src/modules/time.ts +1 -1
  36. package/src/modules/tokens.ts +1 -1
  37. package/src/modules/truncation.ts +37 -0
  38. package/src/modules/turn.ts +1 -1
  39. package/src/modules/types.ts +22 -0
  40. package/src/pi-starship.ts +27 -1
  41. package/src/runtime/development.ts +1 -2
  42. package/src/runtime/execution.ts +19 -9
  43. package/src/runtime/types.ts +2 -0
  44. package/src/runtime/workspace.ts +21 -7
@@ -1,3 +1,4 @@
1
+ import { sanitizeTerminalText } from "./terminal.js";
1
2
  import { defineModule } from "./types.js";
2
3
 
3
4
  const TRUNCATION_DIRECTIONS = ["start", "middle", "end"] as const;
@@ -10,7 +11,7 @@ export const modelModule = defineModule({
10
11
  defaults: {
11
12
  format: "[$symbol $model ]($style)",
12
13
  symbol: "🤖",
13
- style: "fg:header_fg bg:header",
14
+ style: "bold blue",
14
15
  disabled: false,
15
16
  },
16
17
  options: {
@@ -21,6 +22,7 @@ export const modelModule = defineModule({
21
22
  default: "end",
22
23
  values: TRUNCATION_DIRECTIONS,
23
24
  },
25
+ model_aliases: { kind: "string-map", default: {} },
24
26
  },
25
27
  values: ({ runtime, options }) => {
26
28
  if (!runtime.model) return undefined;
@@ -29,8 +31,17 @@ export const modelModule = defineModule({
29
31
  const direction = isTruncationDirection(options.truncation_direction)
30
32
  ? options.truncation_direction
31
33
  : "end";
34
+ const aliases = options.model_aliases;
35
+ const aliasMap =
36
+ aliases && typeof aliases === "object" && !Array.isArray(aliases)
37
+ ? (aliases as Readonly<Record<string, string>>)
38
+ : undefined;
39
+ const alias =
40
+ aliasMap && Object.hasOwn(aliasMap, runtime.model.id)
41
+ ? aliasMap[runtime.model.id]
42
+ : undefined;
32
43
  return {
33
- model: truncateModel(shortenModel(runtime.model.id), length, symbol, direction),
44
+ model: truncateModel(alias ?? shortenModel(runtime.model.id), length, symbol, direction),
34
45
  };
35
46
  },
36
47
  });
@@ -41,11 +52,11 @@ export function truncateModel(
41
52
  symbol: string,
42
53
  direction: TruncationDirection,
43
54
  ): string {
44
- const safeModel = sanitizeModelDisplay(model);
55
+ const safeModel = sanitizeTerminalText(model);
45
56
  if (length === 0) return safeModel;
46
57
  const graphemes = [...graphemeSegmenter.segment(safeModel)].map(({ segment }) => segment);
47
58
  if (graphemes.length <= length) return safeModel;
48
- const safeSymbol = sanitizeModelDisplay(symbol);
59
+ const safeSymbol = sanitizeTerminalText(symbol);
49
60
 
50
61
  switch (direction) {
51
62
  case "start":
@@ -61,67 +72,6 @@ export function truncateModel(
61
72
  }
62
73
  }
63
74
 
64
- function sanitizeModelDisplay(value: string): string {
65
- let result = "";
66
- for (let index = 0; index < value.length; ) {
67
- const codePoint = value.codePointAt(index) ?? 0;
68
- const character = String.fromCodePoint(codePoint);
69
- if (codePoint === 0x1b || codePoint === 0x9b || codePoint === 0x9d) {
70
- index = skipTerminalEscape(value, index, codePoint);
71
- continue;
72
- }
73
- if (
74
- codePoint <= 0x1f ||
75
- (codePoint >= 0x7f && codePoint <= 0x9f) ||
76
- codePoint === 0x2028 ||
77
- codePoint === 0x2029
78
- ) {
79
- if (
80
- codePoint === 0x09 ||
81
- codePoint === 0x0a ||
82
- codePoint === 0x0d ||
83
- codePoint === 0x85 ||
84
- codePoint === 0x2028 ||
85
- codePoint === 0x2029
86
- ) {
87
- result += " ";
88
- }
89
- index += character.length;
90
- continue;
91
- }
92
- result += character;
93
- index += character.length;
94
- }
95
- return result;
96
- }
97
-
98
- function skipTerminalEscape(value: string, start: number, codePoint: number): number {
99
- let index = start + 1;
100
- const next = value.charCodeAt(index);
101
- const isOsc = codePoint === 0x9d || (codePoint === 0x1b && next === 0x5d);
102
- if (isOsc) {
103
- if (codePoint === 0x1b) index += 1;
104
- while (index < value.length) {
105
- const current = value.charCodeAt(index);
106
- if (current === 0x07 || current === 0x9c) return index + 1;
107
- if (current === 0x1b && value.charCodeAt(index + 1) === 0x5c) return index + 2;
108
- index += 1;
109
- }
110
- return index;
111
- }
112
- const isCsi = codePoint === 0x9b || (codePoint === 0x1b && next === 0x5b);
113
- if (isCsi) {
114
- if (codePoint === 0x1b) index += 1;
115
- while (index < value.length) {
116
- const current = value.charCodeAt(index);
117
- index += 1;
118
- if (current >= 0x40 && current <= 0x7e) break;
119
- }
120
- return index;
121
- }
122
- return Math.min(value.length, start + (codePoint === 0x1b ? 2 : 1));
123
- }
124
-
125
75
  function isTruncationDirection(value: unknown): value is TruncationDirection {
126
76
  return TRUNCATION_DIRECTIONS.includes(value as TruncationDirection);
127
77
  }
@@ -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
  }
@@ -0,0 +1,60 @@
1
+ export function sanitizeTerminalText(value: string): string {
2
+ let result = "";
3
+ for (let index = 0; index < value.length; ) {
4
+ const codePoint = value.codePointAt(index) ?? 0;
5
+ const character = String.fromCodePoint(codePoint);
6
+ if (codePoint === 0x1b || codePoint === 0x9b || codePoint === 0x9d) {
7
+ index = skipTerminalEscape(value, index, codePoint);
8
+ continue;
9
+ }
10
+ if (
11
+ codePoint <= 0x1f ||
12
+ (codePoint >= 0x7f && codePoint <= 0x9f) ||
13
+ codePoint === 0x2028 ||
14
+ codePoint === 0x2029
15
+ ) {
16
+ if (
17
+ codePoint === 0x09 ||
18
+ codePoint === 0x0a ||
19
+ codePoint === 0x0d ||
20
+ codePoint === 0x85 ||
21
+ codePoint === 0x2028 ||
22
+ codePoint === 0x2029
23
+ ) {
24
+ result += " ";
25
+ }
26
+ index += character.length;
27
+ continue;
28
+ }
29
+ result += character;
30
+ index += character.length;
31
+ }
32
+ return result;
33
+ }
34
+
35
+ function skipTerminalEscape(value: string, start: number, codePoint: number): number {
36
+ let index = start + 1;
37
+ const next = value.charCodeAt(index);
38
+ const isOsc = codePoint === 0x9d || (codePoint === 0x1b && next === 0x5d);
39
+ if (isOsc) {
40
+ if (codePoint === 0x1b) index += 1;
41
+ while (index < value.length) {
42
+ const current = value.charCodeAt(index);
43
+ if (current === 0x07 || current === 0x9c) return index + 1;
44
+ if (current === 0x1b && value.charCodeAt(index + 1) === 0x5c) return index + 2;
45
+ index += 1;
46
+ }
47
+ return index;
48
+ }
49
+ const isCsi = codePoint === 0x9b || (codePoint === 0x1b && next === 0x5b);
50
+ if (isCsi) {
51
+ if (codePoint === 0x1b) index += 1;
52
+ while (index < value.length) {
53
+ const current = value.charCodeAt(index);
54
+ index += 1;
55
+ if (current >= 0x40 && current <= 0x7e) break;
56
+ }
57
+ return index;
58
+ }
59
+ return Math.min(value.length, start + (codePoint === 0x1b ? 2 : 1));
60
+ }
@@ -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 }) => ({
@@ -0,0 +1,37 @@
1
+ import { sep } from "node:path";
2
+
3
+ const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
4
+
5
+ export function graphemes(value: string): string[] {
6
+ return [...graphemeSegmenter.segment(value)].map(({ segment }) => segment);
7
+ }
8
+
9
+ export function firstGrapheme(value: string): string {
10
+ return graphemes(value)[0] ?? "";
11
+ }
12
+
13
+ export function truncateLeadingGraphemes(value: string, length: number, symbol: string): string {
14
+ if (length <= 0) return value;
15
+ const parts = graphemes(value);
16
+ if (parts.length <= length) return value;
17
+ return `${parts.slice(0, length).join("")}${firstGrapheme(symbol)}`;
18
+ }
19
+
20
+ export function toSlashPath(value: string): string {
21
+ return sep === "\\" ? value.replaceAll("\\", "/") : value;
22
+ }
23
+
24
+ export function truncatePathComponents(
25
+ value: string,
26
+ length: number,
27
+ ): { value: string; truncated: boolean } {
28
+ if (length <= 0) return { value, truncated: false };
29
+ const normalized = toSlashPath(value);
30
+ const components = normalized.split("/").filter((component) => component.length > 0);
31
+ if (components.length <= length) return { value: normalized, truncated: false };
32
+ return { value: components.slice(-length).join("/"), truncated: true };
33
+ }
34
+
35
+ export function useNativePathSeparator(value: string): string {
36
+ return sep === "/" ? value : value.replaceAll("/", sep);
37
+ }
@@ -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}` }),
@@ -63,6 +63,7 @@ export interface GithubPrSnapshot {
63
63
  }
64
64
 
65
65
  export interface GitSnapshot {
66
+ root?: string;
66
67
  branch?: GitBranchSnapshot;
67
68
  commit?: GitCommitSnapshot;
68
69
  state?: GitStateSnapshot;
@@ -73,10 +74,13 @@ export interface GitSnapshot {
73
74
 
74
75
  export interface WorkspaceSnapshot {
75
76
  modules: Readonly<Record<string, Readonly<Record<string, string>>>>;
77
+ styleSelectors?: Readonly<Record<string, string>>;
76
78
  }
77
79
 
78
80
  export interface StarshipRuntimeSnapshot {
79
81
  cwd: string;
82
+ homeDir?: string;
83
+ gitRoot?: string;
80
84
  model?: { provider: string; id: string };
81
85
  thinkingLevel: string;
82
86
  turnCount: number;
@@ -138,6 +142,12 @@ export type ModuleOptionSchema =
138
142
  | { kind: "string-array"; default: readonly string[]; allowNegative?: boolean }
139
143
  | { kind: "string-map"; default: Readonly<Record<string, string>> };
140
144
 
145
+ export interface ModuleDisplayConfig {
146
+ threshold: number;
147
+ style: string;
148
+ hidden: boolean;
149
+ }
150
+
141
151
  export interface ModuleDefaults {
142
152
  format: string;
143
153
  symbol: string;
@@ -145,10 +155,22 @@ export interface ModuleDefaults {
145
155
  disabled: boolean;
146
156
  }
147
157
 
158
+ export interface ModuleStyleContext {
159
+ runtime: StarshipRuntimeSnapshot;
160
+ values: Readonly<Record<string, string>>;
161
+ style: string;
162
+ styles: Readonly<Record<string, string>>;
163
+ display: readonly ModuleDisplayConfig[];
164
+ }
165
+
148
166
  export interface ModuleDefinition<Name extends string> {
149
167
  name: Name;
150
168
  variables: readonly string[];
151
169
  defaults: ModuleDefaults;
170
+ styleDefaults?: Readonly<Record<string, string>>;
171
+ displayDefaults?: readonly ModuleDisplayConfig[];
172
+ styleVariables?: readonly string[];
173
+ resolveStyleVariables?(context: ModuleStyleContext): Readonly<Record<string, string>> | undefined;
152
174
  options?: Readonly<Record<string, ModuleOptionSchema>>;
153
175
  layout?: "fill";
154
176
  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 {
@@ -86,7 +90,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
86
90
  const gitController = new AsyncRefreshController<GitRefreshInput, GitSnapshot | undefined>({
87
91
  async read(input, signal) {
88
92
  const requirements = reachableModuleRequirements(input.config);
89
- const gitReachable = [...requirements.keys()].some((name) => name.startsWith("git_"));
93
+ const gitReachable =
94
+ [...requirements.keys()].some((name) => name.startsWith("git_")) ||
95
+ (requirements.has("directory") &&
96
+ input.config.modules.directory.options.truncate_to_repo === true);
90
97
  if (!gitReachable) return undefined;
91
98
  try {
92
99
  return await readGitSnapshot(pi, input.cwd, {
@@ -242,6 +249,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
242
249
  runtime.workspace = undefined;
243
250
  runtime.requestRender = undefined;
244
251
  runtime.renderPreview = undefined;
252
+ runtime.inspect = undefined;
253
+ runtime.footerWidth = undefined;
245
254
  activeTarget = ctx.mode === "tui" ? target : undefined;
246
255
  ctx.ui.setStatus("starship", undefined);
247
256
  if (!activeTarget || !loaded) return;
@@ -258,6 +267,12 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
258
267
  width,
259
268
  );
260
269
  };
270
+ runtime.inspect = (current) =>
271
+ inspectStatuslineModules(
272
+ current.config,
273
+ runtimeSnapshot(ctx, footerData, runtime),
274
+ runtime.footerWidth ?? 80,
275
+ );
261
276
  const unsubscribe = footerData.onBranchChange(() => {
262
277
  if (!isActiveTarget(target)) return;
263
278
  runtime.git = undefined;
@@ -292,10 +307,13 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
292
307
  runtime.workspace = undefined;
293
308
  runtime.requestRender = undefined;
294
309
  runtime.renderPreview = undefined;
310
+ runtime.inspect = undefined;
311
+ runtime.footerWidth = undefined;
295
312
  }
296
313
  },
297
314
  invalidate() {},
298
315
  render(width: number): string[] {
316
+ runtime.footerWidth = width;
299
317
  if (!loaded) return [];
300
318
  const snapshot = runtimeSnapshot(ctx, footerData, runtime);
301
319
  return wrapFormattedStatusline(
@@ -313,6 +331,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
313
331
  registerStarshipCommand(pi, {
314
332
  settingsPath: configPath,
315
333
  getLoaded: () => loaded ?? loadStarshipConfig(configPath),
334
+ getInspection: () => {
335
+ const current = loaded ?? loadStarshipConfig(configPath);
336
+ return runtime.inspect?.(current);
337
+ },
316
338
  getMenuOwner: () => {
317
339
  const generation = sessionGeneration;
318
340
  return {
@@ -371,6 +393,8 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
371
393
  runtime.workspace = undefined;
372
394
  runtime.requestRender = undefined;
373
395
  runtime.renderPreview = undefined;
396
+ runtime.inspect = undefined;
397
+ runtime.footerWidth = undefined;
374
398
  ctx.ui.setFooter(undefined);
375
399
  ctx.ui.setStatus("starship", undefined);
376
400
  });
@@ -500,6 +524,8 @@ function runtimeSnapshot(
500
524
  ): StarshipRuntimeSnapshot {
501
525
  return {
502
526
  cwd: ctx.cwd,
527
+ homeDir: homedir(),
528
+ gitRoot: runtime.git?.root,
503
529
  model: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,
504
530
  thinkingLevel: runtime.thinkingLevel,
505
531
  turnCount: userTurnCount(ctx),
@@ -8,7 +8,6 @@ import {
8
8
  optionBoolean,
9
9
  optionString,
10
10
  optionStrings,
11
- pathName,
12
11
  runBounded,
13
12
  safeMetadata,
14
13
  setString,
@@ -51,7 +50,7 @@ export async function collectDevelopment(
51
50
  conda &&
52
51
  !(optionBoolean(context, "conda", "ignore_base") && conda === "base")
53
52
  ) {
54
- result.conda = { environment: pathName(conda) };
53
+ result.conda = { environment: conda };
55
54
  }
56
55
 
57
56
  if (context.needs("pixi") && detected(context, entries, "pixi", ["pixi.toml", "pixi.lock"])) {
@@ -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
  }
@@ -89,12 +98,10 @@ function hostnameValues(context: CollectorContext): Record<string, string> | und
89
98
  const raw = safeMetadata(context.input.hostname);
90
99
  if (!raw) return undefined;
91
100
  const aliases = optionMap(context, "hostname", "aliases");
92
- let hostname = exactAlias(raw, aliases) ?? raw;
93
- if (hostname === raw) {
94
- const trimAt = optionString(context, "hostname", "trim_at");
95
- const index = trimAt ? hostname.indexOf(trimAt) : -1;
96
- if (index > 0) hostname = hostname.slice(0, index);
97
- }
101
+ const trimAt = optionString(context, "hostname", "trim_at");
102
+ const index = trimAt ? raw.indexOf(trimAt) : -1;
103
+ const trimmed = index >= 0 ? raw.slice(0, index) : raw;
104
+ const hostname = exactAlias(trimmed, aliases) ?? trimmed;
98
105
  return { hostname, ssh_symbol: ssh ? "🌐 " : "" };
99
106
  }
100
107
 
@@ -116,7 +123,10 @@ function usernameValues(context: CollectorContext): Record<string, string> | und
116
123
  ) {
117
124
  return undefined;
118
125
  }
119
- return { user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user };
126
+ return {
127
+ user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user,
128
+ [PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user",
129
+ };
120
130
  }
121
131
 
122
132
  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
  }