@narumitw/pi-starship 0.55.1 → 0.56.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.
Files changed (106) hide show
  1. package/README.md +2 -0
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
  3. package/dist/chunks/chunk-SD7TUSSU.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-MJCAK6JL.js} +18 -42
  11. package/dist/chunks/commands-MJCAK6JL.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +20 -55
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/SKILL.md +18 -4
  26. package/skills/configuring-pi-starship/references/configuration.md +70 -2
  27. package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
  28. package/skills/configuring-pi-starship/references/modules.md +2 -0
  29. package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
  30. package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
  31. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  32. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  33. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  34. package/src/command-configuration.ts +267 -286
  35. package/src/command-contract.ts +6 -6
  36. package/src/command-inspector.ts +27 -27
  37. package/src/command-preset-picker.ts +45 -50
  38. package/src/command-preview.ts +153 -166
  39. package/src/commands.ts +590 -618
  40. package/src/config.ts +635 -660
  41. package/src/effective-config.ts +49 -48
  42. package/src/format/formatter.ts +211 -227
  43. package/src/format/style.ts +205 -216
  44. package/src/modules/activity.ts +74 -74
  45. package/src/modules/brand.ts +9 -9
  46. package/src/modules/cache.ts +18 -18
  47. package/src/modules/catalog.ts +79 -83
  48. package/src/modules/cloud.ts +54 -54
  49. package/src/modules/context.ts +27 -27
  50. package/src/modules/cost.ts +23 -23
  51. package/src/modules/deployment.ts +45 -45
  52. package/src/modules/development.ts +80 -81
  53. package/src/modules/directory.ts +89 -113
  54. package/src/modules/display.ts +9 -9
  55. package/src/modules/execution.ts +62 -69
  56. package/src/modules/extension-status.ts +59 -64
  57. package/src/modules/fill.ts +10 -10
  58. package/src/modules/git/branch.ts +26 -26
  59. package/src/modules/git/commit.ts +21 -23
  60. package/src/modules/git/metrics.ts +22 -22
  61. package/src/modules/git/runtime.ts +299 -334
  62. package/src/modules/git/state.ts +17 -17
  63. package/src/modules/git/status.ts +77 -79
  64. package/src/modules/git/worktree.ts +10 -12
  65. package/src/modules/github-pr.ts +20 -20
  66. package/src/modules/helpers.ts +3 -3
  67. package/src/modules/index.ts +21 -21
  68. package/src/modules/inspection.ts +105 -108
  69. package/src/modules/languages.ts +52 -59
  70. package/src/modules/model.ts +61 -67
  71. package/src/modules/package.ts +12 -12
  72. package/src/modules/provider.ts +25 -24
  73. package/src/modules/render.ts +131 -141
  74. package/src/modules/style-rules.ts +21 -0
  75. package/src/modules/thinking.ts +31 -26
  76. package/src/modules/time.ts +10 -13
  77. package/src/modules/tokens.ts +13 -13
  78. package/src/modules/truncation.ts +14 -17
  79. package/src/modules/turn.ts +9 -9
  80. package/src/modules/types.ts +133 -132
  81. package/src/modules/workspace-helpers.ts +4 -7
  82. package/src/pi-starship.ts +567 -603
  83. package/src/presets/catalog.ts +113 -113
  84. package/src/runtime/cloud.ts +122 -150
  85. package/src/runtime/command.ts +106 -108
  86. package/src/runtime/deployment.ts +150 -179
  87. package/src/runtime/development.ts +107 -124
  88. package/src/runtime/execution.ts +110 -124
  89. package/src/runtime/github-pr.ts +223 -252
  90. package/src/runtime/helpers.ts +186 -199
  91. package/src/runtime/languages.ts +149 -180
  92. package/src/runtime/package.ts +74 -87
  93. package/src/runtime/refresh-controller.ts +82 -86
  94. package/src/runtime/types.ts +38 -38
  95. package/src/runtime/workspace.ts +108 -116
  96. package/src/usage.ts +40 -40
  97. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  98. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  99. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  100. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  101. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  102. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  103. package/dist/chunks/development-BERD42HW.js.map +0 -7
  104. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  105. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  106. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -1,286 +1,275 @@
1
1
  export type NamedColor =
