@narumitw/pi-starship 0.55.1 → 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 (99) hide show
  1. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  2. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  3. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  4. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  5. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  6. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  7. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  8. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  9. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  10. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  11. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  12. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  13. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  14. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  15. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  16. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  17. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  18. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  19. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  20. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  21. package/dist/index.ts +20 -55
  22. package/dist/index.ts.map +2 -2
  23. package/package.json +60 -61
  24. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  25. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  26. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  27. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  28. package/src/command-configuration.ts +267 -286
  29. package/src/command-contract.ts +6 -6
  30. package/src/command-inspector.ts +27 -27
  31. package/src/command-preset-picker.ts +45 -50
  32. package/src/command-preview.ts +153 -166
  33. package/src/commands.ts +588 -618
  34. package/src/config.ts +580 -660
  35. package/src/effective-config.ts +46 -48
  36. package/src/format/formatter.ts +211 -227
  37. package/src/format/style.ts +205 -216
  38. package/src/modules/activity.ts +74 -74
  39. package/src/modules/brand.ts +9 -9
  40. package/src/modules/cache.ts +18 -18
  41. package/src/modules/catalog.ts +79 -83
  42. package/src/modules/cloud.ts +54 -54
  43. package/src/modules/context.ts +27 -27
  44. package/src/modules/cost.ts +23 -23
  45. package/src/modules/deployment.ts +45 -45
  46. package/src/modules/development.ts +80 -81
  47. package/src/modules/directory.ts +89 -113
  48. package/src/modules/display.ts +9 -9
  49. package/src/modules/execution.ts +62 -69
  50. package/src/modules/extension-status.ts +59 -64
  51. package/src/modules/fill.ts +10 -10
  52. package/src/modules/git/branch.ts +26 -26
  53. package/src/modules/git/commit.ts +21 -23
  54. package/src/modules/git/metrics.ts +22 -22
  55. package/src/modules/git/runtime.ts +299 -334
  56. package/src/modules/git/state.ts +17 -17
  57. package/src/modules/git/status.ts +77 -79
  58. package/src/modules/git/worktree.ts +10 -12
  59. package/src/modules/github-pr.ts +20 -20
  60. package/src/modules/helpers.ts +3 -3
  61. package/src/modules/index.ts +21 -21
  62. package/src/modules/inspection.ts +101 -108
  63. package/src/modules/languages.ts +52 -59
  64. package/src/modules/model.ts +57 -67
  65. package/src/modules/package.ts +12 -12
  66. package/src/modules/provider.ts +22 -24
  67. package/src/modules/render.ts +124 -140
  68. package/src/modules/thinking.ts +27 -26
  69. package/src/modules/time.ts +10 -13
  70. package/src/modules/tokens.ts +13 -13
  71. package/src/modules/truncation.ts +14 -17
  72. package/src/modules/turn.ts +9 -9
  73. package/src/modules/types.ts +125 -132
  74. package/src/modules/workspace-helpers.ts +4 -7
  75. package/src/pi-starship.ts +567 -603
  76. package/src/presets/catalog.ts +113 -113
  77. package/src/runtime/cloud.ts +122 -150
  78. package/src/runtime/command.ts +106 -108
  79. package/src/runtime/deployment.ts +150 -179
  80. package/src/runtime/development.ts +107 -124
  81. package/src/runtime/execution.ts +110 -124
  82. package/src/runtime/github-pr.ts +223 -252
  83. package/src/runtime/helpers.ts +186 -199
  84. package/src/runtime/languages.ts +149 -180
  85. package/src/runtime/package.ts +74 -87
  86. package/src/runtime/refresh-controller.ts +82 -86
  87. package/src/runtime/types.ts +38 -38
  88. package/src/runtime/workspace.ts +108 -116
  89. package/src/usage.ts +40 -40
  90. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  91. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  92. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  93. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  94. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  95. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  96. package/dist/chunks/development-BERD42HW.js.map +0 -7
  97. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  98. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  99. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -1,153 +1,136 @@
1
1
  import { join } from "node:path";
2
2
  import { parse } from "smol-toml";
