@narumitw/pi-starship 0.55.0 → 0.55.2

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 (101) hide show
  1. package/README.md +21 -36
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  3. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  11. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +38 -53
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
  26. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  27. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  28. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  29. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  30. package/src/command-configuration.ts +267 -286
  31. package/src/command-contract.ts +6 -6
  32. package/src/command-inspector.ts +27 -27
  33. package/src/command-preset-picker.ts +45 -50
  34. package/src/command-preview.ts +153 -166
  35. package/src/commands.ts +588 -618
  36. package/src/config.ts +580 -660
  37. package/src/effective-config.ts +46 -48
  38. package/src/format/formatter.ts +211 -227
  39. package/src/format/style.ts +205 -216
  40. package/src/modules/activity.ts +74 -74
  41. package/src/modules/brand.ts +9 -9
  42. package/src/modules/cache.ts +18 -18
  43. package/src/modules/catalog.ts +79 -83
  44. package/src/modules/cloud.ts +54 -54
  45. package/src/modules/context.ts +27 -27
  46. package/src/modules/cost.ts +23 -23
  47. package/src/modules/deployment.ts +45 -45
  48. package/src/modules/development.ts +80 -81
  49. package/src/modules/directory.ts +89 -113
  50. package/src/modules/display.ts +9 -9
  51. package/src/modules/execution.ts +62 -69
  52. package/src/modules/extension-status.ts +59 -64
  53. package/src/modules/fill.ts +10 -10
  54. package/src/modules/git/branch.ts +26 -26
  55. package/src/modules/git/commit.ts +21 -23
  56. package/src/modules/git/metrics.ts +22 -22
  57. package/src/modules/git/runtime.ts +299 -334
  58. package/src/modules/git/state.ts +17 -17
  59. package/src/modules/git/status.ts +77 -79
  60. package/src/modules/git/worktree.ts +10 -12
  61. package/src/modules/github-pr.ts +20 -20
  62. package/src/modules/helpers.ts +3 -3
  63. package/src/modules/index.ts +21 -21
  64. package/src/modules/inspection.ts +101 -108
  65. package/src/modules/languages.ts +52 -59
  66. package/src/modules/model.ts +57 -67
  67. package/src/modules/package.ts +12 -12
  68. package/src/modules/provider.ts +22 -24
  69. package/src/modules/render.ts +124 -140
  70. package/src/modules/thinking.ts +27 -26
  71. package/src/modules/time.ts +10 -13
  72. package/src/modules/tokens.ts +13 -13
  73. package/src/modules/truncation.ts +14 -17
  74. package/src/modules/turn.ts +9 -9
  75. package/src/modules/types.ts +125 -132
  76. package/src/modules/workspace-helpers.ts +4 -7
  77. package/src/pi-starship.ts +567 -571
  78. package/src/presets/catalog.ts +113 -113
  79. package/src/runtime/cloud.ts +122 -150
  80. package/src/runtime/command.ts +106 -108
  81. package/src/runtime/deployment.ts +150 -179
  82. package/src/runtime/development.ts +107 -124
  83. package/src/runtime/execution.ts +110 -124
  84. package/src/runtime/github-pr.ts +223 -252
  85. package/src/runtime/helpers.ts +186 -199
  86. package/src/runtime/languages.ts +149 -180
  87. package/src/runtime/package.ts +74 -87
  88. package/src/runtime/refresh-controller.ts +82 -86
  89. package/src/runtime/types.ts +38 -38
  90. package/src/runtime/workspace.ts +108 -116
  91. package/src/usage.ts +40 -40
  92. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  93. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  94. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  95. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  96. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  97. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  98. package/dist/chunks/development-BERD42HW.js.map +0 -7
  99. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  100. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  101. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -13,126 +13,126 @@ import { PURE_PRESET } from "./pure-preset.js";
13
13
  import { TOKYO_NIGHT_PRESET } from "./tokyo-night.js";
14
14
 