2
- | "black"
3
- | "red"
4
- | "green"
5
- | "yellow"
6
- | "blue"
7
- | "purple"
8
- | "cyan"
9
- | "white"
10
- | "bright-black"
11
- | "bright-red"
12
- | "bright-green"
13
- | "bright-yellow"
14
- | "bright-blue"
15
- | "bright-purple"
16
- | "bright-cyan"
17
- | "bright-white";
2
+ | "black"
3
+ | "red"
4
+ | "green"
5
+ | "yellow"
6
+ | "blue"
7
+ | "purple"
8
+ | "cyan"
9
+ | "white"
10
+ | "bright-black"
11
+ | "bright-red"
12
+ | "bright-green"
13
+ | "bright-yellow"
14
+ | "bright-blue"
15
+ | "bright-purple"
16
+ | "bright-cyan"
17
+ | "bright-white";
18
18
 
19
19
  export type ColorSpec =
20
- | { kind: "named"; name: NamedColor }
21
- | { kind: "fixed"; value: number }
22
- | { kind: "rgb"; red: number; green: number; blue: number };
20
+ | { kind: "named"; name: NamedColor }
21
+ | { kind: "fixed"; value: number }
22
+ | { kind: "rgb"; red: number; green: number; blue: number };
23
23
 
24
24
  export type PreviousColorSource = "foreground" | "background";
25
25
 
26
26
  export interface TextStyle {
27
- foreground?: ColorSpec;
28
- background?: ColorSpec;
29
- foregroundPrevious?: PreviousColorSource;
30
- backgroundPrevious?: PreviousColorSource;
31
- bold?: boolean;
32
- italic?: boolean;
33
- underline?: boolean;
34
- dimmed?: boolean;
35
- inverted?: boolean;
36
- blink?: boolean;
37
- hidden?: boolean;
38
- strikethrough?: boolean;
27
+ foreground?: ColorSpec;
28
+ background?: ColorSpec;
29
+ foregroundPrevious?: PreviousColorSource;
30
+ backgroundPrevious?: PreviousColorSource;
31
+ bold?: boolean;
32
+ italic?: boolean;
33
+ underline?: boolean;
34
+ dimmed?: boolean;
35
+ inverted?: boolean;
36
+ blink?: boolean;
37
+ hidden?: boolean;
38
+ strikethrough?: boolean;
39
39
  }
40
40
 
41
- export type StyleParseResult =
42
- | { valid: true; style: TextStyle | undefined }
43
- | { valid: false; style: undefined };
41
+ export type StyleParseResult = { valid: true; style: TextStyle | undefined } | { valid: false; style: undefined };
44
42
 
45
43
  export interface StyledChunk {
46
- text: string;
47
- style?: TextStyle;
44
+ text: string;
45
+ style?: TextStyle;
48
46
  }
49
47
 
50
48
  export interface FillChunk {
51
- type: "fill";
52
- pattern: readonly StyledChunk[];
49
+ type: "fill";
50
+ pattern: readonly StyledChunk[];
53
51
  }
54
52
 
55
53
  export type LayoutChunk = StyledChunk | FillChunk;
56
54
 
57
55
  export function isFillChunk(chunk: LayoutChunk): chunk is FillChunk {
58
- return "type" in chunk && chunk.type === "fill";
56
+ return "type" in chunk && chunk.type === "fill";
59
57
  }
60
58
 
61
59
  export type ColorPalette = Readonly<Record<string, string>>;
62
60
 
63
61
  const NAMED_COLORS = new Set<NamedColor>([
64
- "black",
65
- "red",
66
- "green",
67
- "yellow",
68
- "blue",
69
- "purple",
70
- "cyan",
71
- "white",
72
- "bright-black",
73
- "bright-red",
74
- "bright-green",
75
- "bright-yellow",
76
- "bright-blue",
77
- "bright-purple",
78
- "bright-cyan",
79
- "bright-white",
62
+ "black",
63
+ "red",
64
+ "green",
65
+ "yellow",
66
+ "blue",
67
+ "purple",
68
+ "cyan",
69
+ "white",
70
+ "bright-black",
71
+ "bright-red",
72
+ "bright-green",
73
+ "bright-yellow",
74
+ "bright-blue",
75
+ "bright-purple",
76
+ "bright-cyan",
77
+ "bright-white",
80
78
  ]);
81
79
 
