@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.
- package/README.md +21 -36
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +38 -53
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -571
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
context: CollectorContext,
|
|
79
|
+
entries: Awaited<ReturnType<CollectorContext["entries"]>>,
|
|
80
|
+
name: "mise" | "direnv" | "pixi",
|
|
81
|
+
defaultFiles: string[],
|
|
96
82
|
): boolean {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
152
|
-
|
|
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
|
}
|
package/src/runtime/execution.ts
CHANGED
|
@@ -1,151 +1,137 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
name?: string;
|
|
48
|
+
version?: string;
|
|
49
|
+
edition?: string;
|
|
50
|
+
codename?: string;
|
|
62
51
|
}> {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
}
|