15
15
  export interface StarshipPreset {
16
- id:
17
- | "minimal"
18
- | "bracketed-segments"
19
- | "catppuccin-powerline"
20
- | "gruvbox-rainbow"
21
- | "jetpack"
22
- | "nerd-font-symbols"
23
- | "no-empty-icons"
24
- | "no-nerd-font"
25
- | "no-runtime-versions"
26
- | "pastel-powerline"
27
- | "plain-text-symbols"
28
- | "pure-preset"
29
- | "tokyo-night";
30
- label: string;
31
- description: string;
32
- requiresNerdFont: boolean;
33
- rawDocument: string;
16
+ id:
17
+ | "minimal"
18
+ | "bracketed-segments"
19
+ | "catppuccin-powerline"
20
+ | "gruvbox-rainbow"
21
+ | "jetpack"
22
+ | "nerd-font-symbols"
23
+ | "no-empty-icons"
24
+ | "no-nerd-font"
25
+ | "no-runtime-versions"
26
+ | "pastel-powerline"
27
+ | "plain-text-symbols"
28
+ | "pure-preset"
29
+ | "tokyo-night";
30
+ label: string;
31
+ description: string;
32
+ requiresNerdFont: boolean;
33
+ rawDocument: string;
34
34
  }
35
35
 
