@narumitw/pi-starship 0.55.1 → 0.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +20 -55
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- 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 -603
- 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
package/src/format/style.ts
CHANGED
|
@@ -1,286 +1,275 @@
|
|
|
1
1
|
export type NamedColor =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
47
|
-
|
|
44
|
+
text: string;
|
|
45
|
+
style?: TextStyle;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
export interface FillChunk {
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
100
|
+
return parseStyleResult(styleString, palette).valid;
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
export function parseStyleResult(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
131
|
+
return parseStyleResult(styleString, palette).style;
|
|
137
132
|
}
|
|
138
133
|
|
|
139
134
|
function normalizeStyleToken(rawToken: string): { token: string; foreground: boolean } {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
223
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
232
224
|
}
|
|
233
225
|
|
|
234
|
-
function resolveStyle(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
237
|
+
fallback: ColorSpec | undefined,
|
|
238
|
+
source: PreviousColorSource | undefined,
|
|
239
|
+
previous: ResolvedStyle | undefined,
|
|
251
240
|
): ColorSpec | undefined {
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
285
|
-
|
|
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
|
}
|
package/src/modules/activity.ts
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
});
|