3
3
  import {
4
- directMatch,
5
- formatVersion,
6
- isRecord,
7
- MAX_METADATA_FILE_BYTES,
8
- optionBoolean,
9
- optionString,
10
- optionStrings,
11
- runBounded,
12
- safeMetadata,
13
- setString,
4
+ directMatch,
5
+ formatVersion,
6
+ isRecord,
7
+ MAX_METADATA_FILE_BYTES,
8
+ optionBoolean,
9
+ optionString,
10
+ optionStrings,
11
+ runBounded,
12
+ safeMetadata,
13
+ setString,
14
14
  } from "./helpers.js";
15
15
  import type { CollectorContext, MutableModuleSnapshot } from "./types.js";
16
16
 
17
- export async function collectDevelopment(
18
- context: CollectorContext,
19
- ): Promise<MutableModuleSnapshot> {
20
- const result: MutableModuleSnapshot = {};
21
- const directNames = ["mise", "direnv", "pixi"] as const;
22
- const needsListing = directNames.some((name) => context.needs(name));
23
- const entries = needsListing ? await context.entries() : [];
17
+ export async function collectDevelopment(context: CollectorContext): Promise<MutableModuleSnapshot> {
18
+ const result: MutableModuleSnapshot = {};
19
+ const directNames = ["mise", "direnv", "pixi"] as const;
20
+ const needsListing = directNames.some((name) => context.needs(name));
21
+ const entries = needsListing ? await context.entries() : [];
24
22
 
25
- if (
26
- context.needs("mise") &&
27
- detected(context, entries, "mise", ["mise.toml", ".mise.toml", ".tool-versions"])
28
- ) {
29
- const values: Record<string, string> = {};
30
- if (context.needs("mise", "health")) {
31
- const output = await runBounded(context, "mise", ["doctor"]);
32
- const health = output ? parseMiseHealth(output) : undefined;
33
- if (health) values.health = health;
34
- }
35
- result.mise = values;
36
- }
23
+ if (context.needs("mise") && detected(context, entries, "mise", ["mise.toml", ".mise.toml", ".tool-versions"])) {
24
+ const values: Record<string, string> = {};
25
+ if (context.needs("mise", "health")) {
26
+ const output = await runBounded(context, "mise", ["doctor"]);
27
+ const health = output ? parseMiseHealth(output) : undefined;
28
+ if (health) values.health = health;
29
+ }
30
+ result.mise = values;
31
+ }
37
32
 
38
- if (context.needs("direnv") && detected(context, entries, "direnv", [".envrc"])) {
39
- const values: Record<string, string> = {};
40
- if (["rc_path", "allowed", "loaded"].some((variable) => context.needs("direnv", variable))) {
41
- const output = await runBounded(context, "direnv", ["status", "--json"]);
42
- if (output) Object.assign(values, parseDirenvStatus(output));
43
- }
44
- result.direnv = values;
45
- }
33
+ if (context.needs("direnv") && detected(context, entries, "direnv", [".envrc"])) {
34
+ const values: Record<string, string> = {};
35
+ if (["rc_path", "allowed", "loaded"].some((variable) => context.needs("direnv", variable))) {
36
+ const output = await runBounded(context, "direnv", ["status", "--json"]);
37
+ if (output) Object.assign(values, parseDirenvStatus(output));
38
+ }
39
+ result.direnv = values;
40
+ }
46
41
 
47
- const conda = safeMetadata(context.input.environment.CONDA_DEFAULT_ENV);
48
- if (
49
- context.needs("conda") &&
50
- conda &&
51
- !(optionBoolean(context, "conda", "ignore_base") && conda === "base")
52
- ) {
53
- result.conda = { environment: conda };
54
- }
42
+ const conda = safeMetadata(context.input.environment.CONDA_DEFAULT_ENV);
43
+ if (context.needs("conda") && conda && !(optionBoolean(context, "conda", "ignore_base") && conda === "base")) {
44
+ result.conda = { environment: conda };
45
+ }
55
46
 
56
- if (context.needs("pixi") && detected(context, entries, "pixi", ["pixi.toml", "pixi.lock"])) {
57
- const values: Record<string, string> = {};
58
- const environment = safeMetadata(context.input.environment.PIXI_ENVIRONMENT_NAME);
59
- if (
60
- environment &&
61
- (environment !== "default" || optionBoolean(context, "pixi", "show_default_environment"))
62
- ) {
63
- values.environment = environment;
64
- }
65
- const project =
66
- safeMetadata(context.input.environment.PIXI_PROJECT_NAME) ?? (await readPixiProject(context));
67
- if (project) values.project_name = project;
68
- if (context.needs("pixi", "version")) {
69
- const output = await runBounded(context, "pixi", ["--version"]);
70
- const version = output ? parsePixiVersion(output) : undefined;
71
- if (version)
72
- values.version = formatVersion(version, optionString(context, "pixi", "version_format"));
73
- }
74
- result.pixi = values;
75
- }
47
+ if (context.needs("pixi") && detected(context, entries, "pixi", ["pixi.toml", "pixi.lock"])) {
48
+ const values: Record<string, string> = {};
49
+ const environment = safeMetadata(context.input.environment.PIXI_ENVIRONMENT_NAME);
50
+ if (environment && (environment !== "default" || optionBoolean(context, "pixi", "show_default_environment"))) {
51
+ values.environment = environment;
52
+ }
53
+ const project = safeMetadata(context.input.environment.PIXI_PROJECT_NAME) ?? (await readPixiProject(context));
54
+ if (project) values.project_name = project;
55
+ if (context.needs("pixi", "version")) {
56
+ const output = await runBounded(context, "pixi", ["--version"]);
57
+ const version = output ? parsePixiVersion(output) : undefined;
58
+ if (version) values.version = formatVersion(version, optionString(context, "pixi", "version_format"));
59
+ }
60
+ result.pixi = values;
61
+ }
76
62
 
77
- const nixState = safeMetadata(context.input.environment.IN_NIX_SHELL);
78
- if (context.needs("nix_shell") && (nixState === "pure" || nixState === "impure")) {
79
- const values: Record<string, string> = { state: nixState };
80
- setString(values, "name", context.input.environment.NIX_SHELL_NAME);
81
- setString(values, "level", context.input.environment.NIX_SHELL_LEVEL);
82
- result.nix_shell = values;
83
- }
63
+ const nixState = safeMetadata(context.input.environment.IN_NIX_SHELL);
64
+ if (context.needs("nix_shell") && (nixState === "pure" || nixState === "impure")) {
65
+ const values: Record<string, string> = { state: nixState };
66
+ setString(values, "name", context.input.environment.NIX_SHELL_NAME);
67
+ setString(values, "level", context.input.environment.NIX_SHELL_LEVEL);
68
+ result.nix_shell = values;
69
+ }
84
70
 
85
- if (context.needs("guix_shell") && safeMetadata(context.input.environment.GUIX_ENVIRONMENT)) {
86
- result.guix_shell = { state: "active" };
87
- }
88
- return result;
71
+ if (context.needs("guix_shell") && safeMetadata(context.input.environment.GUIX_ENVIRONMENT)) {
72
+ result.guix_shell = { state: "active" };
73
+ }
74
+ return result;
89
75
  }
90
76
 
91
77
  function detected(
92
- context: CollectorContext,
93
- entries: Awaited<ReturnType<CollectorContext["entries"]>>,
94
- name: "mise" | "direnv" | "pixi",
95
- defaultFiles: string[],
78
+ context: CollectorContext,
79
+ entries: Awaited<ReturnType<CollectorContext["entries"]>>,
80
+ name: "mise" | "direnv" | "pixi",
81
+ defaultFiles: string[],
96
82
  ): boolean {
97
- const files = optionStrings(context, name, "detect_files");
98
- return directMatch(
99
- entries,
100
- files.length > 0 ? files : defaultFiles,
101
- optionStrings(context, name, "detect_extensions"),
102
- optionStrings(context, name, "detect_folders"),
103
- );
83
+ const files = optionStrings(context, name, "detect_files");
84
+ return directMatch(
85
+ entries,
86
+ files.length > 0 ? files : defaultFiles,
87
+ optionStrings(context, name, "detect_extensions"),
88
+ optionStrings(context, name, "detect_folders"),
89
+ );
104
90
  }
105
91
 
106
92
  export function parseMiseHealth(output: string): string | undefined {
107
- const text = safeMetadata(output, 8_192)?.toLowerCase();
108
- if (!text) return undefined;
109
- if (/\b(?:healthy|no problems found|all checks passed)\b/u.test(text)) return "healthy";
110
- if (/\b(?:error|unhealthy|problem|warning)\b/u.test(text)) return "issues";
111
- return undefined;
93
+ const text = safeMetadata(output, 8_192)?.toLowerCase();
94
+ if (!text) return undefined;
95
+ if (/\b(?:healthy|no problems found|all checks passed)\b/u.test(text)) return "healthy";
96
+ if (/\b(?:error|unhealthy|problem|warning)\b/u.test(text)) return "issues";
97
+ return undefined;
112
98
  }
113
99
 
114
100
  export function parseDirenvStatus(output: string): Record<string, string> {
115
- try {
116
- const document = JSON.parse(output) as unknown;
117
- if (!isRecord(document)) return {};
118
- const values: Record<string, string> = {};
119
- const found = isRecord(document.foundRC) ? document.foundRC : undefined;
120
- const loaded = isRecord(document.loadedRC) ? document.loadedRC : undefined;
121
- setString(values, "rc_path", found?.path ?? loaded?.path);
122
- if (typeof found?.allowed === "number" || typeof found?.allowed === "boolean") {
123
- values.allowed = found.allowed ? "allowed" : "denied";
124
- }
125
- if (loaded) values.loaded = "loaded";
126
- else if (found) values.loaded = "not loaded";
127
- return values;
128
- } catch {
129
- const path = /^Found RC path ([^\r\n]+)$/mu.exec(output)?.[1];
130
- return path ? { rc_path: safeMetadata(path) ?? "" } : {};
131
- }
101
+ try {
102
+ const document = JSON.parse(output) as unknown;
103
+ if (!isRecord(document)) return {};
104
+ const values: Record<string, string> = {};
105
+ const found = isRecord(document.foundRC) ? document.foundRC : undefined;
106
+ const loaded = isRecord(document.loadedRC) ? document.loadedRC : undefined;
107
+ setString(values, "rc_path", found?.path ?? loaded?.path);
108
+ if (typeof found?.allowed === "number" || typeof found?.allowed === "boolean") {
109
+ values.allowed = found.allowed ? "allowed" : "denied";
110
+ }
111
+ if (loaded) values.loaded = "loaded";
112
+ else if (found) values.loaded = "not loaded";
113
+ return values;
114
+ } catch {
115
+ const path = /^Found RC path ([^\r\n]+)$/mu.exec(output)?.[1];
116
+ return path ? { rc_path: safeMetadata(path) ?? "" } : {};
117
+ }
132
118
  }
133
119
 
134
120
  async function readPixiProject(context: CollectorContext): Promise<string | undefined> {
135
- const source = await context.fs.readFile(
136
- join(context.input.cwd, "pixi.toml"),
137
- MAX_METADATA_FILE_BYTES,
138
- );
139
- if (!source) return undefined;
140
- try {
141
- const document = parse(source);
142
- const project = isRecord(document.project) ? document.project : undefined;
143
- const workspace = isRecord(document.workspace) ? document.workspace : undefined;
144
- return safeMetadata(project?.name) ?? safeMetadata(workspace?.name);
145
- } catch {
146
- return undefined;
147
- }
121
+ const source = await context.fs.readFile(join(context.input.cwd, "pixi.toml"), MAX_METADATA_FILE_BYTES);
122
+ if (!source) return undefined;
123
+ try {
124
+ const document = parse(source);
125
+ const project = isRecord(document.project) ? document.project : undefined;
126
+ const workspace = isRecord(document.workspace) ? document.workspace : undefined;
127
+ return safeMetadata(project?.name) ?? safeMetadata(workspace?.name);
128
+ } catch {
129
+ return undefined;
130
+ }
148
131
  }
149
132
 
150
133
  function parsePixiVersion(output: string): string | undefined {
151
- const match = /^(?:pixi\s+)?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(output.trim());
152
- return match?.[1] ? `v${match[1]}` : undefined;
134
+ const match = /^(?:pixi\s+)?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/u.exec(output.trim());
135
+ return match?.[1] ? `v${match[1]}` : undefined;
153
136
  }
@@ -1,151 +1,137 @@
1
- import {
2
- exactAlias,
3
- optionBoolean,
4
- optionMap,
5
- optionString,
6
- optionStrings,
7
- safeMetadata,
8
- } from "./helpers.js";
9
- import {
10
- type CollectorContext,
11
- type MutableModuleSnapshot,
12
- PRIVATE_STYLE_SELECTOR,
13
- } from "./types.js";
1
+ import { exactAlias, optionBoolean, optionMap, optionString, optionStrings, safeMetadata } from "./helpers.js";
2
+ import { type CollectorContext, type MutableModuleSnapshot, PRIVATE_STYLE_SELECTOR } from "./types.js";
14
3
 
15
4
  export async function collectExecution(context: CollectorContext): Promise<MutableModuleSnapshot> {
16
- if (context.input.reason === "periodic" && context.input.previous) {
17
- const retained: MutableModuleSnapshot = {};
18
- for (const name of ["os", "container", "hostname", "username"] as const) {
19
- const values = context.input.previous.modules[name];
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
- };
26
- }
27
- return retained;
28
- }
29
- const result: MutableModuleSnapshot = {};
30
- if (context.needs("os")) result.os = await osValues(context);
31
- const container = context.needs("container") ? await containerValues(context) : undefined;
32
- if (container) result.container = container;
33
- const hostname = context.needs("hostname") ? hostnameValues(context) : undefined;
34
- if (hostname) result.hostname = hostname;
35
- const username = context.needs("username") ? usernameValues(context) : undefined;
36
- if (username) result.username = username;
37
- return result;
5
+ if (context.input.reason === "periodic" && context.input.previous) {
6
+ const retained: MutableModuleSnapshot = {};
7
+ for (const name of ["os", "container", "hostname", "username"] as const) {
8
+ const values = context.input.previous.modules[name];
9
+ if (!context.needs(name) || !values) continue;
10
+ const selector = context.input.previous.styleSelectors?.[name];
11
+ retained[name] = {
12
+ ...values,
13
+ ...(selector === undefined ? {} : { [PRIVATE_STYLE_SELECTOR]: selector }),
14
+ };
15
+ }
16
+ return retained;
17
+ }
18
+ const result: MutableModuleSnapshot = {};
19
+ if (context.needs("os")) result.os = await osValues(context);
20
+ const container = context.needs("container") ? await containerValues(context) : undefined;
21
+ if (container) result.container = container;
22
+ const hostname = context.needs("hostname") ? hostnameValues(context) : undefined;
23
+ if (hostname) result.hostname = hostname;
24
+ const username = context.needs("username") ? usernameValues(context) : undefined;
25
+ if (username) result.username = username;
26
+ return result;
38
27
  }
