@narumitw/pi-starship 0.43.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +274 -89
- package/package.json +2 -2
- package/src/command-inspector.ts +470 -0
- package/src/command-preview.ts +206 -0
- package/src/commands.ts +187 -152
- package/src/config.ts +177 -67
- package/src/format/style.ts +64 -45
- package/src/modules/activity.ts +1 -1
- package/src/modules/brand.ts +1 -1
- package/src/modules/cache.ts +1 -1
- package/src/modules/catalog.ts +65 -4
- package/src/modules/context.ts +13 -1
- package/src/modules/cost.ts +12 -1
- package/src/modules/development.ts +1 -1
- package/src/modules/directory.ts +1 -1
- package/src/modules/display.ts +14 -0
- package/src/modules/execution.ts +12 -1
- package/src/modules/extension-status.ts +7 -98
- package/src/modules/fill.ts +1 -1
- package/src/modules/git/branch.ts +3 -37
- package/src/modules/git/commit.ts +1 -1
- package/src/modules/git/metrics.ts +8 -2
- package/src/modules/git/runtime.ts +5 -2
- package/src/modules/git/state.ts +1 -1
- package/src/modules/git/status.ts +1 -1
- package/src/modules/git/worktree.ts +1 -1
- package/src/modules/github-pr.ts +24 -0
- package/src/modules/index.ts +15 -6
- package/src/modules/inspection.ts +138 -0
- package/src/modules/model.ts +1 -1
- package/src/modules/provider.ts +1 -1
- package/src/modules/render.ts +23 -19
- package/src/modules/thinking.ts +1 -1
- package/src/modules/time.ts +1 -1
- package/src/modules/tokens.ts +1 -1
- package/src/modules/turn.ts +1 -1
- package/src/modules/types.ts +32 -5
- package/src/pi-starship.ts +149 -27
- package/src/runtime/command.ts +46 -8
- package/src/runtime/execution.ts +15 -3
- package/src/runtime/github-pr.ts +332 -0
- package/src/runtime/helpers.ts +1 -0
- package/src/runtime/refresh-controller.ts +30 -8
- package/src/runtime/types.ts +4 -0
- package/src/runtime/workspace.ts +27 -10
- package/src/installed-packages.ts +0 -84
package/src/modules/context.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDisplayStyle } from "./display.js";
|
|
1
2
|
import { formatCount } from "./helpers.js";
|
|
2
3
|
import { defineModule } from "./types.js";
|
|
3
4
|
|
|
@@ -7,9 +8,20 @@ export const contextModule = defineModule({
|
|
|
7
8
|
defaults: {
|
|
8
9
|
format: "[$symbol ctx $percentage ]($style)",
|
|
9
10
|
symbol: "🪟",
|
|
10
|
-
style: "
|
|
11
|
+
style: "none",
|
|
11
12
|
disabled: false,
|
|
12
13
|
},
|
|
14
|
+
displayDefaults: [
|
|
15
|
+
{ threshold: 0, style: "bold green", hidden: true },
|
|
16
|
+
{ threshold: 30, style: "bold green", hidden: false },
|
|
17
|
+
{ threshold: 60, style: "bold yellow", hidden: false },
|
|
18
|
+
{ threshold: 80, style: "bold red", hidden: false },
|
|
19
|
+
],
|
|
20
|
+
styleVariables: ["style"],
|
|
21
|
+
resolveStyleVariables: ({ runtime, display }) => {
|
|
22
|
+
const style = resolveDisplayStyle(display, runtime.contextUsage?.percent);
|
|
23
|
+
return style === undefined ? undefined : { style };
|
|
24
|
+
},
|
|
13
25
|
values: ({ runtime }) => {
|
|
14
26
|
const percent = runtime.contextUsage?.percent;
|
|
15
27
|
return {
|
package/src/modules/cost.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDisplayStyle } from "./display.js";
|
|
1
2
|
import { defineModule } from "./types.js";
|
|
2
3
|
|
|
3
4
|
export const costModule = defineModule({
|
|
@@ -6,9 +7,19 @@ export const costModule = defineModule({
|
|
|
6
7
|
defaults: {
|
|
7
8
|
format: "[ $symbol \\$$cost( $subscription) ]($style)",
|
|
8
9
|
symbol: "💸",
|
|
9
|
-
style: "
|
|
10
|
+
style: "none",
|
|
10
11
|
disabled: false,
|
|
11
12
|
},
|
|
13
|
+
displayDefaults: [
|
|
14
|
+
{ threshold: 0, style: "bold green", hidden: true },
|
|
15
|
+
{ threshold: 1, style: "bold yellow", hidden: false },
|
|
16
|
+
{ threshold: 5, style: "bold red", hidden: false },
|
|
17
|
+
],
|
|
18
|
+
styleVariables: ["style"],
|
|
19
|
+
resolveStyleVariables: ({ runtime, display }) => {
|
|
20
|
+
const style = resolveDisplayStyle(display, runtime.tokenTotals.cost);
|
|
21
|
+
return style === undefined ? undefined : { style };
|
|
22
|
+
},
|
|
12
23
|
values: ({ runtime }) => ({
|
|
13
24
|
cost: formatCost(runtime.tokenTotals.cost),
|
|
14
25
|
subscription: runtime.usingSubscription ? "(sub)" : "",
|
package/src/modules/directory.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ModuleDisplayConfig } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function resolveDisplayStyle(
|
|
4
|
+
display: readonly ModuleDisplayConfig[],
|
|
5
|
+
value: number | null | undefined,
|
|
6
|
+
): string | undefined {
|
|
7
|
+
if (value === null || value === undefined || !Number.isFinite(value)) return undefined;
|
|
8
|
+
let selected: ModuleDisplayConfig | undefined;
|
|
9
|
+
for (const entry of display) {
|
|
10
|
+
if (entry.threshold > value) continue;
|
|
11
|
+
if (!selected || entry.threshold >= selected.threshold) selected = entry;
|
|
12
|
+
}
|
|
13
|
+
return selected && !selected.hidden ? selected.style : undefined;
|
|
14
|
+
}
|
package/src/modules/execution.ts
CHANGED
|
@@ -54,9 +54,20 @@ export const usernameModule = defineModule({
|
|
|
54
54
|
defaults: {
|
|
55
55
|
format: "[$user]($style) in ",
|
|
56
56
|
symbol: "",
|
|
57
|
-
style: "
|
|
57
|
+
style: "none",
|
|
58
58
|
disabled: false,
|
|
59
59
|
},
|
|
60
|
+
styleDefaults: {
|
|
61
|
+
style_user: "yellow bold",
|
|
62
|
+
style_root: "red bold",
|
|
63
|
+
},
|
|
64
|
+
styleVariables: ["style"],
|
|
65
|
+
resolveStyleVariables: ({ runtime, styles }) => ({
|
|
66
|
+
style:
|
|
67
|
+
runtime.workspace?.styleSelectors?.username === "root"
|
|
68
|
+
? (styles.style_root ?? "")
|
|
69
|
+
: (styles.style_user ?? ""),
|
|
70
|
+
}),
|
|
60
71
|
options: {
|
|
61
72
|
show_always: { kind: "boolean", default: false },
|
|
62
73
|
aliases: { kind: "string-map", default: {} },
|
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import { defineModule
|
|
2
|
-
|
|
3
|
-
const DEFAULT_EXTENSION_STATUS_ICONS: Record<string, string> = {
|
|
4
|
-
accounts: "👤",
|
|
5
|
-
caffeinate: "💊",
|
|
6
|
-
"chrome-devtools": "🌐",
|
|
7
|
-
"codex-usage": "📊",
|
|
8
|
-
firecrawl: "🔥",
|
|
9
|
-
"github-pr": "🔎",
|
|
10
|
-
goal: "🎯",
|
|
11
|
-
"google-genai": "✨",
|
|
12
|
-
lsp: "🧰",
|
|
13
|
-
"plan-mode": "📝",
|
|
14
|
-
retry: "🔁",
|
|
15
|
-
pisync: "🔄",
|
|
16
|
-
subagents: "🧑🤝🧑",
|
|
17
|
-
sync: "🔄",
|
|
18
|
-
usage: "📊",
|
|
19
|
-
"unknown-error-retry": "🔁",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const COMPATIBLE_STATUS_ICON_KEYS: Readonly<Record<string, string>> = {
|
|
23
|
-
retry: "unknown-error-retry",
|
|
24
|
-
sync: "pisync",
|
|
25
|
-
"unknown-error-retry": "retry",
|
|
26
|
-
pisync: "sync",
|
|
27
|
-
};
|
|
1
|
+
import { defineModule } from "./types.js";
|
|
28
2
|
|
|
29
3
|
export const extensionStatusModule = defineModule({
|
|
30
4
|
name: "extension_status",
|
|
@@ -32,22 +6,13 @@ export const extensionStatusModule = defineModule({
|
|
|
32
6
|
defaults: {
|
|
33
7
|
format: "[$statuses]($style)",
|
|
34
8
|
symbol: "",
|
|
35
|
-
style: "
|
|
9
|
+
style: "dimmed white",
|
|
36
10
|
disabled: false,
|
|
37
11
|
},
|
|
38
|
-
values: ({ runtime, extensionStatus
|
|
12
|
+
values: ({ runtime, extensionStatus }) => {
|
|
39
13
|
const statuses = [...runtime.extensionStatuses.entries()]
|
|
40
|
-
.filter(
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
.map(([key, value]) =>
|
|
44
|
-
formatExtensionStatus(
|
|
45
|
-
key,
|
|
46
|
-
value,
|
|
47
|
-
extensionStatus.icons,
|
|
48
|
-
runtime.extensionStatusIconAliases,
|
|
49
|
-
),
|
|
50
|
-
)
|
|
14
|
+
.filter(([key, value]) => key !== "starship" && value.trim())
|
|
15
|
+
.map(([key, value]) => formatExtensionStatus(key, value, extensionStatus.icons))
|
|
51
16
|
.slice(0, extensionStatus.maxStatuses);
|
|
52
17
|
if (statuses.length === 0) return undefined;
|
|
53
18
|
return {
|
|
@@ -61,10 +26,9 @@ export function formatExtensionStatus(
|
|
|
61
26
|
key: string,
|
|
62
27
|
value: string,
|
|
63
28
|
configuredIcons: Readonly<Record<string, string>>,
|
|
64
|
-
aliases: ExtensionStatusIconAliasMap,
|
|
65
29
|
): string {
|
|
66
30
|
const status = splitExtensionStatusIcon(stripExtensionStatusPrefix(key, value));
|
|
67
|
-
const icon = extensionStatusIcon(key, status.icon, configuredIcons
|
|
31
|
+
const icon = extensionStatusIcon(key, status.icon, configuredIcons);
|
|
68
32
|
const text = simplifyExtensionStatusText(status.text);
|
|
69
33
|
return icon ? `${icon} ${text}` : text;
|
|
70
34
|
}
|
|
@@ -73,25 +37,14 @@ function extensionStatusIcon(
|
|
|
73
37
|
key: string,
|
|
74
38
|
leadingIcon: string | undefined,
|
|
75
39
|
configuredIcons: Readonly<Record<string, string>>,
|
|
76
|
-
aliases: ExtensionStatusIconAliasMap,
|
|
77
40
|
): string {
|
|
78
41
|
if (Object.hasOwn(configuredIcons, key)) return configuredIcons[key] ?? "";
|
|
79
42
|
const namespaceIcon = configuredNamespaceIcon(key, configuredIcons);
|
|
80
43
|
if (namespaceIcon !== undefined) return namespaceIcon;
|
|
81
|
-
const compatibleKey = COMPATIBLE_STATUS_ICON_KEYS[key];
|
|
82
|
-
if (compatibleKey && Object.hasOwn(configuredIcons, compatibleKey)) {
|
|
83
|
-
return configuredIcons[compatibleKey] ?? "";
|
|
84
|
-
}
|
|
85
|
-
for (const alias of extensionStatusAliasesForKey(key, aliases)) {
|
|
86
|
-
if (Object.hasOwn(configuredIcons, alias)) return configuredIcons[alias] ?? "";
|
|
87
|
-
}
|
|
88
|
-
const defaultIcon = Object.hasOwn(DEFAULT_EXTENSION_STATUS_ICONS, key)
|
|
89
|
-
? DEFAULT_EXTENSION_STATUS_ICONS[key]
|
|
90
|
-
: undefined;
|
|
91
44
|
const fallbackIcon = Object.hasOwn(configuredIcons, "fallback")
|
|
92
45
|
? configuredIcons.fallback
|
|
93
46
|
: undefined;
|
|
94
|
-
return leadingIcon ??
|
|
47
|
+
return leadingIcon ?? fallbackIcon ?? "🔌";
|
|
95
48
|
}
|
|
96
49
|
|
|
97
50
|
function configuredNamespaceIcon(
|
|
@@ -108,16 +61,6 @@ function configuredNamespaceIcon(
|
|
|
108
61
|
return match?.icon;
|
|
109
62
|
}
|
|
110
63
|
|
|
111
|
-
function extensionStatusAliasesForKey(
|
|
112
|
-
key: string,
|
|
113
|
-
aliases: ExtensionStatusIconAliasMap,
|
|
114
|
-
): readonly string[] {
|
|
115
|
-
for (const [base, values] of aliases) {
|
|
116
|
-
if (key === base || key.startsWith(`${base}:`) || key.startsWith(`${base}/`)) return values;
|
|
117
|
-
}
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
64
|
function splitExtensionStatusIcon(value: string): { icon?: string; text: string } {
|
|
122
65
|
const trimmed = value.trim();
|
|
123
66
|
const [first, ...rest] = trimmed.split(/\s+/u);
|
|
@@ -148,37 +91,3 @@ function simplifyExtensionStatusText(value: string): string {
|
|
|
148
91
|
function escapeRegExp(value: string): string {
|
|
149
92
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
150
93
|
}
|
|
151
|
-
|
|
152
|
-
interface InstalledPackage {
|
|
153
|
-
packageName: string;
|
|
154
|
-
source?: string;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function buildExtensionStatusIconAliases(
|
|
158
|
-
packages: readonly InstalledPackage[],
|
|
159
|
-
): Map<string, string[]> {
|
|
160
|
-
const candidates = new Map<string, Map<string, string[]>>();
|
|
161
|
-
for (const installed of packages) {
|
|
162
|
-
const base = installed.packageName.slice(installed.packageName.lastIndexOf("/") + 1);
|
|
163
|
-
const statusBase = base.startsWith("pi-") ? base.slice(3) : base;
|
|
164
|
-
if (!statusBase) continue;
|
|
165
|
-
const sourceAliases = installed.source?.startsWith("npm:")
|
|
166
|
-
? [installed.source, `npm:${npmPackageName(installed.source)}`]
|
|
167
|
-
: [];
|
|
168
|
-
const aliases = [...new Set([...sourceAliases, installed.packageName, base, statusBase])];
|
|
169
|
-
const byPackage = candidates.get(statusBase) ?? new Map<string, string[]>();
|
|
170
|
-
byPackage.set(installed.packageName, aliases);
|
|
171
|
-
candidates.set(statusBase, byPackage);
|
|
172
|
-
}
|
|
173
|
-
const result = new Map<string, string[]>();
|
|
174
|
-
for (const [base, byPackage] of candidates) {
|
|
175
|
-
if (byPackage.size === 1) result.set(base, [...byPackage.values()][0] ?? []);
|
|
176
|
-
}
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function npmPackageName(source: string): string {
|
|
181
|
-
const spec = source.slice("npm:".length);
|
|
182
|
-
if (spec.startsWith("@")) return spec.split("@").slice(0, 2).join("@");
|
|
183
|
-
return spec.split("@")[0] ?? spec;
|
|
184
|
-
}
|
package/src/modules/fill.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { defineModule } from "../types.js";
|
|
|
2
2
|
|
|
3
3
|
export const gitBranchModule = defineModule({
|
|
4
4
|
name: "git_branch",
|
|
5
|
-
variables: ["symbol", "branch", "remote_name", "remote_branch"
|
|
5
|
+
variables: ["symbol", "branch", "remote_name", "remote_branch"],
|
|
6
6
|
defaults: {
|
|
7
|
-
format: "[ $symbol $branch
|
|
7
|
+
format: "[ $symbol $branch ]($style)",
|
|
8
8
|
symbol: "🌿",
|
|
9
|
-
style: "
|
|
9
|
+
style: "bold purple",
|
|
10
10
|
disabled: false,
|
|
11
11
|
},
|
|
12
12
|
values: ({ runtime }) => {
|
|
@@ -17,40 +17,6 @@ export const gitBranchModule = defineModule({
|
|
|
17
17
|
branch: name,
|
|
18
18
|
remote_name: branch?.remoteName ?? "",
|
|
19
19
|
remote_branch: branch?.remoteBranch ?? "",
|
|
20
|
-
pr: prContextFromStatuses(runtime.extensionStatuses) ?? "",
|
|
21
20
|
};
|
|
22
21
|
},
|
|
23
22
|
});
|
|
24
|
-
|
|
25
|
-
export function prContextFromStatuses(statuses: ReadonlyMap<string, string>): string | undefined {
|
|
26
|
-
const value = statuses.get("github-pr");
|
|
27
|
-
if (!value) return undefined;
|
|
28
|
-
const link = prLink(value);
|
|
29
|
-
if (!link) return undefined;
|
|
30
|
-
const state = compactPrState(value.replace(link, ""));
|
|
31
|
-
return state ? `${link} · ${state}` : undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function prLink(value: string): string | undefined {
|
|
35
|
-
const open = value.indexOf("\x1b]8;;");
|
|
36
|
-
if (open === -1) return undefined;
|
|
37
|
-
const closeMarker = "\x1b]8;;\x07";
|
|
38
|
-
const close = value.indexOf(closeMarker, open + 1);
|
|
39
|
-
return close === -1 ? undefined : value.slice(open, close + closeMarker.length);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function compactPrState(value: string): string | undefined {
|
|
43
|
-
if (/:\s*merged\s*$/u.test(value)) return "merged";
|
|
44
|
-
if (/:\s*closed\s*$/u.test(value)) return "closed";
|
|
45
|
-
if (/\bdraft\b/u.test(value)) return "draft";
|
|
46
|
-
const failing = /\bchecks failing \((\d+)\)/u.exec(value);
|
|
47
|
-
if (failing?.[1]) return `${failing[1]} failing`;
|
|
48
|
-
if (/\bchanges requested\b/u.test(value)) return "changes requested";
|
|
49
|
-
const pending = /\bchecks pending \((\d+)\)/u.exec(value);
|
|
50
|
-
if (pending?.[1]) return `${pending[1]} pending`;
|
|
51
|
-
if (/\bapproved\b/u.test(value)) return "approved";
|
|
52
|
-
if (/\breview required\b/u.test(value)) return "review required";
|
|
53
|
-
if (/\bchecks passing\b/u.test(value)) return "checks passing";
|
|
54
|
-
if (/\bno checks\b/u.test(value)) return "no checks";
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
@@ -4,11 +4,17 @@ export const gitMetricsModule = defineModule({
|
|
|
4
4
|
name: "git_metrics",
|
|
5
5
|
variables: ["symbol", "added", "deleted"],
|
|
6
6
|
defaults: {
|
|
7
|
-
format: "[
|
|
7
|
+
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
|
8
8
|
symbol: "",
|
|
9
|
-
style: "
|
|
9
|
+
style: "none",
|
|
10
10
|
disabled: true,
|
|
11
11
|
},
|
|
12
|
+
styleDefaults: {
|
|
13
|
+
added_style: "bold green",
|
|
14
|
+
deleted_style: "bold red",
|
|
15
|
+
},
|
|
16
|
+
styleVariables: ["added_style", "deleted_style"],
|
|
17
|
+
resolveStyleVariables: ({ styles }) => styles,
|
|
12
18
|
values: ({ runtime }) => {
|
|
13
19
|
const metrics = runtime.gitMetrics;
|
|
14
20
|
if (!metrics || (metrics.added === 0 && metrics.deleted === 0)) return undefined;
|
|
@@ -16,6 +16,7 @@ const GIT_TIMEOUT_MS = 3_000;
|
|
|
16
16
|
export interface ReadGitSnapshotOptions {
|
|
17
17
|
includeMetrics: boolean;
|
|
18
18
|
includeTag: boolean;
|
|
19
|
+
signal?: AbortSignal;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export async function readGitSnapshot(
|
|
@@ -33,22 +34,24 @@ export async function readGitSnapshot(
|
|
|
33
34
|
"--show-stash",
|
|
34
35
|
"--untracked-files=normal",
|
|
35
36
|
],
|
|
36
|
-
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
37
|
+
{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
|
|
37
38
|
);
|
|
38
39
|
const metadataPromise = pi.exec(
|
|
39
40
|
"git",
|
|
40
41
|
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
41
|
-
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
42
|
+
{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
|
|
42
43
|
);
|
|
43
44
|
const metricsPromise = options.includeMetrics
|
|
44
45
|
? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
|
|
45
46
|
cwd,
|
|
47
|
+
signal: options.signal,
|
|
46
48
|
timeout: GIT_TIMEOUT_MS,
|
|
47
49
|
})
|
|
48
50
|
: Promise.resolve(undefined);
|
|
49
51
|
const tagPromise = options.includeTag
|
|
50
52
|
? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
|
|
51
53
|
cwd,
|
|
54
|
+
signal: options.signal,
|
|
52
55
|
timeout: GIT_TIMEOUT_MS,
|
|
53
56
|
})
|
|
54
57
|
: Promise.resolve(undefined);
|
package/src/modules/git/state.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineModule } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const githubPrModule = defineModule({
|
|
4
|
+
name: "github_pr",
|
|
5
|
+
variables: ["symbol", "number", "link", "state", "checks", "review", "status"],
|
|
6
|
+
defaults: {
|
|
7
|
+
format: "[ $symbol$link( · $status) ]($style)",
|
|
8
|
+
symbol: "PR ",
|
|
9
|
+
style: "bold blue",
|
|
10
|
+
disabled: false,
|
|
11
|
+
},
|
|
12
|
+
values: ({ runtime }) => {
|
|
13
|
+
const snapshot = runtime.githubPr;
|
|
14
|
+
if (!snapshot) return undefined;
|
|
15
|
+
return {
|
|
16
|
+
number: snapshot.number,
|
|
17
|
+
link: snapshot.link,
|
|
18
|
+
state: snapshot.state,
|
|
19
|
+
checks: snapshot.checks,
|
|
20
|
+
review: snapshot.review,
|
|
21
|
+
status: snapshot.status,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
package/src/modules/index.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
export { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
|
|
2
1
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
type CatalogModuleDefinition,
|
|
3
|
+
MODULE_DEFINITIONS,
|
|
4
|
+
MODULE_NAMES,
|
|
5
|
+
type ModuleName,
|
|
6
|
+
} from "./catalog.js";
|
|
7
|
+
export { formatExtensionStatus } from "./extension-status.js";
|
|
7
8
|
export { formatCount } from "./helpers.js";
|
|
9
|
+
export {
|
|
10
|
+
inspectStatuslineModules,
|
|
11
|
+
inspectUnavailableModules,
|
|
12
|
+
type ModuleInspection,
|
|
13
|
+
type ModuleInspectionState,
|
|
14
|
+
type StatuslineInspection,
|
|
15
|
+
} from "./inspection.js";
|
|
8
16
|
export { shortenModel } from "./model.js";
|
|
9
17
|
export { reachableModuleRequirements, renderStatusline } from "./render.js";
|
|
10
18
|
export type {
|
|
11
|
-
ExtensionStatusIconAliasMap,
|
|
12
19
|
GitBranchSnapshot,
|
|
13
20
|
GitCommitSnapshot,
|
|
21
|
+
GithubPrSnapshot,
|
|
22
|
+
GithubPrState,
|
|
14
23
|
GitMetricsSnapshot,
|
|
15
24
|
GitSnapshot,
|
|
16
25
|
GitStateSnapshot,
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
import type { StarshipConfig } from "../config.js";
|
|
3
|
+
import { formatVariables } from "../format/formatter.js";
|
|
4
|
+
import { MODULE_DEFINITIONS, type ModuleName } from "./catalog.js";
|
|
5
|
+
import { reachableModuleRequirements, renderStatusline } from "./render.js";
|
|
6
|
+
import type { StarshipRuntimeSnapshot } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export type ModuleInspectionState =
|
|
9
|
+
| "Showing"
|
|
10
|
+
| "Empty"
|
|
11
|
+
| "Disabled"
|
|
12
|
+
| "Not in format"
|
|
13
|
+
| "Unavailable";
|
|
14
|
+
|
|
15
|
+
export interface ModuleInspection {
|
|
16
|
+
name: ModuleName;
|
|
17
|
+
description: string;
|
|
18
|
+
state: ModuleInspectionState;
|
|
19
|
+
preview: string;
|
|
20
|
+
variables: readonly string[];
|
|
21
|
+
styleFields: readonly string[];
|
|
22
|
+
displayRules: readonly string[];
|
|
23
|
+
rootReferenced: boolean;
|
|
24
|
+
reachable: boolean;
|
|
25
|
+
reason: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StatuslineInspection {
|
|
29
|
+
modules: readonly ModuleInspection[];
|
|
30
|
+
showing: readonly ModuleInspection[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function inspectStatuslineModules(
|
|
34
|
+
config: StarshipConfig,
|
|
35
|
+
runtime: StarshipRuntimeSnapshot,
|
|
36
|
+
width = 80,
|
|
37
|
+
): StatuslineInspection {
|
|
38
|
+
const rendered = renderStatusline(config, runtime, width);
|
|
39
|
+
const requirements = reachableModuleRequirements(config);
|
|
40
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
41
|
+
const includeAll = rootVariables.has("all");
|
|
42
|
+
const modules = MODULE_DEFINITIONS.map((definition): ModuleInspection => {
|
|
43
|
+
const module = config.modules[definition.name];
|
|
44
|
+
const reachable = requirements.has(definition.name);
|
|
45
|
+
const preview = plainPreview(
|
|
46
|
+
rendered.modules[definition.name].map((chunk) => chunk.text).join(""),
|
|
47
|
+
);
|
|
48
|
+
const state = module.disabled
|
|
49
|
+
? "Disabled"
|
|
50
|
+
: !reachable
|
|
51
|
+
? "Not in format"
|
|
52
|
+
: preview.length > 0
|
|
53
|
+
? "Showing"
|
|
54
|
+
: "Empty";
|
|
55
|
+
return moduleInspection(
|
|
56
|
+
config,
|
|
57
|
+
definition,
|
|
58
|
+
state,
|
|
59
|
+
preview,
|
|
60
|
+
includeAll || rootVariables.has(definition.name),
|
|
61
|
+
reachable,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
modules,
|
|
66
|
+
showing: modules.filter((module) => module.state === "Showing"),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function inspectUnavailableModules(config: StarshipConfig): StatuslineInspection {
|
|
71
|
+
const requirements = reachableModuleRequirements(config);
|
|
72
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
73
|
+
const includeAll = rootVariables.has("all");
|
|
74
|
+
return {
|
|
75
|
+
modules: MODULE_DEFINITIONS.map((definition) => {
|
|
76
|
+
const module = config.modules[definition.name];
|
|
77
|
+
const reachable = requirements.has(definition.name);
|
|
78
|
+
const state = module.disabled ? "Disabled" : reachable ? "Unavailable" : "Not in format";
|
|
79
|
+
return moduleInspection(
|
|
80
|
+
config,
|
|
81
|
+
definition,
|
|
82
|
+
state,
|
|
83
|
+
"",
|
|
84
|
+
includeAll || rootVariables.has(definition.name),
|
|
85
|
+
reachable,
|
|
86
|
+
);
|
|
87
|
+
}),
|
|
88
|
+
showing: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function moduleInspection(
|
|
93
|
+
config: StarshipConfig,
|
|
94
|
+
definition: (typeof MODULE_DEFINITIONS)[number],
|
|
95
|
+
state: ModuleInspectionState,
|
|
96
|
+
preview: string,
|
|
97
|
+
rootReferenced: boolean,
|
|
98
|
+
reachable: boolean,
|
|
99
|
+
): ModuleInspection {
|
|
100
|
+
const module = config.modules[definition.name];
|
|
101
|
+
return {
|
|
102
|
+
name: definition.name,
|
|
103
|
+
description: definition.description,
|
|
104
|
+
state,
|
|
105
|
+
preview,
|
|
106
|
+
variables: [...definition.variables],
|
|
107
|
+
styleFields: ["style", ...Object.keys(module.styles)],
|
|
108
|
+
displayRules: module.display.map(
|
|
109
|
+
(rule) => `${rule.threshold}: ${rule.hidden ? "hidden" : rule.style || "unstyled"}`,
|
|
110
|
+
),
|
|
111
|
+
rootReferenced,
|
|
112
|
+
reachable,
|
|
113
|
+
reason: inspectionReason(state),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function inspectionReason(state: ModuleInspectionState): string {
|
|
118
|
+
switch (state) {
|
|
119
|
+
case "Showing":
|
|
120
|
+
return "Rendered in the current footer.";
|
|
121
|
+
case "Empty":
|
|
122
|
+
return "Referenced by the root format, but the current snapshot produced no output.";
|
|
123
|
+
case "Disabled":
|
|
124
|
+
return "Disabled by this module's configuration.";
|
|
125
|
+
case "Not in format":
|
|
126
|
+
return "Not referenced by the root format or $all.";
|
|
127
|
+
case "Unavailable":
|
|
128
|
+
return "Current footer inspection is unavailable; no collector failure was inferred.";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function plainPreview(value: string): string {
|
|
133
|
+
return Array.from(stripVTControlCharacters(value), (character) => {
|
|
134
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
135
|
+
if (character === "\n") return character;
|
|
136
|
+
return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? " " : character;
|
|
137
|
+
}).join("");
|
|
138
|
+
}
|
package/src/modules/model.ts
CHANGED
package/src/modules/provider.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const providerModule = defineModule({
|
|
|
6
6
|
defaults: {
|
|
7
7
|
format: "[$symbol $provider ]($style)",
|
|
8
8
|
symbol: "🔌",
|
|
9
|
-
style: "
|
|
9
|
+
style: "bold blue",
|
|
10
10
|
disabled: false,
|
|
11
11
|
},
|
|
12
12
|
values: ({ runtime }) => (runtime.model ? { provider: runtime.model.provider } : undefined),
|