36
36
  export const STARSHIP_PRESETS = [
37
- {
38
- id: "minimal",
39
- label: "Minimal",
40
- description: "Compact Pi essentials · font-safe",
41
- requiresNerdFont: false,
42
- rawDocument: MINIMAL_PRESET,
43
- },
44
- {
45
- id: "bracketed-segments",
46
- label: "Bracketed Segments",
47
- description: "Balanced Pi and Git details in brackets · font-safe",
48
- requiresNerdFont: false,
49
- rawDocument: BRACKETED_SEGMENTS_PRESET,
50
- },
51
- {
52
- id: "catppuccin-powerline",
53
- label: "Catppuccin Powerline",
54
- description: "Mocha connected color blocks · requires Nerd Font",
55
- requiresNerdFont: true,
56
- rawDocument: CATPPUCCIN_POWERLINE_PRESET,
57
- },
58
- {
59
- id: "gruvbox-rainbow",
60
- label: "Gruvbox Rainbow",
61
- description: "Warm Gruvbox connected segments · requires Nerd Font",
62
- requiresNerdFont: true,
63
- rawDocument: GRUVBOX_RAINBOW_PRESET,
64
- },
65
- {
66
- id: "jetpack",
67
- label: "Jetpack",
68
- description: "Airy geometric left/right layout · font-safe",
69
- requiresNerdFont: false,
70
- rawDocument: JETPACK_PRESET,
71
- },
72
- {
73
- id: "nerd-font-symbols",
74
- label: "Nerd Font Symbols",
75
- description: "Balanced default layout with icon-rich symbols · requires Nerd Font",
76
- requiresNerdFont: true,
77
- rawDocument: NERD_FONT_SYMBOLS_PRESET,
78
- },
79
- {
80
- id: "no-empty-icons",
81
- label: "No Empty Icons",
82
- description: "Conditional labels never appear without values · font-safe",
83
- requiresNerdFont: false,
84
- rawDocument: NO_EMPTY_ICONS_PRESET,
85
- },
86
- {
87
- id: "no-nerd-font",
88
- label: "No Nerd Font",
89
- description: "Portable Unicode symbols without private-use glyphs · font-safe",
90
- requiresNerdFont: false,
91
- rawDocument: NO_NERD_FONT_PRESET,
92
- },
93
- {
94
- id: "no-runtime-versions",
95
- label: "No Runtime Versions",
96
- description: "Presence indicators without model or thinking details · font-safe",
97
- requiresNerdFont: false,
98
- rawDocument: NO_RUNTIME_VERSIONS_PRESET,
99
- },
100
- {
101
- id: "pastel-powerline",
102
- label: "Pastel Powerline",
103
- description: "Pastel connected color blocks · requires Nerd Font",
104
- requiresNerdFont: true,
105
- rawDocument: PASTEL_POWERLINE_PRESET,
106
- },
107
- {
108
- id: "plain-text-symbols",
109
- label: "Plain Text Symbols",
110
- description: "Plain words replace pictograms · font-safe",
111
- requiresNerdFont: false,
112
- rawDocument: PLAIN_TEXT_SYMBOLS_PRESET,
113
- },
114
- {
115
- id: "pure-preset",
116
- label: "Pure Preset",
117
- description: "Clean two-line workspace and session context · font-safe",
118
- requiresNerdFont: false,
119
- rawDocument: PURE_PRESET,
120
- },
121
- {
122
- id: "tokyo-night",
123
- label: "Tokyo Night",
124
- description: "Cool connected color blocks · requires Nerd Font",
125
- requiresNerdFont: true,
126
- rawDocument: TOKYO_NIGHT_PRESET,
127
- },
37
+ {
38
+ id: "minimal",
39
+ label: "Minimal",
40
+ description: "Compact Pi essentials · font-safe",
41
+ requiresNerdFont: false,
42
+ rawDocument: MINIMAL_PRESET,
43
+ },
44
+ {
45
+ id: "bracketed-segments",
46
+ label: "Bracketed Segments",
47
+ description: "Balanced Pi and Git details in brackets · font-safe",
48
+ requiresNerdFont: false,
49
+ rawDocument: BRACKETED_SEGMENTS_PRESET,
50
+ },
51
+ {
52
+ id: "catppuccin-powerline",
53
+ label: "Catppuccin Powerline",
54
+ description: "Mocha connected color blocks · requires Nerd Font",
55
+ requiresNerdFont: true,
56
+ rawDocument: CATPPUCCIN_POWERLINE_PRESET,
57
+ },
58
+ {
59
+ id: "gruvbox-rainbow",
60
+ label: "Gruvbox Rainbow",
61
+ description: "Warm Gruvbox connected segments · requires Nerd Font",
62
+ requiresNerdFont: true,
63
+ rawDocument: GRUVBOX_RAINBOW_PRESET,
64
+ },
65
+ {
66
+ id: "jetpack",
67
+ label: "Jetpack",
68
+ description: "Airy geometric left/right layout · font-safe",
69
+ requiresNerdFont: false,
70
+ rawDocument: JETPACK_PRESET,
71
+ },
72
+ {
73
+ id: "nerd-font-symbols",
74
+ label: "Nerd Font Symbols",
75
+ description: "Balanced default layout with icon-rich symbols · requires Nerd Font",
76
+ requiresNerdFont: true,
77
+ rawDocument: NERD_FONT_SYMBOLS_PRESET,
78
+ },
79
+ {
80
+ id: "no-empty-icons",
81
+ label: "No Empty Icons",
82
+ description: "Conditional labels never appear without values · font-safe",
83
+ requiresNerdFont: false,
84
+ rawDocument: NO_EMPTY_ICONS_PRESET,
85
+ },
86
+ {
87
+ id: "no-nerd-font",
88
+ label: "No Nerd Font",
89
+ description: "Portable Unicode symbols without private-use glyphs · font-safe",
90
+ requiresNerdFont: false,
91
+ rawDocument: NO_NERD_FONT_PRESET,
92
+ },
93
+ {
94
+ id: "no-runtime-versions",
95
+ label: "No Runtime Versions",
96
+ description: "Presence indicators without model or thinking details · font-safe",
97
+ requiresNerdFont: false,
98
+ rawDocument: NO_RUNTIME_VERSIONS_PRESET,
99
+ },
100
+ {
101
+ id: "pastel-powerline",
102
+ label: "Pastel Powerline",
103
+ description: "Pastel connected color blocks · requires Nerd Font",
104
+ requiresNerdFont: true,
105
+ rawDocument: PASTEL_POWERLINE_PRESET,
106
+ },
107
+ {
108
+ id: "plain-text-symbols",
109
+ label: "Plain Text Symbols",
110
+ description: "Plain words replace pictograms · font-safe",
111
+ requiresNerdFont: false,
112
+ rawDocument: PLAIN_TEXT_SYMBOLS_PRESET,
113
+ },
114
+ {
115
+ id: "pure-preset",
116
+ label: "Pure Preset",
117
+ description: "Clean two-line workspace and session context · font-safe",
118
+ requiresNerdFont: false,
119
+ rawDocument: PURE_PRESET,
120
+ },
121
+ {
122
+ id: "tokyo-night",
123
+ label: "Tokyo Night",
124
+ description: "Cool connected color blocks · requires Nerd Font",
125
+ requiresNerdFont: true,
126
+ rawDocument: TOKYO_NIGHT_PRESET,
127
+ },
128
128
  ] as const satisfies readonly StarshipPreset[];