39
28
 
40
29
  async function osValues(context: CollectorContext): Promise<Record<string, string>> {
41
- const wsl = Boolean(safeMetadata(context.input.environment.WSL_DISTRO_NAME));
42
- const type = wsl ? "wsl" : platformType(context.input.platform);
43
- const details = context.input.platform === "linux" ? await linuxRelease(context) : {};
44
- const symbols = optionMap(context, "os", "symbols");
45
- return {
46
- type,
47
- name: details.name ?? platformName(context.input.platform, wsl),
48
- ...(details.version ? { version: details.version } : {}),
49
- ...(details.edition ? { edition: details.edition } : {}),
50
- ...(details.codename ? { codename: details.codename } : {}),
51
- ...(Object.hasOwn(symbols, type) && safeMetadata(symbols[type])
52
- ? { symbol: safeMetadata(symbols[type]) as string }
53
- : {}),
54
- };
30
+ const wsl = Boolean(safeMetadata(context.input.environment.WSL_DISTRO_NAME));
31
+ const type = wsl ? "wsl" : platformType(context.input.platform);
32
+ const details = context.input.platform === "linux" ? await linuxRelease(context) : {};
33
+ const symbols = optionMap(context, "os", "symbols");
34
+ return {
35
+ type,
36
+ name: details.name ?? platformName(context.input.platform, wsl),
37
+ ...(details.version ? { version: details.version } : {}),
38
+ ...(details.edition ? { edition: details.edition } : {}),
39
+ ...(details.codename ? { codename: details.codename } : {}),
40
+ ...(Object.hasOwn(symbols, type) && safeMetadata(symbols[type])
41
+ ? { symbol: safeMetadata(symbols[type]) as string }
42
+ : {}),
43
+ };
55
44
  }