82
80
  const FOREGROUND_CODES: Record<NamedColor, number> = {
83
- black: 30,
84
- red: 31,
85
- green: 32,
86
- yellow: 33,
87
- blue: 34,
88
- purple: 35,
89
- cyan: 36,
90
- white: 37,
91
- "bright-black": 90,
92
- "bright-red": 91,
93
- "bright-green": 92,
94
- "bright-yellow": 93,
95
- "bright-blue": 94,
96
- "bright-purple": 95,
97
- "bright-cyan": 96,
98
- "bright-white": 97,
81
+ black: 30,
82
+ red: 31,
83
+ green: 32,
84
+ yellow: 33,
85
+ blue: 34,
86
+ purple: 35,
87
+ cyan: 36,
88
+ white: 37,
89
+ "bright-black": 90,
90
+ "bright-red": 91,
91
+ "bright-green": 92,
92
+ "bright-yellow": 93,
93
+ "bright-blue": 94,
94
+ "bright-purple": 95,
95
+ "bright-cyan": 96,
96
+ "bright-white": 97,
99
97
  };
100
98
 
101
99
  export function isValidStyle(styleString: string, palette: ColorPalette = {}): boolean {
102
- return parseStyleResult(styleString, palette).valid;
100
+ return parseStyleResult(styleString, palette).valid;
103
101
  }
104
102
 
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
- }
103
+ export function parseStyleResult(styleString: string, palette: ColorPalette = {}): StyleParseResult {
104
+ const tokens = styleString.split(/\s+/u).filter(Boolean).map(normalizeStyleToken);
105
+ if (tokens.some(({ token, foreground }) => foreground && token === "none")) {
106
+ return { valid: true, style: undefined };
107
+ }
113
108
 
114
- const style: TextStyle = {};
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;
121
- continue;
122
- }
123
- const color = parseColor(token, palette);
124
- if (!foreground && !color) {
125
- delete style.background;
126
- continue;
127
- }
128
- if (!color) return { valid: false, style: undefined };
129
- if (foreground) style.foreground = color;
130
- else style.background = color;
131
- }
132
- return { valid: true, style };
109
+ const style: TextStyle = {};
110
+ for (const { token, foreground } of tokens) {
111
+ if (applyModifier(style, token)) continue;
112
+ if (token === "prev_fg" || token === "prev_bg") {
113
+ const source = token === "prev_fg" ? "foreground" : "background";
114
+ if (foreground) style.foregroundPrevious = source;
115
+ else style.backgroundPrevious = source;
116
+ continue;
117
+ }
118
+ const color = parseColor(token, palette);
119
+ if (!foreground && !color) {
120
+ delete style.background;
121
+ continue;
122
+ }
123
+ if (!color) return { valid: false, style: undefined };
124
+ if (foreground) style.foreground = color;
125
+ else style.background = color;
126
+ }
127
+ return { valid: true, style };
133
128
  }
134
129
 
135
130
  export function parseStyle(styleString: string, palette: ColorPalette = {}): TextStyle | undefined {
136
- return parseStyleResult(styleString, palette).style;
131
+ return parseStyleResult(styleString, palette).style;
137
132
  }
138
133
 
139
134
  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 };
135
+ let token = rawToken.toLowerCase();
136
+ if (token.startsWith("fg:")) {
137
+ return { token: token.replace(/^(?:fg:)+/u, ""), foreground: true };
138
+ }
139
+ if (token.startsWith("bg:")) {
140
+ token = token.replace(/^(?:bg:)+/u, "");
141
+ return { token, foreground: false };
142
+ }
143
+ return { token, foreground: true };
149
144
  }
150
145
 