129
129
 
130
130
  export function getStarshipPreset(id: StarshipPreset["id"]): StarshipPreset {
131
- const preset = STARSHIP_PRESETS.find((candidate) => candidate.id === id);
132
- if (!preset) throw new Error(`Unknown pi-starship preset: ${id}`);
133
- return preset;
131
+ const preset = STARSHIP_PRESETS.find((candidate) => candidate.id === id);
132
+ if (!preset) throw new Error(`Unknown pi-starship preset: ${id}`);
133
+ return preset;
134
134
  }
135
135
 
136
136
  export function presetForDocument(rawDocument: string | undefined): StarshipPreset | undefined {
137
- return STARSHIP_PRESETS.find((preset) => preset.rawDocument === rawDocument);
137
+ return STARSHIP_PRESETS.find((preset) => preset.rawDocument === rawDocument);
138
138
  }
@@ -1,167 +1,139 @@
1
1
  import { join } from "node:path";
2
2
  import { parse as parseYaml } from "yaml";
3
3
  import {
4
- exactAlias,
5
- isRecord,
6
- joinHome,
7
- MAX_METADATA_FILE_BYTES,
8
- optionBoolean,
9
- optionMap,
10
- parseIni,
11
- safeMetadata,
4
+ exactAlias,
5
+ isRecord,
6
+ joinHome,
7
+ MAX_METADATA_FILE_BYTES,
8
+ optionBoolean,
9
+ optionMap,
10
+ parseIni,
11
+ safeMetadata,
12
12
  } from "./helpers.js";
13
13
  import type { CollectorContext, MutableModuleSnapshot } from "./types.js";
14
14
 
15
15
  export async function collectCloud(context: CollectorContext): Promise<MutableModuleSnapshot> {
16
- const result: MutableModuleSnapshot = {};
17
- if (context.needs("aws")) {
18
- const values = await collectAws(context);
19
- if (values) result.aws = values;
20
- }
21
- if (context.needs("gcloud")) {
22
- const values = await collectGcloud(context);
23
- if (values) result.gcloud = values;
24
- }
25
- if (context.needs("azure")) {
26
- const values = await collectAzure(context);
27
- if (values) result.azure = values;
28
- }
29
- if (context.needs("openstack")) {
30
- const values = await collectOpenstack(context);
31
- if (values) result.openstack = values;
32
- }
33
- return result;
16
+ const result: MutableModuleSnapshot = {};
17
+ if (context.needs("aws")) {
18
+ const values = await collectAws(context);
19
+ if (values) result.aws = values;
20
+ }
21
+ if (context.needs("gcloud")) {
22
+ const values = await collectGcloud(context);
23
+ if (values) result.gcloud = values;
24
+ }
25
+ if (context.needs("azure")) {
26
+ const values = await collectAzure(context);
27
+ if (values) result.azure = values;
28
+ }
29
+ if (context.needs("openstack")) {
30
+ const values = await collectOpenstack(context);
31
+ if (values) result.openstack = values;
32
+ }
33
+ return result;
34
34
  }