56
45
 
57
46
  async function linuxRelease(context: CollectorContext): Promise<{
58
- name?: string;
59
- version?: string;
60
- edition?: string;
61
- codename?: string;
47
+ name?: string;
48
+ version?: string;
49
+ edition?: string;
50
+ codename?: string;
62
51
  }> {
63
- const source = await context.fs.readFile("/etc/os-release", 16 * 1024);
64
- if (!source) return {};
65
- const values: Record<string, string> = {};
66
- for (const line of source.split(/\r?\n/u)) {
67
- const match = /^([A-Z_]+)=(.*)$/u.exec(line);
68
- if (!match?.[1] || match[2] === undefined) continue;
69
- const value = safeMetadata(match[2].replace(/^['"]|['"]$/gu, ""));
70
- if (value) values[match[1]] = value;
71
- }
72
- return {
73
- name: values.NAME,
74
- version: values.VERSION_ID,
75
- edition: values.ID,
76
- codename: values.VERSION_CODENAME,
77
- };
52
+ const source = await context.fs.readFile("/etc/os-release", 16 * 1024);
53
+ if (!source) return {};
54
+ const values: Record<string, string> = {};
55
+ for (const line of source.split(/\r?\n/u)) {
56
+ const match = /^([A-Z_]+)=(.*)$/u.exec(line);
57
+ if (!match?.[1] || match[2] === undefined) continue;
58
+ const value = safeMetadata(match[2].replace(/^['"]|['"]$/gu, ""));
59
+ if (value) values[match[1]] = value;
60
+ }
61
+ return {
62
+ name: values.NAME,
63
+ version: values.VERSION_ID,
64
+ edition: values.ID,
65
+ codename: values.VERSION_CODENAME,
66
+ };
78
67
  }
79
68
 
80
- async function containerValues(
81
- context: CollectorContext,
82
- ): Promise<Record<string, string> | undefined> {
83
- const env = context.input.environment;
84
- if (safeMetadata(env.REMOTE_CONTAINERS) || safeMetadata(env.CODESPACES)) {
85
- return { name: "Dev Container", type: "devcontainer" };
86
- }
87
- const wsl = safeMetadata(env.WSL_DISTRO_NAME);
88
- if (wsl) return { name: `WSL ${wsl}`, type: "wsl" };
89
- if (await context.fs.fileExists("/.dockerenv")) return { name: "Docker", type: "docker" };
90
- if (await context.fs.fileExists("/run/.containerenv")) return { name: "Podman", type: "podman" };
91
- const systemd = safeMetadata(await context.fs.readFile("/run/systemd/container", 256));
92
- return systemd ? { name: systemd, type: "container" } : undefined;
69
+ async function containerValues(context: CollectorContext): Promise<Record<string, string> | undefined> {
70
+ const env = context.input.environment;
71
+ if (safeMetadata(env.REMOTE_CONTAINERS) || safeMetadata(env.CODESPACES)) {
72
+ return { name: "Dev Container", type: "devcontainer" };
73
+ }
74
+ const wsl = safeMetadata(env.WSL_DISTRO_NAME);
75
+ if (wsl) return { name: `WSL ${wsl}`, type: "wsl" };
76
+ if (await context.fs.fileExists("/.dockerenv")) return { name: "Docker", type: "docker" };
77
+ if (await context.fs.fileExists("/run/.containerenv")) return { name: "Podman", type: "podman" };
78
+ const systemd = safeMetadata(await context.fs.readFile("/run/systemd/container", 256));
79
+ return systemd ? { name: systemd, type: "container" } : undefined;
93
80
  }
94
81
 
95
82
  function hostnameValues(context: CollectorContext): Record<string, string> | undefined {
96
- const ssh = isSsh(context);
97
- if (optionBoolean(context, "hostname", "ssh_only") && !ssh) return undefined;
98
- const raw = safeMetadata(context.input.hostname);
99
- if (!raw) return undefined;
100
- const aliases = optionMap(context, "hostname", "aliases");
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;
105
- return { hostname, ssh_symbol: ssh ? "🌐 " : "" };
83
+ const ssh = isSsh(context);
84
+ if (optionBoolean(context, "hostname", "ssh_only") && !ssh) return undefined;
85
+ const raw = safeMetadata(context.input.hostname);
86
+ if (!raw) return undefined;
87
+ const aliases = optionMap(context, "hostname", "aliases");
88
+ const trimAt = optionString(context, "hostname", "trim_at");
89
+ const index = trimAt ? raw.indexOf(trimAt) : -1;
90
+ const trimmed = index >= 0 ? raw.slice(0, index) : raw;
91
+ const hostname = exactAlias(trimmed, aliases) ?? trimmed;
92
+ return { hostname, ssh_symbol: ssh ? "🌐 " : "" };
106
93
  }
107
94
 
108
95
  function usernameValues(context: CollectorContext): Record<string, string> | undefined {
109
- const user = safeMetadata(context.input.username);
110
- if (!user) return undefined;
111
- const env = context.input.environment;
112
- const login = safeMetadata(env.LOGNAME) ?? safeMetadata(env.USER) ?? safeMetadata(env.USERNAME);
113
- const privileged = /^(?:root|administrator)$/iu.test(user);
114
- const detected = optionStrings(context, "username", "detect_env_vars").some(
115
- (name) => safeMetadata(env[name]) !== undefined,
116
- );
117
- if (
118
- !optionBoolean(context, "username", "show_always") &&
119
- !isSsh(context) &&
120
- !privileged &&
121
- !(login && login !== user) &&
122
- !detected
123
- ) {
124
- return undefined;
125
- }
126
- return {
127
- user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user,
128
- [PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user",
129
- };
96
+ const user = safeMetadata(context.input.username);
97
+ if (!user) return undefined;
98
+ const env = context.input.environment;
99
+ const login = safeMetadata(env.LOGNAME) ?? safeMetadata(env.USER) ?? safeMetadata(env.USERNAME);
100
+ const privileged = /^(?:root|administrator)$/iu.test(user);
101
+ const detected = optionStrings(context, "username", "detect_env_vars").some(
102
+ (name) => safeMetadata(env[name]) !== undefined,
103
+ );
104
+ if (
105
+ !optionBoolean(context, "username", "show_always") &&
106
+ !isSsh(context) &&
107
+ !privileged &&
108
+ !(login && login !== user) &&
109
+ !detected
110
+ ) {
111
+ return undefined;
112
+ }
113
+ return {
114
+ user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user,
115
+ [PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user",
116
+ };
130
117
  }
131
118
 
132
119
  function isSsh(context: CollectorContext): boolean {
133
- return Boolean(
134
- safeMetadata(context.input.environment.SSH_CONNECTION) ||
135
- safeMetadata(context.input.environment.SSH_TTY),
136
- );
120
+ return Boolean(
121
+ safeMetadata(context.input.environment.SSH_CONNECTION) || safeMetadata(context.input.environment.SSH_TTY),
122
+ );
137
123
  }
138
124
 
139
125
  function platformType(platform: NodeJS.Platform): string {
140
- if (platform === "darwin") return "macos";
141
- if (platform === "win32") return "windows";
142
- return platform;
126
+ if (platform === "darwin") return "macos";
127
+ if (platform === "win32") return "windows";
128
+ return platform;
143
129
  }
144
130
 
145
131
  function platformName(platform: NodeJS.Platform, wsl: boolean): string {
146
- if (wsl) return "WSL";
147
- if (platform === "darwin") return "macOS";
148
- if (platform === "win32") return "Windows";
149
- if (platform === "linux") return "Linux";
150
- return platform;
132
+ if (wsl) return "WSL";
133
+ if (platform === "darwin") return "macOS";
134
+ if (platform === "win32") return "Windows";
135
+ if (platform === "linux") return "Linux";
136
+ return platform;
151
137
  }