151
146
  function applyModifier(style: TextStyle, token: string): boolean {
152
- switch (token) {
153
- case "bold":
154
- style.bold = true;
155
- return true;
156
- case "italic":
157
- style.italic = true;
158
- return true;
159
- case "underline":
160
- style.underline = true;
161
- return true;
162
- case "dimmed":
163
- style.dimmed = true;
164
- return true;
165
- case "inverted":
166
- style.inverted = true;
167
- return true;
168
- case "blink":
169
- style.blink = true;
170
- return true;
171
- case "hidden":
172
- style.hidden = true;
173
- return true;
174
- case "strikethrough":
175
- style.strikethrough = true;
176
- return true;
177
- default:
178
- return false;
179
- }
147
+ switch (token) {
148
+ case "bold":
149
+ style.bold = true;
150
+ return true;
151
+ case "italic":
152
+ style.italic = true;
153
+ return true;
154
+ case "underline":
155
+ style.underline = true;
156
+ return true;
157
+ case "dimmed":
158
+ style.dimmed = true;
159
+ return true;
160
+ case "inverted":
161
+ style.inverted = true;
162
+ return true;
163
+ case "blink":
164
+ style.blink = true;
165
+ return true;
166
+ case "hidden":
167
+ style.hidden = true;
168
+ return true;
169
+ case "strikethrough":
170
+ style.strikethrough = true;
171
+ return true;
172
+ default:
173
+ return false;
174
+ }
180
175
  }
181
176
 
182
177
  export function parseColor(token: string, palette: ColorPalette = {}): ColorSpec | undefined {
183
- const paletteValue = Object.hasOwn(palette, token) ? palette[token] : undefined;
184
- if (paletteValue !== undefined) return parseColor(paletteValue.toLowerCase(), {});
185
- if (NAMED_COLORS.has(token as NamedColor)) {
186
- return { kind: "named", name: token as NamedColor };
187
- }
188
- if (/^\d{1,3}$/u.test(token)) {
189
- const value = Number(token);
190
- return value <= 255 ? { kind: "fixed", value } : undefined;
191
- }
192
- const rgb = /^#([0-9a-f]{6})$/iu.exec(token);
193
- if (!rgb?.[1]) return undefined;
194
- return {
195
- kind: "rgb",
196
- red: Number.parseInt(rgb[1].slice(0, 2), 16),
197
- green: Number.parseInt(rgb[1].slice(2, 4), 16),
198
- blue: Number.parseInt(rgb[1].slice(4, 6), 16),
199
- };
178
+ const paletteValue = Object.hasOwn(palette, token) ? palette[token] : undefined;
179
+ if (paletteValue !== undefined) return parseColor(paletteValue.toLowerCase(), {});
180
+ if (NAMED_COLORS.has(token as NamedColor)) {
181
+ return { kind: "named", name: token as NamedColor };
182
+ }
183
+ if (/^\d{1,3}$/u.test(token)) {
184
+ const value = Number(token);
185
+ return value <= 255 ? { kind: "fixed", value } : undefined;
186
+ }
187
+ const rgb = /^#([0-9a-f]{6})$/iu.exec(token);
188
+ if (!rgb?.[1]) return undefined;
189
+ return {
190
+ kind: "rgb",
191
+ red: Number.parseInt(rgb[1].slice(0, 2), 16),
192
+ green: Number.parseInt(rgb[1].slice(2, 4), 16),
193
+ blue: Number.parseInt(rgb[1].slice(4, 6), 16),
194
+ };
200
195
  }
201
196
 
202
197
  interface ResolvedStyle