35
35
 
36
36
  async function collectAws(context: CollectorContext): Promise<Record<string, string> | undefined> {
37
- const env = context.input.environment;
38
- const profile =
39
- safeMetadata(env.AWS_PROFILE) ?? safeMetadata(env.AWS_DEFAULT_PROFILE) ?? "default";
40
- let region = safeMetadata(env.AWS_REGION) ?? safeMetadata(env.AWS_DEFAULT_REGION);
41
- if (!region) {
42
- const configPath =
43
- safeMetadata(env.AWS_CONFIG_FILE, 1_024) ?? joinHome(context.input, ".aws", "config");
44
- const source = await context.fs.readFile(configPath, MAX_METADATA_FILE_BYTES);
45
- if (source) {
46
- const section = profile === "default" ? "default" : `profile ${profile}`;
47
- region = safeMetadata(parseIni(source)[section]?.region);
48
- }
49
- }
50
- if (profile === "default" && !region && !env.AWS_PROFILE && !env.AWS_DEFAULT_PROFILE)
51
- return undefined;
52
- const values: Record<string, string> = {
53
- profile: exactAlias(profile, optionMap(context, "aws", "profile_aliases")) ?? profile,
54
- };
55
- if (region)
56
- values.region = exactAlias(region, optionMap(context, "aws", "region_aliases")) ?? region;
57
- return values;
37
+ const env = context.input.environment;
38
+ const profile = safeMetadata(env.AWS_PROFILE) ?? safeMetadata(env.AWS_DEFAULT_PROFILE) ?? "default";
39
+ let region = safeMetadata(env.AWS_REGION) ?? safeMetadata(env.AWS_DEFAULT_REGION);
40
+ if (!region) {
41
+ const configPath = safeMetadata(env.AWS_CONFIG_FILE, 1_024) ?? joinHome(context.input, ".aws", "config");
42
+ const source = await context.fs.readFile(configPath, MAX_METADATA_FILE_BYTES);
43
+ if (source) {
44
+ const section = profile === "default" ? "default" : `profile ${profile}`;
45
+ region = safeMetadata(parseIni(source)[section]?.region);
46
+ }
47
+ }
48
+ if (profile === "default" && !region && !env.AWS_PROFILE && !env.AWS_DEFAULT_PROFILE) return undefined;
49
+ const values: Record<string, string> = {
50
+ profile: exactAlias(profile, optionMap(context, "aws", "profile_aliases")) ?? profile,
51
+ };
52
+ if (region) values.region = exactAlias(region, optionMap(context, "aws", "region_aliases")) ?? region;
53
+ return values;
58
54
  }
59
55
 
