@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/config.ts
CHANGED
|
@@ -18,7 +18,11 @@ import {
|
|
|
18
18
|
} from "./format/formatter.js";
|
|
19
19
|
import { type ColorPalette, isValidStyle, parseColor } from "./format/style.js";
|
|
20
20
|
import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./modules/catalog.js";
|
|
21
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
ModuleDisplayConfig,
|
|
23
|
+
ModuleOptionSchema,
|
|
24
|
+
ModuleOptionValue,
|
|
25
|
+
} from "./modules/types.js";
|
|
22
26
|
|
|
23
27
|
export const CONFIG_FILE_NAME = "pi-starship.toml";
|
|
24
28
|
export { MODULE_NAMES, type ModuleName } from "./modules/catalog.js";
|
|
@@ -32,6 +36,8 @@ export interface ModuleConfig {
|
|
|
32
36
|
formatAst: FormatNode[];
|
|
33
37
|
symbol: string;
|
|
34
38
|
style: string;
|
|
39
|
+
styles: Record<string, string>;
|
|
40
|
+
display: ModuleDisplayConfig[];
|
|
35
41
|
disabled: boolean;
|
|
36
42
|
options: Record<string, ModuleOptionValue>;
|
|
37
43
|
}
|
|
@@ -45,7 +51,7 @@ export interface ExtensionStatusConfig {
|
|
|
45
51
|
export interface StarshipConfig {
|
|
46
52
|
format: string;
|
|
47
53
|
formatAst: FormatNode[];
|
|
48
|
-
palette
|
|
54
|
+
palette?: string;
|
|
49
55
|
palettes: Record<string, Record<string, string>>;
|
|
50
56
|
modules: Record<ModuleName, ModuleConfig>;
|
|
51
57
|
extensionStatus: ExtensionStatusConfig;
|
|
@@ -67,51 +73,26 @@ export interface LoadedStarshipConfig {
|
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
const BUILT_IN_FORMAT_DOCUMENT = String.raw`format = """
|
|
70
|
-
[░▒▓](lead)\
|
|
71
76
|
$brand\
|
|
72
|
-
$provider\
|
|
73
77
|
$model\
|
|
74
78
|
$thinking\
|
|
75
|
-
[](fg:header bg:directory)\
|
|
76
79
|
$directory\
|
|
77
|
-
[](fg:directory bg:git)\
|
|
78
|
-
$git_worktree\
|
|
79
80
|
$git_branch\
|
|
80
81
|
$git_status\
|
|
81
|
-
[](fg:git bg:runtime)\
|
|
82
82
|
$activity\
|
|
83
83
|
$context\
|
|
84
|
-
$
|
|
85
|
-
$cache\
|
|
86
|
-
[](fg:runtime bg:meter)\
|
|
87
|
-
$cost\
|
|
88
|
-
$time\
|
|
89
|
-
[](fg:meter)\
|
|
90
|
-
(\n$extension_status)"""`;
|
|
84
|
+
$time"""`;
|
|
91
85
|
|
|
92
86
|
const BUILT_IN_FORMAT = parseBuiltInFormat(BUILT_IN_FORMAT_DOCUMENT);
|
|
93
87
|
|
|
94
|
-
const BUILT_IN_PALETTE = {
|
|
95
|
-
lead: "#a3aed2",
|
|
96
|
-
header: "#a3aed2",
|
|
97
|
-
header_fg: "#090c0c",
|
|
98
|
-
directory: "#769ff0",
|
|
99
|
-
directory_fg: "#e3e5e5",
|
|
100
|
-
git: "#394260",
|
|
101
|
-
git_fg: "#769ff0",
|
|
102
|
-
runtime: "#212736",
|
|
103
|
-
runtime_fg: "#769ff0",
|
|
104
|
-
meter: "#1d2230",
|
|
105
|
-
meter_fg: "#a0a9cb",
|
|
106
|
-
extension: "#a0a9cb",
|
|
107
|
-
};
|
|
108
|
-
|
|
109
88
|
const BUILT_IN_MODULES = Object.fromEntries(
|
|
110
|
-
MODULE_DEFINITIONS.map(({ name, defaults, options }) => [
|
|
89
|
+
MODULE_DEFINITIONS.map(({ name, defaults, styleDefaults, displayDefaults, options }) => [
|
|
111
90
|
name,
|
|
112
91
|
{
|
|
113
92
|
...defaults,
|
|
114
93
|
formatAst: parseFormat(defaults.format),
|
|
94
|
+
styles: { ...styleDefaults },
|
|
95
|
+
display: structuredClone(displayDefaults ?? []),
|
|
115
96
|
options: Object.fromEntries(
|
|
116
97
|
Object.entries(options ?? {}).map(([key, schema]) => [
|
|
117
98
|
key,
|
|
@@ -125,17 +106,13 @@ const BUILT_IN_MODULES = Object.fromEntries(
|
|
|
125
106
|
export const BUILT_IN_CONFIG: StarshipConfig = {
|
|
126
107
|
format: BUILT_IN_FORMAT,
|
|
127
108
|
formatAst: parseFormat(BUILT_IN_FORMAT),
|
|
128
|
-
palette:
|
|
129
|
-
palettes: {
|
|
109
|
+
palette: undefined,
|
|
110
|
+
palettes: {},
|
|
130
111
|
modules: BUILT_IN_MODULES,
|
|
131
112
|
extensionStatus: { separator: " • ", maxStatuses: 5, icons: {} },
|
|
132
113
|
};
|
|
133
114
|
|
|
134
|
-
export const BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.\n${BUILT_IN_FORMAT_DOCUMENT}\
|
|
135
|
-
BUILT_IN_PALETTE,
|
|
136
|
-
)
|
|
137
|
-
.map(([name, color]) => `${name} = "${color}"`)
|
|
138
|
-
.join("\n")}\n`;
|
|
115
|
+
export const BUILT_IN_EXAMPLE = `# Native Pi modules with Starship-compatible format and style syntax.\n${BUILT_IN_FORMAT_DOCUMENT}\n`;
|
|
139
116
|
|
|
140
117
|
function parseBuiltInFormat(document: string): string {
|
|
141
118
|
const format = parse(document).format;
|
|
@@ -252,11 +229,14 @@ export function normalizeConfig(value: unknown): {
|
|
|
252
229
|
|
|
253
230
|
if (value.palette !== undefined) {
|
|
254
231
|
if (typeof value.palette !== "string") diagnostics.push(typeDiagnostic("palette", "string"));
|
|
255
|
-
else
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
232
|
+
else {
|
|
233
|
+
config.palette = value.palette;
|
|
234
|
+
if (!Object.hasOwn(config.palettes, value.palette)) {
|
|
235
|
+
diagnostics.push(
|
|
236
|
+
diagnostic("warning", "palette", `Unknown palette ${JSON.stringify(value.palette)}`),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
260
240
|
}
|
|
261
241
|
|
|
262
242
|
for (const name of MODULE_NAMES) {
|
|
@@ -277,7 +257,9 @@ export function normalizeConfig(value: unknown): {
|
|
|
277
257
|
);
|
|
278
258
|
validateStyleVariables(config.formatAst, new Set(), "format", diagnostics);
|
|
279
259
|
const palette = activePalette(config);
|
|
280
|
-
|
|
260
|
+
validateLiteralStyles(config.formatAst, palette, "format", diagnostics);
|
|
261
|
+
for (const definition of MODULE_DEFINITIONS) {
|
|
262
|
+
const name = definition.name;
|
|
281
263
|
const module = config.modules[name];
|
|
282
264
|
validateFormatVariables(
|
|
283
265
|
module.formatAst,
|
|
@@ -285,16 +267,19 @@ export function normalizeConfig(value: unknown): {
|
|
|
285
267
|
`${name}.format`,
|
|
286
268
|
diagnostics,
|
|
287
269
|
);
|
|
288
|
-
validateStyleVariables(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
)
|
|
297
|
-
|
|
270
|
+
validateStyleVariables(
|
|
271
|
+
module.formatAst,
|
|
272
|
+
new Set(definition.styleVariables ?? ["style"]),
|
|
273
|
+
`${name}.format`,
|
|
274
|
+
diagnostics,
|
|
275
|
+
);
|
|
276
|
+
validateLiteralStyles(module.formatAst, palette, `${name}.format`, diagnostics);
|
|
277
|
+
if (definition.styleDefaults) {
|
|
278
|
+
for (const field of Object.keys(definition.styleDefaults)) {
|
|
279
|
+
validateModuleStyleField(name, field, module, palette, diagnostics);
|
|
280
|
+
}
|
|
281
|
+
} else if (!definition.displayDefaults) {
|
|
282
|
+
validateModuleStyleField(name, "style", module, palette, diagnostics);
|
|
298
283
|
}
|
|
299
284
|
}
|
|
300
285
|
|
|
@@ -308,8 +293,13 @@ function normalizeModule(
|
|
|
308
293
|
diagnostics: ConfigDiagnostic[],
|
|
309
294
|
) {
|
|
310
295
|
const definition = MODULE_DEFINITIONS.find((candidate) => candidate.name === name);
|
|
311
|
-
|
|
312
|
-
const
|
|
296
|
+
if (!definition) return;
|
|
297
|
+
const optionSchemas: Readonly<Record<string, ModuleOptionSchema>> = definition.options ?? {};
|
|
298
|
+
const known = new Set(["format", "symbol", "disabled", ...Object.keys(optionSchemas)]);
|
|
299
|
+
if (definition.styleDefaults) {
|
|
300
|
+
for (const field of Object.keys(definition.styleDefaults)) known.add(field);
|
|
301
|
+
} else if (!definition.displayDefaults) known.add("style");
|
|
302
|
+
if (definition.displayDefaults) known.add("display");
|
|
313
303
|
if (name === "extension_status") {
|
|
314
304
|
known.add("separator");
|
|
315
305
|
known.add("max_statuses");
|
|
@@ -337,11 +327,31 @@ function normalizeModule(
|
|
|
337
327
|
}
|
|
338
328
|
}
|
|
339
329
|
}
|
|
340
|
-
|
|
341
|
-
if (value
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
330
|
+
if (value.symbol !== undefined) {
|
|
331
|
+
if (typeof value.symbol !== "string") {
|
|
332
|
+
diagnostics.push(typeDiagnostic(`${name}.symbol`, "string"));
|
|
333
|
+
} else module.symbol = value.symbol;
|
|
334
|
+
}
|
|
335
|
+
if (definition.styleDefaults) {
|
|
336
|
+
for (const field of Object.keys(definition.styleDefaults)) {
|
|
337
|
+
if (value[field] === undefined) continue;
|
|
338
|
+
if (typeof value[field] !== "string") {
|
|
339
|
+
diagnostics.push(typeDiagnostic(`${name}.${field}`, "string"));
|
|
340
|
+
} else module.styles[field] = value[field];
|
|
341
|
+
}
|
|
342
|
+
} else if (!definition.displayDefaults && value.style !== undefined) {
|
|
343
|
+
if (typeof value.style !== "string") {
|
|
344
|
+
diagnostics.push(typeDiagnostic(`${name}.style`, "string"));
|
|
345
|
+
} else module.style = value.style;
|
|
346
|
+
}
|
|
347
|
+
if (definition.displayDefaults && value.display !== undefined) {
|
|
348
|
+
module.display = normalizeDisplay(
|
|
349
|
+
name,
|
|
350
|
+
value.display,
|
|
351
|
+
definition.displayDefaults,
|
|
352
|
+
activePalette(config),
|
|
353
|
+
diagnostics,
|
|
354
|
+
);
|
|
345
355
|
}
|
|
346
356
|
if (value.disabled !== undefined) {
|
|
347
357
|
if (typeof value.disabled !== "boolean") {
|
|
@@ -513,6 +523,8 @@ function cloneBuiltInConfig(): StarshipConfig {
|
|
|
513
523
|
{
|
|
514
524
|
...BUILT_IN_CONFIG.modules[name],
|
|
515
525
|
formatAst: structuredClone(BUILT_IN_CONFIG.modules[name].formatAst),
|
|
526
|
+
styles: { ...BUILT_IN_CONFIG.modules[name].styles },
|
|
527
|
+
display: structuredClone(BUILT_IN_CONFIG.modules[name].display),
|
|
516
528
|
options: structuredClone(BUILT_IN_CONFIG.modules[name].options),
|
|
517
529
|
},
|
|
518
530
|
]),
|
|
@@ -560,6 +572,107 @@ function validateStyleVariables(
|
|
|
560
572
|
}
|
|
561
573
|
}
|
|
562
574
|
|
|
575
|
+
function validateModuleStyleField(
|
|
576
|
+
name: ModuleName,
|
|
577
|
+
field: string,
|
|
578
|
+
module: ModuleConfig,
|
|
579
|
+
palette: ColorPalette,
|
|
580
|
+
diagnostics: ConfigDiagnostic[],
|
|
581
|
+
) {
|
|
582
|
+
const style = field === "style" ? module.style : module.styles[field];
|
|
583
|
+
if (style === undefined || isValidStyle(style, palette)) return;
|
|
584
|
+
diagnostics.push(
|
|
585
|
+
diagnostic(
|
|
586
|
+
"warning",
|
|
587
|
+
`${name}.${field}`,
|
|
588
|
+
`Invalid style ${JSON.stringify(style)}; using the module default`,
|
|
589
|
+
),
|
|
590
|
+
);
|
|
591
|
+
if (field === "style") module.style = BUILT_IN_CONFIG.modules[name].style;
|
|
592
|
+
else {
|
|
593
|
+
const fallback = BUILT_IN_CONFIG.modules[name].styles[field];
|
|
594
|
+
if (fallback !== undefined) module.styles[field] = fallback;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function normalizeDisplay(
|
|
599
|
+
name: ModuleName,
|
|
600
|
+
value: unknown,
|
|
601
|
+
defaults: readonly ModuleDisplayConfig[],
|
|
602
|
+
palette: ColorPalette,
|
|
603
|
+
diagnostics: ConfigDiagnostic[],
|
|
604
|
+
): ModuleDisplayConfig[] {
|
|
605
|
+
if (!Array.isArray(value)) {
|
|
606
|
+
diagnostics.push(typeDiagnostic(`${name}.display`, "array of tables"));
|
|
607
|
+
return defaults.map((entry) => ({ ...entry }));
|
|
608
|
+
}
|
|
609
|
+
const result: ModuleDisplayConfig[] = [];
|
|
610
|
+
for (const [index, entry] of value.entries()) {
|
|
611
|
+
const path = `${name}.display.${index}`;
|
|
612
|
+
if (!isRecord(entry)) {
|
|
613
|
+
diagnostics.push(typeDiagnostic(path, "table"));
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
for (const field of Object.keys(entry)) {
|
|
617
|
+
if (!new Set(["threshold", "style", "hidden"]).has(field)) {
|
|
618
|
+
diagnostics.push(unknownDiagnostic(`${path}.${field}`));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
let valid = true;
|
|
622
|
+
if (typeof entry.threshold !== "number" || !Number.isFinite(entry.threshold)) {
|
|
623
|
+
diagnostics.push(diagnostic("warning", `${path}.threshold`, "Expected a finite number"));
|
|
624
|
+
valid = false;
|
|
625
|
+
}
|
|
626
|
+
if (typeof entry.style !== "string" || !isValidStyle(entry.style, palette)) {
|
|
627
|
+
diagnostics.push(
|
|
628
|
+
diagnostic("warning", `${path}.style`, "Expected a valid Starship style string"),
|
|
629
|
+
);
|
|
630
|
+
valid = false;
|
|
631
|
+
}
|
|
632
|
+
if (typeof entry.hidden !== "boolean") {
|
|
633
|
+
diagnostics.push(typeDiagnostic(`${path}.hidden`, "boolean"));
|
|
634
|
+
valid = false;
|
|
635
|
+
}
|
|
636
|
+
if (valid) {
|
|
637
|
+
result.push({
|
|
638
|
+
threshold: entry.threshold as number,
|
|
639
|
+
style: entry.style as string,
|
|
640
|
+
hidden: entry.hidden as boolean,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (result.length > 0) return result;
|
|
645
|
+
diagnostics.push(
|
|
646
|
+
diagnostic("warning", `${name}.display`, "Expected at least one valid entry; using defaults"),
|
|
647
|
+
);
|
|
648
|
+
return defaults.map((entry) => ({ ...entry }));
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function validateLiteralStyles(
|
|
652
|
+
ast: readonly FormatNode[],
|
|
653
|
+
palette: ColorPalette,
|
|
654
|
+
path: string,
|
|
655
|
+
diagnostics: ConfigDiagnostic[],
|
|
656
|
+
) {
|
|
657
|
+
for (const node of ast) {
|
|
658
|
+
if (node.type === "group" && node.style.every((part) => part.type === "text")) {
|
|
659
|
+
const style = node.style.map((part) => (part.type === "text" ? part.value : "")).join("");
|
|
660
|
+
if (!isValidStyle(style, palette)) {
|
|
661
|
+
diagnostics.push(
|
|
662
|
+
diagnostic(
|
|
663
|
+
"warning",
|
|
664
|
+
path,
|
|
665
|
+
`Invalid literal style ${JSON.stringify(style)}; rendered unstyled`,
|
|
666
|
+
),
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (node.type === "group" || node.type === "conditional") {
|
|
671
|
+
validateLiteralStyles(node.children, palette, path, diagnostics);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
563
676
|
function normalizeModuleOption(
|
|
564
677
|
value: unknown,
|
|
565
678
|
schema: ModuleOptionSchema,
|
|
@@ -666,15 +779,12 @@ function formatError(error: unknown): string {
|
|
|
666
779
|
}
|
|
667
780
|
|
|
668
781
|
export function activePalette(config: StarshipConfig): ColorPalette {
|
|
669
|
-
return {
|
|
670
|
-
...ownPalette(config.palettes, BUILT_IN_CONFIG.palette),
|
|
671
|
-
...ownPalette(config.palettes, config.palette),
|
|
672
|
-
};
|
|
782
|
+
return ownPalette(config.palettes, config.palette) ?? {};
|
|
673
783
|
}
|
|
674
784
|
|
|
675
785
|
function ownPalette(
|
|
676
786
|
palettes: Readonly<Record<string, Record<string, string>>>,
|
|
677
|
-
name: string,
|
|
787
|
+
name: string | undefined,
|
|
678
788
|
): Record<string, string> | undefined {
|
|
679
|
-
return Object.hasOwn(palettes, name) ? palettes[name] : undefined;
|
|
789
|
+
return name !== undefined && Object.hasOwn(palettes, name) ? palettes[name] : undefined;
|
|
680
790
|
}
|
package/src/format/style.ts
CHANGED
|
@@ -19,12 +19,15 @@ export type NamedColor =
|
|
|
19
19
|
export type ColorSpec =
|
|
20
20
|
| { kind: "named"; name: NamedColor }
|
|
21
21
|
| { kind: "fixed"; value: number }
|
|
22
|
-
| { kind: "rgb"; red: number; green: number; blue: number }
|
|
23
|
-
|
|
22
|
+
| { kind: "rgb"; red: number; green: number; blue: number };
|
|
23
|
+
|
|
24
|
+
export type PreviousColorSource = "foreground" | "background";
|
|
24
25
|
|
|
25
26
|
export interface TextStyle {
|
|
26
27
|
foreground?: ColorSpec;
|
|
27
28
|
background?: ColorSpec;
|
|
29
|
+
foregroundPrevious?: PreviousColorSource;
|
|
30
|
+
backgroundPrevious?: PreviousColorSource;
|
|
28
31
|
bold?: boolean;
|
|
29
32
|
italic?: boolean;
|
|
30
33
|
underline?: boolean;
|
|
@@ -35,6 +38,10 @@ export interface TextStyle {
|
|
|
35
38
|
strikethrough?: boolean;
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
export type StyleParseResult =
|
|
42
|
+
| { valid: true; style: TextStyle | undefined }
|
|
43
|
+
| { valid: false; style: undefined };
|
|
44
|
+
|
|
38
45
|
export interface StyledChunk {
|
|
39
46
|
text: string;
|
|
40
47
|
style?: TextStyle;
|
|
@@ -92,41 +99,53 @@ const FOREGROUND_CODES: Record<NamedColor, number> = {
|
|
|
92
99
|
};
|
|
93
100
|
|
|
94
101
|
export function isValidStyle(styleString: string, palette: ColorPalette = {}): boolean {
|
|
95
|
-
|
|
96
|
-
const token = rawToken.toLowerCase();
|
|
97
|
-
if (token === "none" || token === "fg:none" || token === "bg:none") continue;
|
|
98
|
-
const probe: TextStyle = {};
|
|
99
|
-
if (applyModifier(probe, token)) continue;
|
|
100
|
-
const colorToken = token.startsWith("fg:") || token.startsWith("bg:") ? token.slice(3) : token;
|
|
101
|
-
if (!parseColor(colorToken, palette)) return false;
|
|
102
|
-
}
|
|
103
|
-
return true;
|
|
102
|
+
return parseStyleResult(styleString, palette).valid;
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
export function
|
|
105
|
+
export function parseStyleResult(
|
|
106
|
+
styleString: string,
|
|
107
|
+
palette: ColorPalette = {},
|
|
108
|
+
): StyleParseResult {
|
|
109
|
+
const tokens = styleString.split(/\s+/u).filter(Boolean).map(normalizeStyleToken);
|
|
110
|
+
if (tokens.some(({ token, foreground }) => foreground && token === "none")) {
|
|
111
|
+
return { valid: true, style: undefined };
|
|
112
|
+
}
|
|
113
|
+
|
|
107
114
|
const style: TextStyle = {};
|
|
108
|
-
for (const
|
|
109
|
-
|
|
110
|
-
if (token === "
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
for (const { token, foreground } of tokens) {
|
|
116
|
+
if (applyModifier(style, token)) continue;
|
|
117
|
+
if (token === "prev_fg" || token === "prev_bg") {
|
|
118
|
+
const source = token === "prev_fg" ? "foreground" : "background";
|
|
119
|
+
if (foreground) style.foregroundPrevious = source;
|
|
120
|
+
else style.backgroundPrevious = source;
|
|
113
121
|
continue;
|
|
114
122
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const foreground = token.startsWith("fg:");
|
|
118
|
-
const background = token.startsWith("bg:");
|
|
119
|
-
const colorToken = foreground || background ? token.slice(3) : token;
|
|
120
|
-
if (background && colorToken === "none") {
|
|
123
|
+
const color = parseColor(token, palette);
|
|
124
|
+
if (!foreground && !color) {
|
|
121
125
|
delete style.background;
|
|
122
126
|
continue;
|
|
123
127
|
}
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
else style.foreground = color;
|
|
128
|
+
if (!color) return { valid: false, style: undefined };
|
|
129
|
+
if (foreground) style.foreground = color;
|
|
130
|
+
else style.background = color;
|
|
128
131
|
}
|
|
129
|
-
return
|
|
132
|
+
return { valid: true, style };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function parseStyle(styleString: string, palette: ColorPalette = {}): TextStyle | undefined {
|
|
136
|
+
return parseStyleResult(styleString, palette).style;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function normalizeStyleToken(rawToken: string): { token: string; foreground: boolean } {
|
|
140
|
+
let token = rawToken.toLowerCase();
|
|
141
|
+
if (token.startsWith("fg:")) {
|
|
142
|
+
return { token: token.replace(/^(?:fg:)+/u, ""), foreground: true };
|
|
143
|
+
}
|
|
144
|
+
if (token.startsWith("bg:")) {
|
|
145
|
+
token = token.replace(/^(?:bg:)+/u, "");
|
|
146
|
+
return { token, foreground: false };
|
|
147
|
+
}
|
|
148
|
+
return { token, foreground: true };
|
|
130
149
|
}
|
|
131
150
|
|
|
132
151
|
function applyModifier(style: TextStyle, token: string): boolean {
|
|
@@ -161,8 +180,6 @@ function applyModifier(style: TextStyle, token: string): boolean {
|
|
|
161
180
|
}
|
|
162
181
|
|
|
163
182
|
export function parseColor(token: string, palette: ColorPalette = {}): ColorSpec | undefined {
|
|
164
|
-
if (token === "prev_fg") return { kind: "previous", source: "foreground" };
|
|
165
|
-
if (token === "prev_bg") return { kind: "previous", source: "background" };
|
|
166
183
|
const paletteValue = Object.hasOwn(palette, token) ? palette[token] : undefined;
|
|
167
184
|
if (paletteValue !== undefined) return parseColor(paletteValue.toLowerCase(), {});
|
|
168
185
|
if (NAMED_COLORS.has(token as NamedColor)) {
|
|
@@ -182,9 +199,13 @@ export function parseColor(token: string, palette: ColorPalette = {}): ColorSpec
|
|
|
182
199
|
};
|
|
183
200
|
}
|
|
184
201
|
|
|
185
|
-
interface ResolvedStyle
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
interface ResolvedStyle
|
|
203
|
+
extends Omit<
|
|
204
|
+
TextStyle,
|
|
205
|
+
"foreground" | "background" | "foregroundPrevious" | "backgroundPrevious"
|
|
206
|
+
> {
|
|
207
|
+
foreground?: ColorSpec;
|
|
208
|
+
background?: ColorSpec;
|
|
188
209
|
}
|
|
189
210
|
|
|
190
211
|
export function renderChunksToAnsi(chunks: readonly LayoutChunk[]): string {
|
|
@@ -215,20 +236,21 @@ function resolveStyle(
|
|
|
215
236
|
previous: ResolvedStyle | undefined,
|
|
216
237
|
): ResolvedStyle {
|
|
217
238
|
if (!style) return {};
|
|
239
|
+
const { foregroundPrevious, backgroundPrevious, ...resolved } = style;
|
|
218
240
|
return {
|
|
219
|
-
...
|
|
220
|
-
foreground: resolveColor(style.foreground, previous),
|
|
221
|
-
background: resolveColor(style.background, previous),
|
|
241
|
+
...resolved,
|
|
242
|
+
foreground: resolveColor(style.foreground, foregroundPrevious, previous),
|
|
243
|
+
background: resolveColor(style.background, backgroundPrevious, previous),
|
|
222
244
|
};
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
function resolveColor(
|
|
226
|
-
|
|
248
|
+
fallback: ColorSpec | undefined,
|
|
249
|
+
source: PreviousColorSource | undefined,
|
|
227
250
|
previous: ResolvedStyle | undefined,
|
|
228
|
-
):
|
|
229
|
-
if (!
|
|
230
|
-
|
|
231
|
-
return color.source === "foreground" ? previous?.foreground : previous?.background;
|
|
251
|
+
): ColorSpec | undefined {
|
|
252
|
+
if (!source || !previous) return fallback;
|
|
253
|
+
return source === "foreground" ? previous.foreground : previous.background;
|
|
232
254
|
}
|
|
233
255
|
|
|
234
256
|
function ansiCodes(style: ResolvedStyle): string[] {
|
|
@@ -246,10 +268,7 @@ function ansiCodes(style: ResolvedStyle): string[] {
|
|
|
246
268
|
return codes;
|
|
247
269
|
}
|
|
248
270
|
|
|
249
|
-
function colorCodes(
|
|
250
|
-
color: Exclude<ColorSpec, { kind: "previous" }>,
|
|
251
|
-
background: boolean,
|
|
252
|
-
): string[] {
|
|
271
|
+
function colorCodes(color: ColorSpec, background: boolean): string[] {
|
|
253
272
|
if (color.kind === "named") {
|
|
254
273
|
const foreground = FOREGROUND_CODES[color.name];
|
|
255
274
|
return [`${background ? foreground + 10 : foreground}`];
|
package/src/modules/activity.ts
CHANGED
package/src/modules/brand.ts
CHANGED
package/src/modules/cache.ts
CHANGED
package/src/modules/catalog.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { gitMetricsModule } from "./git/metrics.js";
|
|
|
16
16
|
import { gitStateModule } from "./git/state.js";
|
|
17
17
|
import { gitStatusModule } from "./git/status.js";
|
|
18
18
|
import { gitWorktreeModule } from "./git/worktree.js";
|
|
19
|
+
import { githubPrModule } from "./github-pr.js";
|
|
19
20
|
import { languageModules } from "./languages.js";
|
|
20
21
|
import { modelModule } from "./model.js";
|
|
21
22
|
import { packageModule } from "./package.js";
|
|
@@ -26,7 +27,7 @@ import { tokensModule } from "./tokens.js";
|
|
|
26
27
|
import { turnModule } from "./turn.js";
|
|
27
28
|
import type { ModuleDefinition } from "./types.js";
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
const MODULE_IMPLEMENTATIONS = [
|
|
30
31
|
brandModule,
|
|
31
32
|
providerModule,
|
|
32
33
|
modelModule,
|
|
@@ -34,6 +35,7 @@ export const MODULE_DEFINITIONS = [
|
|
|
34
35
|
directoryModule,
|
|
35
36
|
gitWorktreeModule,
|
|
36
37
|
gitBranchModule,
|
|
38
|
+
githubPrModule,
|
|
37
39
|
gitCommitModule,
|
|
38
40
|
gitStateModule,
|
|
39
41
|
gitMetricsModule,
|
|
@@ -52,12 +54,71 @@ export const MODULE_DEFINITIONS = [
|
|
|
52
54
|
timeModule,
|
|
53
55
|
turnModule,
|
|
54
56
|
fillModule,
|
|
55
|
-
//
|
|
57
|
+
// Keep arbitrary third-party statuses after the native modules.
|
|
56
58
|
extensionStatusModule,
|
|
57
59
|
] as const satisfies readonly ModuleDefinition<string>[];
|
|
58
60
|
|
|
59
|
-
export type ModuleName = (typeof
|
|
61
|
+
export type ModuleName = (typeof MODULE_IMPLEMENTATIONS)[number]["name"];
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
const MODULE_DESCRIPTIONS = {
|
|
64
|
+
activity: "Current Pi activity or most recently completed tool.",
|
|
65
|
+
aws: "Active AWS profile and region.",
|
|
66
|
+
azure: "Active Azure subscription and optional username.",
|
|
67
|
+
brand: "pi-starship brand mark.",
|
|
68
|
+
bun: "Bun version detected in the current workspace.",
|
|
69
|
+
cache: "Prompt-cache usage and latest cache hit rate.",
|
|
70
|
+
conda: "Active Conda environment.",
|
|
71
|
+
container: "Current container or remote development environment.",
|
|
72
|
+
context: "Current model context-window usage.",
|
|
73
|
+
cost: "Reported estimated session cost or subscription state.",
|
|
74
|
+
deno: "Deno version detected in the current workspace.",
|
|
75
|
+
directory: "Current working directory.",
|
|
76
|
+
direnv: "Current direnv loading and permission state.",
|
|
77
|
+
docker_context: "Active Docker context.",
|
|
78
|
+
extension_status: "Statuses published through Pi's extension-neutral status map.",
|
|
79
|
+
fill: "Flexible spacing that aligns content within the footer width.",
|
|
80
|
+
gcloud: "Active Google Cloud project, account, and region.",
|
|
81
|
+
git_branch: "Current Git branch and upstream identity.",
|
|
82
|
+
git_commit: "Current Git commit hash or tag.",
|
|
83
|
+
git_metrics: "Added and deleted lines in the current Git worktree.",
|
|
84
|
+
git_state: "Current Git operation such as merge, rebase, or cherry-pick.",
|
|
85
|
+
git_status: "Current Git worktree and index status summary.",
|
|
86
|
+
git_worktree: "Current linked Git worktree identity.",
|
|
87
|
+
github_pr: "Current branch's GitHub pull request state, checks, and review.",
|
|
88
|
+
golang: "Go version detected in the current workspace.",
|
|
89
|
+
guix_shell: "Current Guix shell state.",
|
|
90
|
+
hostname: "Current host name, normally shown for remote sessions.",
|
|
91
|
+
kubernetes: "Active Kubernetes context, namespace, cluster, and user.",
|
|
92
|
+
mise: "Current mise configuration health.",
|
|
93
|
+
model: "Current Pi model.",
|
|
94
|
+
nix_shell: "Current Nix shell state, name, and nesting level.",
|
|
95
|
+
nodejs: "Node.js version detected in the current workspace.",
|
|
96
|
+
openstack: "Active OpenStack cloud and project.",
|
|
97
|
+
os: "Current operating system identity.",
|
|
98
|
+
package: "Current workspace package name and version.",
|
|
99
|
+
pixi: "Active Pixi environment and project.",
|
|
100
|
+
provider: "Current Pi model provider.",
|
|
101
|
+
python: "Python version, virtual environment, and pyenv state.",
|
|
102
|
+
rust: "Rust toolchain detected in the current workspace.",
|
|
103
|
+
terraform: "Active Terraform workspace and version.",
|
|
104
|
+
thinking: "Current Pi thinking level or streaming state.",
|
|
105
|
+
time: "Current local time.",
|
|
106
|
+
tokens: "Session input and output token totals.",
|
|
107
|
+
turn: "Current user-turn count.",
|
|
108
|
+
username: "Current user identity when configured to display.",
|
|
109
|
+
} as const satisfies Record<ModuleName, string>;
|
|
110
|
+
|
|
111
|
+
export type CatalogModuleDefinition<Name extends string = ModuleName> = ModuleDefinition<Name> & {
|
|
112
|
+
readonly description: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const MODULE_DEFINITIONS: readonly CatalogModuleDefinition[] = MODULE_IMPLEMENTATIONS.map(
|
|
116
|
+
(definition) => ({
|
|
117
|
+
...definition,
|
|
118
|
+
description: MODULE_DESCRIPTIONS[definition.name],
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
export const MODULE_NAMES: readonly ModuleName[] = MODULE_IMPLEMENTATIONS.map(
|
|
62
123
|
(definition) => definition.name,
|
|
63
124
|
);
|