203
- extends Omit<
204
- TextStyle,
205
- "foreground" | "background" | "foregroundPrevious" | "backgroundPrevious"
206
- > {
207
- foreground?: ColorSpec;
208
- background?: ColorSpec;
198
+ extends Omit<TextStyle, "foreground" | "background" | "foregroundPrevious" | "backgroundPrevious"> {
199
+ foreground?: ColorSpec;
200
+ background?: ColorSpec;
209
201
  }
210
202
 
211
203
  export function renderChunksToAnsi(chunks: readonly LayoutChunk[], trueColor = true): string {
212
- const runs: Array<{ text: string; style: ResolvedStyle }> = [];
213
- let previous: ResolvedStyle | undefined;
214
- for (const chunk of chunks) {
215
- if (isFillChunk(chunk)) continue;
216
- const style = resolveStyle(chunk.style, previous);
217
- const last = runs.at(-1);
218
- if (chunk.text && last && stylesEqual(last.style, style)) last.text += chunk.text;
219
- else if (chunk.text) runs.push({ text: chunk.text, style });
220
- previous = style;
221
- }
222
- return runs
223
- .map(({ text, style }) => {
224
- const codes = ansiCodes(style, trueColor);
225
- return codes.length > 0 ? `\u001b[${codes.join(";")}m${text}\u001b[0m` : text;
226
- })
227
- .join("");
204
+ const runs: Array<{ text: string; style: ResolvedStyle }> = [];
205
+ let previous: ResolvedStyle | undefined;
206
+ for (const chunk of chunks) {
207
+ if (isFillChunk(chunk)) continue;
208
+ const style = resolveStyle(chunk.style, previous);
209
+ const last = runs.at(-1);
210
+ if (chunk.text && last && stylesEqual(last.style, style)) last.text += chunk.text;
211
+ else if (chunk.text) runs.push({ text: chunk.text, style });
212
+ previous = style;
213
+ }
214
+ return runs
215
+ .map(({ text, style }) => {
216
+ const codes = ansiCodes(style, trueColor);
217
+ return codes.length > 0 ? `\u001b[${codes.join(";")}m${text}\u001b[0m` : text;
218
+ })
219
+ .join("");
228
220
  }
229
221
 
230
222
  function stylesEqual(left: ResolvedStyle, right: ResolvedStyle): boolean {
231
- return JSON.stringify(left) === JSON.stringify(right);
223
+ return JSON.stringify(left) === JSON.stringify(right);
232
224
  }
233
225
 
234
- function resolveStyle(
235
- style: TextStyle | undefined,
236
- previous: ResolvedStyle | undefined,
237
- ): ResolvedStyle {
238
- if (!style) return {};
239
- const { foregroundPrevious, backgroundPrevious, ...resolved } = style;
240
- return {
241
- ...resolved,
242
- foreground: resolveColor(style.foreground, foregroundPrevious, previous),
243
- background: resolveColor(style.background, backgroundPrevious, previous),
244
- };
226
+ function resolveStyle(style: TextStyle | undefined, previous: ResolvedStyle | undefined): ResolvedStyle {
227
+ if (!style) return {};
228
+ const { foregroundPrevious, backgroundPrevious, ...resolved } = style;
229
+ return {
230
+ ...resolved,
231
+ foreground: resolveColor(style.foreground, foregroundPrevious, previous),
232
+ background: resolveColor(style.background, backgroundPrevious, previous),
233
+ };
245
234
  }
246
235
 
247
236
  function resolveColor(
248
- fallback: ColorSpec | undefined,
249
- source: PreviousColorSource | undefined,
250
- previous: ResolvedStyle | undefined,
237
+ fallback: ColorSpec | undefined,
238
+ source: PreviousColorSource | undefined,
239
+ previous: ResolvedStyle | undefined,
251
240
  ): ColorSpec | undefined {
252
- if (!source || !previous) return fallback;
253
- return source === "foreground" ? previous.foreground : previous.background;
241
+ if (!source || !previous) return fallback;
242
+ return source === "foreground" ? previous.foreground : previous.background;
254
243
  }
255
244
 
256
245
  function ansiCodes(style: ResolvedStyle, trueColor: boolean): string[] {
257
- const codes: string[] = [];
258
- if (style.foreground) codes.push(...colorCodes(style.foreground, false, trueColor));
259
- if (style.background) codes.push(...colorCodes(style.background, true, trueColor));
260
- if (style.bold) codes.push("1");
261
- if (style.dimmed) codes.push("2");
262
- if (style.italic) codes.push("3");
263
- if (style.underline) codes.push("4");
264
- if (style.blink) codes.push("5");
265
- if (style.inverted) codes.push("7");
266
- if (style.hidden) codes.push("8");
267
- if (style.strikethrough) codes.push("9");
268
- return codes;
246
+ const codes: string[] = [];
247
+ if (style.foreground) codes.push(...colorCodes(style.foreground, false, trueColor));
248
+ if (style.background) codes.push(...colorCodes(style.background, true, trueColor));
249
+ if (style.bold) codes.push("1");
250
+ if (style.dimmed) codes.push("2");
251
+ if (style.italic) codes.push("3");
252
+ if (style.underline) codes.push("4");
253
+ if (style.blink) codes.push("5");
254
+ if (style.inverted) codes.push("7");
255
+ if (style.hidden) codes.push("8");
256
+ if (style.strikethrough) codes.push("9");
257
+ return codes;
269
258
  }
270
259
 
271
260
  function colorCodes(color: ColorSpec, background: boolean, trueColor: boolean): string[] {
272
- if (color.kind === "named") {
273
- const foreground = FOREGROUND_CODES[color.name];
274
- return [`${background ? foreground + 10 : foreground}`];
275
- }
276
- if (color.kind === "fixed") return [background ? "48" : "38", "5", `${color.value}`];
277
- if (!trueColor) {
278
- return [background ? "48" : "38", "5", `${rgbToAnsi256(color.red, color.green, color.blue)}`];
279
- }
280
- return [background ? "48" : "38", "2", `${color.red}`, `${color.green}`, `${color.blue}`];
261
+ if (color.kind === "named") {
262
+ const foreground = FOREGROUND_CODES[color.name];
263
+ return [`${background ? foreground + 10 : foreground}`];
264
+ }
265
+ if (color.kind === "fixed") return [background ? "48" : "38", "5", `${color.value}`];
266
+ if (!trueColor) {
267
+ return [background ? "48" : "38", "5", `${rgbToAnsi256(color.red, color.green, color.blue)}`];
268
+ }
269
+ return [background ? "48" : "38", "2", `${color.red}`, `${color.green}`, `${color.blue}`];
281
270
  }
282
271
 
283
272
  function rgbToAnsi256(red: number, green: number, blue: number): number {
284
- const channels = [red, green, blue].map((value) => Math.round((value / 255) * 5));
285
- return 16 + 36 * (channels[0] ?? 0) + 6 * (channels[1] ?? 0) + (channels[2] ?? 0);
273
+ const channels = [red, green, blue].map((value) => Math.round((value / 255) * 5));
274
+ return 16 + 36 * (channels[0] ?? 0) + 6 * (channels[1] ?? 0) + (channels[2] ?? 0);
286
275
  }
@@ -7,85 +7,85 @@ const MAX_UI_PROMPT_TITLE_WIDTH = 40;
7
7
  const EMPTY_PROMPT_VALUES = { kind: "", title: "" } as const;
8
8
 
9
9
  function boundUIPromptTitleLength(title: string): string {
10
- let end = 0;
11
- let ellipsisEnd = 0;
12
- let codePoints = 0;
13
- while (end < title.length && codePoints < MAX_UI_PROMPT_TITLE_CODE_POINTS) {
14
- const codePoint = title.codePointAt(end) ?? 0;
15
- end += codePoint > 0xffff ? 2 : 1;
16
- codePoints += 1;
17
- if (codePoints < MAX_UI_PROMPT_TITLE_CODE_POINTS) ellipsisEnd = end;
18
- }
19
- return end < title.length ? `${title.slice(0, ellipsisEnd)}…` : title;
10
+ let end = 0;
11
+ let ellipsisEnd = 0;
12
+ let codePoints = 0;
13
+ while (end < title.length && codePoints < MAX_UI_PROMPT_TITLE_CODE_POINTS) {
14
+ const codePoint = title.codePointAt(end) ?? 0;
15
+ end += codePoint > 0xffff ? 2 : 1;
16
+ codePoints += 1;
17
+ if (codePoints < MAX_UI_PROMPT_TITLE_CODE_POINTS) ellipsisEnd = end;
18
+ }
19
+ return end < title.length ? `${title.slice(0, ellipsisEnd)}…` : title;
20
20
  }
21
21
 
22
22
  function formatUIPromptTitle(title: string | undefined): string {
23
- const safeTitle = title ? sanitizeTerminalText(title).trim() : "";
24
- const boundedTitle = boundUIPromptTitleLength(safeTitle);
25
- if (visibleWidth(boundedTitle) <= MAX_UI_PROMPT_TITLE_WIDTH) return boundedTitle;
26
- return `${sliceByColumn(boundedTitle, 0, MAX_UI_PROMPT_TITLE_WIDTH - 1, true)}…`;
23
+ const safeTitle = title ? sanitizeTerminalText(title).trim() : "";
24
+ const boundedTitle = boundUIPromptTitleLength(safeTitle);
25
+ if (visibleWidth(boundedTitle) <= MAX_UI_PROMPT_TITLE_WIDTH) return boundedTitle;
26
+ return `${sliceByColumn(boundedTitle, 0, MAX_UI_PROMPT_TITLE_WIDTH - 1, true)}…`;
27
27
  }
28
28
 
29
29
  export const activityModule = defineModule({
30
- name: "activity",
31
- variables: ["symbol", "state", "tool", "count", "kind", "title", "text"],
32
- defaults: {
33
- format: "[ $text ]($style)",
34
- symbol: "⚙️",
35
- style: "bold yellow",
36
- disabled: false,
37
- },
38
- values: ({ runtime, symbol }) => {
39
- if (runtime.uiPrompt) {
40
- const title = formatUIPromptTitle(runtime.uiPrompt.title);
41
- const waiting = `waiting for ${runtime.uiPrompt.kind}${title ? ` · ${title}` : ""}`;
42
- return {
43
- state: "waiting",
44
- tool: "",
45
- count: "0",
46
- kind: runtime.uiPrompt.kind,
47
- title,
48
- text: `${symbol} ${waiting}`,
49
- };
50
- }
30
+ name: "activity",
31
+ variables: ["symbol", "state", "tool", "count", "kind", "title", "text"],
32
+ defaults: {
33
+ format: "[ $text ]($style)",
34
+ symbol: "⚙️",
35
+ style: "bold yellow",
36
+ disabled: false,
37
+ },
38
+ values: ({ runtime, symbol }) => {
39
+ if (runtime.uiPrompt) {
40
+ const title = formatUIPromptTitle(runtime.uiPrompt.title);
41
+ const waiting = `waiting for ${runtime.uiPrompt.kind}${title ? ` · ${title}` : ""}`;
42
+ return {
43
+ state: "waiting",
44
+ tool: "",
45
+ count: "0",
46
+ kind: runtime.uiPrompt.kind,
47
+ title,
48
+ text: `${symbol} ${waiting}`,
49
+ };
50
+ }
51
51
 
52
- const active = [...runtime.activeTools.entries()];
53
- if (active.length > 0) {
54
- const [tool = "tool", count = 1] = active[0] ?? [];
55
- const suffix = count > 1 ? `×${count}` : "";
56
- const more = active.length > 1 ? `+${active.length - 1}` : "";
57
- return {
58
- state: "active",
59
- tool,
60
- count: `${count}`,
61
- ...EMPTY_PROMPT_VALUES,
62
- text: `${symbol} ${tool}${suffix}${more}`,
63
- };
64
- }
65
- if (runtime.isStreaming) {
66
- return {
67
- state: "thinking",
68
- tool: "",
69
- count: "0",
70
- ...EMPTY_PROMPT_VALUES,
71
- text: `${symbol} thinking`,
72
- };
73
- }
74
- if (runtime.lastCompletedTool) {
75
- return {
76
- state: "completed",
77
- tool: runtime.lastCompletedTool,
78
- count: "0",
79
- ...EMPTY_PROMPT_VALUES,
80
- text: `${symbol} completed ${runtime.lastCompletedTool}`,
81
- };
82
- }
83
- return {
84
- state: "idle",
85
- tool: "",
86
- count: "0",
87
- ...EMPTY_PROMPT_VALUES,
88
- text: `${symbol} idle`,
89
- };
90
- },
52
+ const active = [...runtime.activeTools.entries()];
53
+ if (active.length > 0) {
54
+ const [tool = "tool", count = 1] = active[0] ?? [];
55
+ const suffix = count > 1 ? `×${count}` : "";
56
+ const more = active.length > 1 ? `+${active.length - 1}` : "";
57
+ return {
58
+ state: "active",
59
+ tool,
60
+ count: `${count}`,
61
+ ...EMPTY_PROMPT_VALUES,
62
+ text: `${symbol} ${tool}${suffix}${more}`,
63
+ };
64
+ }
65
+ if (runtime.isStreaming) {
66
+ return {
67
+ state: "thinking",
68
+ tool: "",
69
+ count: "0",
70
+ ...EMPTY_PROMPT_VALUES,
71
+ text: `${symbol} thinking`,
72
+ };
73
+ }
74
+ if (runtime.lastCompletedTool) {
75
+ return {
76
+ state: "completed",
77
+ tool: runtime.lastCompletedTool,
78
+ count: "0",
79
+ ...EMPTY_PROMPT_VALUES,
80
+ text: `${symbol} completed ${runtime.lastCompletedTool}`,
81
+ };
82
+ }
83
+ return {
84
+ state: "idle",
85
+ tool: "",
86
+ count: "0",
87
+ ...EMPTY_PROMPT_VALUES,
88
+ text: `${symbol} idle`,
89
+ };
90
+ },
91
91
  });