60
- async function collectGcloud(
61
- context: CollectorContext,
62
- ): Promise<Record<string, string> | undefined> {
63
- const env = context.input.environment;
64
- const directory =
65
- safeMetadata(env.CLOUDSDK_CONFIG, 1_024) ?? joinHome(context.input, ".config", "gcloud");
66
- const active =
67
- safeMetadata(env.CLOUDSDK_ACTIVE_CONFIG_NAME) ??
68
- safeMetadata(await context.fs.readFile(join(directory, "active_config"), 256));
69
- if (!active || !/^[A-Za-z0-9_-]+$/u.test(active)) return undefined;
70
- const source = await context.fs.readFile(
71
- join(directory, "configurations", `config_${active}`),
72
- MAX_METADATA_FILE_BYTES,
73
- );
74
- if (!source) return { active };
75
- const document = parseIni(source);
76
- const account = safeMetadata(document.core?.account);
77
- const project = safeMetadata(document.core?.project);
78
- const region = safeMetadata(document.compute?.region);
79
- const values: Record<string, string> = { active };
80
- if (account) {
81
- values.account = account;
82
- const separator = account.lastIndexOf("@");
83
- if (separator >= 0 && separator < account.length - 1)
84
- values.domain = account.slice(separator + 1);
85
- }
86
- if (project) {
87
- values.project =
88
- exactAlias(project, optionMap(context, "gcloud", "project_aliases")) ?? project;
89
- }
90
- if (region)
91
- values.region = exactAlias(region, optionMap(context, "gcloud", "region_aliases")) ?? region;
92
- return values;
56
+ async function collectGcloud(context: CollectorContext): Promise<Record<string, string> | undefined> {
57
+ const env = context.input.environment;
58
+ const directory = safeMetadata(env.CLOUDSDK_CONFIG, 1_024) ?? joinHome(context.input, ".config", "gcloud");
59
+ const active =
60
+ safeMetadata(env.CLOUDSDK_ACTIVE_CONFIG_NAME) ??
61
+ safeMetadata(await context.fs.readFile(join(directory, "active_config"), 256));
62
+ if (!active || !/^[A-Za-z0-9_-]+$/u.test(active)) return undefined;
63
+ const source = await context.fs.readFile(
64
+ join(directory, "configurations", `config_${active}`),
65
+ MAX_METADATA_FILE_BYTES,
66
+ );
67
+ if (!source) return { active };
68
+ const document = parseIni(source);
69
+ const account = safeMetadata(document.core?.account);
70
+ const project = safeMetadata(document.core?.project);
71
+ const region = safeMetadata(document.compute?.region);
72
+ const values: Record<string, string> = { active };
73
+ if (account) {
74
+ values.account = account;
75
+ const separator = account.lastIndexOf("@");
76
+ if (separator >= 0 && separator < account.length - 1) values.domain = account.slice(separator + 1);
77
+ }
78
+ if (project) {
79
+ values.project = exactAlias(project, optionMap(context, "gcloud", "project_aliases")) ?? project;
80
+ }
81
+ if (region) values.region = exactAlias(region, optionMap(context, "gcloud", "region_aliases")) ?? region;
82
+ return values;
93
83
  }
94
84
 
95
- async function collectAzure(
96
- context: CollectorContext,
97
- ): Promise<Record<string, string> | undefined> {
98
- const directory =
99
- safeMetadata(context.input.environment.AZURE_CONFIG_DIR, 1_024) ??
100
- joinHome(context.input, ".azure");
101
- const source = await context.fs.readFile(
102
- join(directory, "azureProfile.json"),
103
- MAX_METADATA_FILE_BYTES,
104
- );
105
- if (!source) return undefined;
106
- try {
107
- const document = JSON.parse(source.replace(/^\uFEFF/u, "")) as unknown;
108
- const subscriptions =
109
- isRecord(document) && Array.isArray(document.subscriptions)
110
- ? document.subscriptions.filter(isRecord)
111
- : [];
112
- const selected = subscriptions.find((item) => item.isDefault === true) ?? subscriptions[0];
113
- const subscription = safeMetadata(selected?.name);
114
- if (!subscription) return undefined;
115
- const values: Record<string, string> = {
116
- subscription:
117
- exactAlias(subscription, optionMap(context, "azure", "subscription_aliases")) ??
118
- subscription,
119
- };
120
- if (optionBoolean(context, "azure", "show_username")) {
121
- const user = isRecord(selected?.user) ? selected.user : undefined;
122
- const username = safeMetadata(user?.name);
123
- if (username) values.username = username;
124
- }
125
- return values;
126
- } catch {
127
- return undefined;
128
- }
85
+ async function collectAzure(context: CollectorContext): Promise<Record<string, string> | undefined> {
86
+ const directory =
87
+ safeMetadata(context.input.environment.AZURE_CONFIG_DIR, 1_024) ?? joinHome(context.input, ".azure");
88
+ const source = await context.fs.readFile(join(directory, "azureProfile.json"), MAX_METADATA_FILE_BYTES);
89
+ if (!source) return undefined;
90
+ try {
91
+ const document = JSON.parse(source.replace(/^\uFEFF/u, "")) as unknown;
92
+ const subscriptions =
93
+ isRecord(document) && Array.isArray(document.subscriptions) ? document.subscriptions.filter(isRecord) : [];
94
+ const selected = subscriptions.find((item) => item.isDefault === true) ?? subscriptions[0];
95
+ const subscription = safeMetadata(selected?.name);
96
+ if (!subscription) return undefined;
97
+ const values: Record<string, string> = {
98
+ subscription: exactAlias(subscription, optionMap(context, "azure", "subscription_aliases")) ?? subscription,
99
+ };
100
+ if (optionBoolean(context, "azure", "show_username")) {
101
+ const user = isRecord(selected?.user) ? selected.user : undefined;
102
+ const username = safeMetadata(user?.name);
103
+ if (username) values.username = username;
104
+ }
105
+ return values;
106
+ } catch {
107
+ return undefined;
108
+ }
129
109
  }
130
110
 
131
- async function collectOpenstack(
132
- context: CollectorContext,
133
- ): Promise<Record<string, string> | undefined> {
134
- const env = context.input.environment;
135
- const cloud = safeMetadata(env.OS_CLOUD);
136
- let project = safeMetadata(env.OS_PROJECT_NAME);
137
- if (!cloud) return undefined;
138
- if (!project) {
139
- const path =
140
- safeMetadata(env.OS_CLIENT_CONFIG_FILE, 1_024) ??
141
- joinHome(context.input, ".config", "openstack", "clouds.yaml");
142
- const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);
143
- if (source) {
144
- try {
145
- const document = parseYaml(source) as unknown;
146
- const clouds =
147
- isRecord(document) && isRecord(document.clouds) ? document.clouds : undefined;
148
- const selected =
149
- clouds && Object.hasOwn(clouds, cloud) && isRecord(clouds[cloud])
150
- ? clouds[cloud]
151
- : undefined;
152
- const auth = isRecord(selected?.auth) ? selected.auth : undefined;
153
- project = safeMetadata(auth?.project_name);
154
- } catch {
155
- // Malformed YAML is ignored.
156
- }
157
- }
158
- }
159
- const values: Record<string, string> = {
160
- cloud: exactAlias(cloud, optionMap(context, "openstack", "cloud_aliases")) ?? cloud,
161
- };
162
- if (project) {
163
- values.project =
164
- exactAlias(project, optionMap(context, "openstack", "project_aliases")) ?? project;
165
- }
166
- return values;
111
+ async function collectOpenstack(context: CollectorContext): Promise<Record<string, string> | undefined> {
112
+ const env = context.input.environment;
113
+ const cloud = safeMetadata(env.OS_CLOUD);
114
+ let project = safeMetadata(env.OS_PROJECT_NAME);
115
+ if (!cloud) return undefined;
116
+ if (!project) {
117
+ const path =
118
+ safeMetadata(env.OS_CLIENT_CONFIG_FILE, 1_024) ?? joinHome(context.input, ".config", "openstack", "clouds.yaml");
119
+ const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);
120
+ if (source) {
121
+ try {
122
+ const document = parseYaml(source) as unknown;
123
+ const clouds = isRecord(document) && isRecord(document.clouds) ? document.clouds : undefined;
124
+ const selected = clouds && Object.hasOwn(clouds, cloud) && isRecord(clouds[cloud]) ? clouds[cloud] : undefined;
125
+ const auth = isRecord(selected?.auth) ? selected.auth : undefined;
126
+ project = safeMetadata(auth?.project_name);
127
+ } catch {
128
+ // Malformed YAML is ignored.
129
+ }
130
+ }
131
+ }
132
+ const values: Record<string, string> = {
133
+ cloud: exactAlias(cloud, optionMap(context, "openstack", "cloud_aliases")) ?? cloud,
134
+ };
135
+ if (project) {
136
+ values.project = exactAlias(project, optionMap(context, "openstack", "project_aliases")) ?? project;
137
+ }
138
+ return values;
167
139
  }