@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.
- package/README.md +2 -0
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
- package/dist/chunks/chunk-SD7TUSSU.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-MJCAK6JL.js} +18 -42
- package/dist/chunks/commands-MJCAK6JL.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/SKILL.md +18 -4
- package/skills/configuring-pi-starship/references/configuration.md +70 -2
- package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
- package/skills/configuring-pi-starship/references/modules.md +2 -0
- package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
- package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
- 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 +590 -618
- package/src/config.ts +635 -660
- package/src/effective-config.ts +49 -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 +105 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +61 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +25 -24
- package/src/modules/render.ts +131 -141
- package/src/modules/style-rules.ts +21 -0
- package/src/modules/thinking.ts +31 -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 +133 -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/pi-starship.ts
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
import { homedir, hostname, userInfo } from "node:os";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type ExtensionAPI,
|
|
4
|
+
type ExtensionContext,
|
|
5
|
+
getAgentDir,
|
|
6
|
+
type ReadonlyFooterDataProvider,
|
|
7
7
|
} from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { getCapabilities, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
9
9
|
import { completeStarshipArguments } from "./command-contract.js";
|
|
10
10
|
import type { StarshipCommandOptions } from "./commands.js";
|
|
11
|
-
import {
|
|
12
|
-
type LoadedStarshipConfig,
|
|
13
|
-
loadStarshipConfig,
|
|
14
|
-
type StarshipConfig,
|
|
15
|
-
settingsFilePath,
|
|
16
|
-
} from "./config.js";
|
|
11
|
+
import { type LoadedStarshipConfig, loadStarshipConfig, type StarshipConfig, settingsFilePath } from "./config.js";
|
|
17
12
|
import { gitSnapshotEqual, readGitSnapshot } from "./modules/git/runtime.js";
|
|
18
13
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
type GithubPrSnapshot,
|
|
15
|
+
type GitSnapshot,
|
|
16
|
+
inspectStatuslineModules,
|
|
17
|
+
reachableModuleRequirements,
|
|
18
|
+
renderStatusline,
|
|
19
|
+
type StarshipRuntimeSnapshot,
|
|
20
|
+
type StatuslineInspection,
|
|
21
|
+
type WorkspaceSnapshot,
|
|
27
22
|
} from "./modules/index.js";
|
|
28
23
|
import { execWorkspaceCommand } from "./runtime/command.js";
|
|
29
24
|
import { githubPrSnapshotEqual, queryGithubPr } from "./runtime/github-pr.js";
|
|
30
25
|
import { AsyncRefreshController } from "./runtime/refresh-controller.js";
|
|
31
26
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
collectWorkspaceSnapshot,
|
|
28
|
+
type WorkspaceExec,
|
|
29
|
+
type WorkspaceRefreshInput,
|
|
30
|
+
workspaceSnapshotEqual,
|
|
36
31
|
} from "./runtime/workspace.js";
|
|
37
32
|
import { summarizeFooterUsage } from "./usage.js";
|
|
38
33
|
|
|
@@ -45,632 +40,601 @@ type StarshipCommands = typeof import("./commands.js");
|
|
|
45
40
|
let starshipCommandsPromise: Promise<StarshipCommands> | undefined;
|
|
46
41
|
|
|
47
42
|
function loadStarshipCommands(): Promise<StarshipCommands> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
if (!starshipCommandsPromise) {
|
|
44
|
+
starshipCommandsPromise = import("./commands.js").catch((error) => {
|
|
45
|
+
starshipCommandsPromise = undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return starshipCommandsPromise;
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
interface RuntimeState {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
activeTools: Map<string, number>;
|
|
54
|
+
isStreaming: boolean;
|
|
55
|
+
uiPrompt?: NonNullable<StarshipRuntimeSnapshot["uiPrompt"]>;
|
|
56
|
+
thinkingLevel: string;
|
|
57
|
+
lastCompletedTool?: string;
|
|
58
|
+
git?: GitSnapshot;
|
|
59
|
+
githubPr?: GithubPrSnapshot;
|
|
60
|
+
workspace?: WorkspaceSnapshot;
|
|
61
|
+
requestRender?: () => void;
|
|
62
|
+
renderPreview?: (loaded: LoadedStarshipConfig, width: number) => string[];
|
|
63
|
+
inspect?: (loaded: LoadedStarshipConfig) => StatuslineInspection;
|
|
64
|
+
footerWidth?: number;
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
interface RefreshTarget {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
cwd: string;
|
|
69
|
+
generation: number;
|
|
70
|
+
sessionManager: ExtensionContext["sessionManager"];
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
interface GitRefreshInput {
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
cwd: string;
|
|
75
|
+
config: StarshipConfig;
|
|
81
76
|
}
|
|
82
77
|
|
|
83
78
|
interface PiStarshipOptions {
|
|
84
|
-
|
|
79
|
+
githubPrExec?: WorkspaceExec;
|
|
85
80
|
}
|
|
86
81
|
|
|
87
82
|
export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions = {}) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
refresh();
|
|
506
|
-
});
|
|
507
|
-
pi.on("turn_start", () => {
|
|
508
|
-
runtime.isStreaming = true;
|
|
509
|
-
refresh();
|
|
510
|
-
});
|
|
511
|
-
pi.on("turn_end", (_event, ctx) => {
|
|
512
|
-
scheduleRefresh(ctx);
|
|
513
|
-
refresh();
|
|
514
|
-
});
|
|
515
|
-
pi.on("tool_execution_start", (event) => {
|
|
516
|
-
runtime.activeTools.set(event.toolName, (runtime.activeTools.get(event.toolName) ?? 0) + 1);
|
|
517
|
-
refresh();
|
|
518
|
-
});
|
|
519
|
-
pi.on("tool_execution_end", (event, ctx) => {
|
|
520
|
-
const count = runtime.activeTools.get(event.toolName) ?? 0;
|
|
521
|
-
if (count <= 1) runtime.activeTools.delete(event.toolName);
|
|
522
|
-
else runtime.activeTools.set(event.toolName, count - 1);
|
|
523
|
-
runtime.lastCompletedTool = event.toolName;
|
|
524
|
-
scheduleRefresh(ctx);
|
|
525
|
-
refresh();
|
|
526
|
-
});
|
|
83
|
+
let loaded: LoadedStarshipConfig | undefined;
|
|
84
|
+
let loadedRevision = 0;
|
|
85
|
+
let previewLoaded: LoadedStarshipConfig | undefined;
|
|
86
|
+
const runtime: RuntimeState = {
|
|
87
|
+
activeTools: new Map(),
|
|
88
|
+
isStreaming: false,
|
|
89
|
+
thinkingLevel: "off",
|
|
90
|
+
};
|
|
91
|
+
let sessionGeneration = 0;
|
|
92
|
+
let menuController = new AbortController();
|
|
93
|
+
let sessionOwner: ExtensionContext["sessionManager"] | undefined;
|
|
94
|
+
let activeTarget: RefreshTarget | undefined;
|
|
95
|
+
let eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
96
|
+
let githubPrRefreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
97
|
+
let githubPrExpiryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
98
|
+
let githubPrGeneration = 0;
|
|
99
|
+
|
|
100
|
+
const refresh = () => runtime.requestRender?.();
|
|
101
|
+
const ownsRuntime = (ctx: ExtensionContext) => sessionOwner === ctx.sessionManager;
|
|
102
|
+
const githubPrExec = options.githubPrExec ?? execWorkspaceCommand;
|
|
103
|
+
const gitController = new AsyncRefreshController<GitRefreshInput, GitSnapshot | undefined>({
|
|
104
|
+
async read(input, signal) {
|
|
105
|
+
const requirements = reachableModuleRequirements(input.config);
|
|
106
|
+
const gitReachable =
|
|
107
|
+
[...requirements.keys()].some((name) => name.startsWith("git_")) ||
|
|
108
|
+
(requirements.has("directory") && input.config.modules.directory.options.truncate_to_repo === true);
|
|
109
|
+
if (!gitReachable) return undefined;
|
|
110
|
+
try {
|
|
111
|
+
return await readGitSnapshot(pi, input.cwd, {
|
|
112
|
+
includeMetrics: requirements.has("git_metrics"),
|
|
113
|
+
includeTag: requirements.get("git_commit")?.has("tag") ?? false,
|
|
114
|
+
signal,
|
|
115
|
+
});
|
|
116
|
+
} catch {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
equal: gitSnapshotEqual,
|
|
121
|
+
publish(snapshot) {
|
|
122
|
+
runtime.git = snapshot;
|
|
123
|
+
refresh();
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const githubPrController = new AsyncRefreshController<Pick<RefreshTarget, "cwd">, GithubPrSnapshot | undefined>({
|
|
127
|
+
read: (input, signal) => queryGithubPr(githubPrExec, input.cwd, signal),
|
|
128
|
+
equal: githubPrSnapshotEqual,
|
|
129
|
+
publish(snapshot) {
|
|
130
|
+
runtime.githubPr = snapshot;
|
|
131
|
+
scheduleGithubPrExpiry(snapshot);
|
|
132
|
+
refresh();
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
const workspaceController = new AsyncRefreshController<WorkspaceRefreshInput, WorkspaceSnapshot>({
|
|
136
|
+
async read(input, signal) {
|
|
137
|
+
try {
|
|
138
|
+
return await collectWorkspaceSnapshot({ ...input, signal });
|
|
139
|
+
} catch {
|
|
140
|
+
return { modules: {} };
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
equal: workspaceSnapshotEqual,
|
|
144
|
+
publish(snapshot) {
|
|
145
|
+
runtime.workspace = snapshot;
|
|
146
|
+
refresh();
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const clearDebounce = () => {
|
|
151
|
+
if (!eventDebounceTimer) return;
|
|
152
|
+
clearTimeout(eventDebounceTimer);
|
|
153
|
+
eventDebounceTimer = undefined;
|
|
154
|
+
};
|
|
155
|
+
const isActiveTarget = (target: RefreshTarget) =>
|
|
156
|
+
activeTarget?.cwd === target.cwd &&
|
|
157
|
+
activeTarget.generation === target.generation &&
|
|
158
|
+
activeTarget.sessionManager === target.sessionManager &&
|
|
159
|
+
target.generation === sessionGeneration;
|
|
160
|
+
|
|
161
|
+
const requestRefresh = (target: RefreshTarget, reason: WorkspaceRefreshInput["reason"] = "event") => {
|
|
162
|
+
if (!loaded || !isActiveTarget(target)) return;
|
|
163
|
+
gitController.request({ cwd: target.cwd, config: loaded.config });
|
|
164
|
+
workspaceController.request(workspaceInput(target.cwd, loaded.config, reason, runtime.workspace));
|
|
165
|
+
};
|
|
166
|
+
const scheduleRefresh = (ctx: ExtensionContext) => {
|
|
167
|
+
const target = activeTarget;
|
|
168
|
+
if (!target || target.cwd !== ctx.cwd || target.sessionManager !== ctx.sessionManager) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
clearDebounce();
|
|
172
|
+
eventDebounceTimer = setTimeout(() => {
|
|
173
|
+
eventDebounceTimer = undefined;
|
|
174
|
+
requestRefresh(target);
|
|
175
|
+
}, EVENT_DEBOUNCE_MS);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function restartLocalControllers(target: RefreshTarget) {
|
|
179
|
+
if (!isActiveTarget(target)) return;
|
|
180
|
+
gitController.start(target.generation);
|
|
181
|
+
workspaceController.start(target.generation);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function clearGithubPrTimers() {
|
|
185
|
+
if (githubPrRefreshTimer) clearInterval(githubPrRefreshTimer);
|
|
186
|
+
if (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);
|
|
187
|
+
githubPrRefreshTimer = undefined;
|
|
188
|
+
githubPrExpiryTimer = undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function stopGithubPr() {
|
|
192
|
+
clearGithubPrTimers();
|
|
193
|
+
githubPrController.stop();
|
|
194
|
+
runtime.githubPr = undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function githubPrReachable(): boolean {
|
|
198
|
+
return Boolean(loaded && reachableModuleRequirements(loaded.config).has("github_pr"));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function startGithubPr(target: RefreshTarget): boolean {
|
|
202
|
+
if (!isActiveTarget(target)) return false;
|
|
203
|
+
stopGithubPr();
|
|
204
|
+
if (!githubPrReachable()) return false;
|
|
205
|
+
githubPrController.start(++githubPrGeneration);
|
|
206
|
+
githubPrRefreshTimer = setInterval(() => {
|
|
207
|
+
requestGithubPr(target);
|
|
208
|
+
}, GITHUB_PR_REFRESH_INTERVAL_MS);
|
|
209
|
+
githubPrRefreshTimer.unref?.();
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function requestGithubPr(target: RefreshTarget) {
|
|
214
|
+
if (!isActiveTarget(target) || !githubPrReachable()) return;
|
|
215
|
+
githubPrController.request({ cwd: target.cwd });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function scheduleGithubPrExpiry(snapshot: GithubPrSnapshot | undefined) {
|
|
219
|
+
if (githubPrExpiryTimer) clearTimeout(githubPrExpiryTimer);
|
|
220
|
+
githubPrExpiryTimer = undefined;
|
|
221
|
+
if (snapshot?.expiresAt === undefined) return;
|
|
222
|
+
const target = activeTarget;
|
|
223
|
+
if (!target) return;
|
|
224
|
+
const delay = snapshot.expiresAt - Date.now();
|
|
225
|
+
if (delay <= 0) {
|
|
226
|
+
runtime.githubPr = undefined;
|
|
227
|
+
githubPrController.clear();
|
|
228
|
+
refresh();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
githubPrExpiryTimer = setTimeout(
|
|
232
|
+
() => {
|
|
233
|
+
githubPrExpiryTimer = undefined;
|
|
234
|
+
if (!isActiveTarget(target) || runtime.githubPr !== snapshot) return;
|
|
235
|
+
scheduleGithubPrExpiry(snapshot);
|
|
236
|
+
},
|
|
237
|
+
Math.min(delay, MAX_TIMER_DELAY_MS),
|
|
238
|
+
);
|
|
239
|
+
githubPrExpiryTimer.unref?.();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const installFooter = (ctx: ExtensionContext) => {
|
|
243
|
+
const generation = ++sessionGeneration;
|
|
244
|
+
sessionOwner = ctx.sessionManager;
|
|
245
|
+
previewLoaded = undefined;
|
|
246
|
+
menuController.abort(new DOMException("Starship session context replaced", "AbortError"));
|
|
247
|
+
menuController = new AbortController();
|
|
248
|
+
const target: RefreshTarget = { cwd: ctx.cwd, generation, sessionManager: ctx.sessionManager };
|
|
249
|
+
clearDebounce();
|
|
250
|
+
gitController.stop();
|
|
251
|
+
workspaceController.stop();
|
|
252
|
+
stopGithubPr();
|
|
253
|
+
runtime.git = undefined;
|
|
254
|
+
runtime.workspace = undefined;
|
|
255
|
+
runtime.requestRender = undefined;
|
|
256
|
+
runtime.renderPreview = undefined;
|
|
257
|
+
runtime.inspect = undefined;
|
|
258
|
+
runtime.footerWidth = undefined;
|
|
259
|
+
activeTarget = ctx.mode === "tui" ? target : undefined;
|
|
260
|
+
ctx.ui.setStatus("starship", undefined);
|
|
261
|
+
if (!activeTarget || !loaded) return;
|
|
262
|
+
gitController.start(generation);
|
|
263
|
+
workspaceController.start(generation);
|
|
264
|
+
startGithubPr(target);
|
|
265
|
+
|
|
266
|
+
ctx.ui.setFooter((tui, _theme, footerData) => {
|
|
267
|
+
runtime.requestRender = () => tui.requestRender();
|
|
268
|
+
runtime.renderPreview = (preview, width) => {
|
|
269
|
+
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
270
|
+
return wrapFormattedStatusline(
|
|
271
|
+
renderStatusline(preview.config, snapshot, width, getCapabilities().trueColor).ansi,
|
|
272
|
+
width,
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
runtime.inspect = (current) =>
|
|
276
|
+
inspectStatuslineModules(current.config, runtimeSnapshot(ctx, footerData, runtime), runtime.footerWidth ?? 80);
|
|
277
|
+
const unsubscribe = footerData.onBranchChange(() => {
|
|
278
|
+
if (!isActiveTarget(target)) return;
|
|
279
|
+
runtime.git = undefined;
|
|
280
|
+
restartLocalControllers(target);
|
|
281
|
+
clearDebounce();
|
|
282
|
+
startGithubPr(target);
|
|
283
|
+
requestRefresh(target);
|
|
284
|
+
requestGithubPr(target);
|
|
285
|
+
tui.requestRender();
|
|
286
|
+
});
|
|
287
|
+
let lastRender:
|
|
288
|
+
| {
|
|
289
|
+
snapshot: StarshipRuntimeSnapshot;
|
|
290
|
+
lines: string[];
|
|
291
|
+
config: StarshipConfig;
|
|
292
|
+
width: number;
|
|
293
|
+
}
|
|
294
|
+
| undefined;
|
|
295
|
+
const timer = setInterval(() => {
|
|
296
|
+
if (!isActiveTarget(target)) return;
|
|
297
|
+
clearDebounce();
|
|
298
|
+
requestRefresh(target, "periodic");
|
|
299
|
+
// Collectors publish only changed snapshots. The clock is the sole value
|
|
300
|
+
// that changes without publication; reuse the last render's session data.
|
|
301
|
+
if (!lastRender || !reachableModuleRequirements(lastRender.config).get("time")?.has("time")) return;
|
|
302
|
+
const now = new Date();
|
|
303
|
+
const previous = lastRender.snapshot.now;
|
|
304
|
+
if (now.getHours() === previous.getHours() && now.getMinutes() === previous.getMinutes()) return;
|
|
305
|
+
const lines = wrapFormattedStatusline(
|
|
306
|
+
renderStatusline(
|
|
307
|
+
lastRender.config,
|
|
308
|
+
{ ...lastRender.snapshot, now },
|
|
309
|
+
lastRender.width,
|
|
310
|
+
getCapabilities().trueColor,
|
|
311
|
+
).ansi,
|
|
312
|
+
lastRender.width,
|
|
313
|
+
);
|
|
314
|
+
const previousLines = lastRender.lines;
|
|
315
|
+
if (lines.length !== previousLines.length || lines.some((line, index) => line !== previousLines[index]))
|
|
316
|
+
tui.requestRender();
|
|
317
|
+
}, REFRESH_INTERVAL_MS);
|
|
318
|
+
let disposed = false;
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
dispose() {
|
|
322
|
+
if (disposed) return;
|
|
323
|
+
disposed = true;
|
|
324
|
+
unsubscribe();
|
|
325
|
+
clearInterval(timer);
|
|
326
|
+
if (isActiveTarget(target)) {
|
|
327
|
+
activeTarget = undefined;
|
|
328
|
+
clearDebounce();
|
|
329
|
+
gitController.stop();
|
|
330
|
+
workspaceController.stop();
|
|
331
|
+
stopGithubPr();
|
|
332
|
+
runtime.git = undefined;
|
|
333
|
+
runtime.workspace = undefined;
|
|
334
|
+
runtime.requestRender = undefined;
|
|
335
|
+
runtime.renderPreview = undefined;
|
|
336
|
+
runtime.inspect = undefined;
|
|
337
|
+
runtime.footerWidth = undefined;
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
invalidate() {},
|
|
341
|
+
render(width: number): string[] {
|
|
342
|
+
runtime.footerWidth = width;
|
|
343
|
+
const current = previewLoaded ?? loaded;
|
|
344
|
+
if (!current) return [];
|
|
345
|
+
const snapshot = runtimeSnapshot(ctx, footerData, runtime);
|
|
346
|
+
const lines = wrapFormattedStatusline(
|
|
347
|
+
renderStatusline(current.config, snapshot, width, getCapabilities().trueColor).ansi,
|
|
348
|
+
width,
|
|
349
|
+
);
|
|
350
|
+
lastRender = { snapshot, lines, config: current.config, width };
|
|
351
|
+
return lines;
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
requestRefresh(target, "initial");
|
|
356
|
+
requestGithubPr(target);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const configPath = settingsFilePath(getAgentDir());
|
|
360
|
+
const commandOptions: StarshipCommandOptions = {
|
|
361
|
+
settingsPath: configPath,
|
|
362
|
+
getLoaded: () => loaded ?? loadStarshipConfig(configPath),
|
|
363
|
+
getLoadedRevision: () => loadedRevision,
|
|
364
|
+
getInspection: () => {
|
|
365
|
+
const current = loaded ?? loadStarshipConfig(configPath);
|
|
366
|
+
return runtime.inspect?.(current);
|
|
367
|
+
},
|
|
368
|
+
getMenuOwner: () => {
|
|
369
|
+
const generation = sessionGeneration;
|
|
370
|
+
return {
|
|
371
|
+
signal: menuController.signal,
|
|
372
|
+
isCurrent: () => generation === sessionGeneration && !menuController.signal.aborted,
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
apply(next, ctx) {
|
|
376
|
+
if (sessionOwner !== ctx.sessionManager) {
|
|
377
|
+
throw new Error("Starship session context was replaced");
|
|
378
|
+
}
|
|
379
|
+
previewLoaded = undefined;
|
|
380
|
+
loaded = next;
|
|
381
|
+
loadedRevision += 1;
|
|
382
|
+
const target = activeTarget;
|
|
383
|
+
if (target) {
|
|
384
|
+
restartLocalControllers(target);
|
|
385
|
+
startGithubPr(target);
|
|
386
|
+
requestRefresh(target);
|
|
387
|
+
requestGithubPr(target);
|
|
388
|
+
}
|
|
389
|
+
refresh();
|
|
390
|
+
},
|
|
391
|
+
preview(next, ctx) {
|
|
392
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
393
|
+
previewLoaded = next;
|
|
394
|
+
refresh();
|
|
395
|
+
},
|
|
396
|
+
renderPreview(preview, width) {
|
|
397
|
+
return runtime.renderPreview?.(preview, width) ?? ["Live preview is unavailable until the footer is ready."];
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
pi.registerCommand("starship", {
|
|
401
|
+
description: "Customize or inspect the native Starship-style footer",
|
|
402
|
+
getArgumentCompletions: completeStarshipArguments,
|
|
403
|
+
handler: async (args, ctx) => {
|
|
404
|
+
const commands = await loadStarshipCommands();
|
|
405
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
406
|
+
await commands.handleStarshipCommand(args, ctx, commandOptions);
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
pi.on("session_start", (_event, ctx) => {
|
|
411
|
+
runtime.activeTools.clear();
|
|
412
|
+
runtime.isStreaming = false;
|
|
413
|
+
runtime.uiPrompt = undefined;
|
|
414
|
+
runtime.lastCompletedTool = undefined;
|
|
415
|
+
loaded = loadStarshipConfig(configPath);
|
|
416
|
+
loadedRevision += 1;
|
|
417
|
+
if (loaded.diagnostics.length > 0 && (ctx.mode === "tui" || ctx.hasUI)) {
|
|
418
|
+
ctx.ui.notify(formatDiagnostics(loaded), "warning");
|
|
419
|
+
}
|
|
420
|
+
runtime.thinkingLevel = pi.getThinkingLevel();
|
|
421
|
+
installFooter(ctx);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
pi.on("session_tree", (_event, ctx) => {
|
|
425
|
+
installFooter(ctx);
|
|
426
|
+
refresh();
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
430
|
+
if (sessionOwner !== ctx.sessionManager) return;
|
|
431
|
+
sessionOwner = undefined;
|
|
432
|
+
previewLoaded = undefined;
|
|
433
|
+
sessionGeneration += 1;
|
|
434
|
+
menuController.abort(new DOMException("Starship session shut down", "AbortError"));
|
|
435
|
+
activeTarget = undefined;
|
|
436
|
+
clearDebounce();
|
|
437
|
+
gitController.stop();
|
|
438
|
+
workspaceController.stop();
|
|
439
|
+
stopGithubPr();
|
|
440
|
+
runtime.git = undefined;
|
|
441
|
+
runtime.workspace = undefined;
|
|
442
|
+
runtime.activeTools.clear();
|
|
443
|
+
runtime.isStreaming = false;
|
|
444
|
+
runtime.uiPrompt = undefined;
|
|
445
|
+
runtime.lastCompletedTool = undefined;
|
|
446
|
+
runtime.requestRender = undefined;
|
|
447
|
+
runtime.renderPreview = undefined;
|
|
448
|
+
runtime.inspect = undefined;
|
|
449
|
+
runtime.footerWidth = undefined;
|
|
450
|
+
ctx.ui.setFooter(undefined);
|
|
451
|
+
ctx.ui.setStatus("starship", undefined);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
pi.on("model_select", () => refresh());
|
|
455
|
+
pi.on("thinking_level_select", (event) => {
|
|
456
|
+
runtime.thinkingLevel = event.level;
|
|
457
|
+
refresh();
|
|
458
|
+
});
|
|
459
|
+
pi.on("agent_start", () => {
|
|
460
|
+
runtime.isStreaming = true;
|
|
461
|
+
refresh();
|
|
462
|
+
});
|
|
463
|
+
pi.on("agent_end", (_event, ctx) => {
|
|
464
|
+
runtime.isStreaming = false;
|
|
465
|
+
scheduleRefresh(ctx);
|
|
466
|
+
const target = activeTarget;
|
|
467
|
+
if (target?.sessionManager === ctx.sessionManager) requestGithubPr(target);
|
|
468
|
+
refresh();
|
|
469
|
+
});
|
|
470
|
+
pi.on("ui_prompt_start", (event, ctx) => {
|
|
471
|
+
if (!ownsRuntime(ctx)) return;
|
|
472
|
+
runtime.uiPrompt = { kind: event.kind, title: event.title };
|
|
473
|
+
refresh();
|
|
474
|
+
});
|
|
475
|
+
pi.on("ui_prompt_end", (_event, ctx) => {
|
|
476
|
+
if (!ownsRuntime(ctx)) return;
|
|
477
|
+
runtime.uiPrompt = undefined;
|
|
478
|
+
refresh();
|
|
479
|
+
});
|
|
480
|
+
pi.on("turn_start", () => {
|
|
481
|
+
runtime.isStreaming = true;
|
|
482
|
+
refresh();
|
|
483
|
+
});
|
|
484
|
+
pi.on("turn_end", (_event, ctx) => {
|
|
485
|
+
scheduleRefresh(ctx);
|
|
486
|
+
refresh();
|
|
487
|
+
});
|
|
488
|
+
pi.on("tool_execution_start", (event) => {
|
|
489
|
+
runtime.activeTools.set(event.toolName, (runtime.activeTools.get(event.toolName) ?? 0) + 1);
|
|
490
|
+
refresh();
|
|
491
|
+
});
|
|
492
|
+
pi.on("tool_execution_end", (event, ctx) => {
|
|
493
|
+
const count = runtime.activeTools.get(event.toolName) ?? 0;
|
|
494
|
+
if (count <= 1) runtime.activeTools.delete(event.toolName);
|
|
495
|
+
else runtime.activeTools.set(event.toolName, count - 1);
|
|
496
|
+
runtime.lastCompletedTool = event.toolName;
|
|
497
|
+
scheduleRefresh(ctx);
|
|
498
|
+
refresh();
|
|
499
|
+
});
|
|
527
500
|
}
|
|
528
501
|
|
|
529
502
|
function workspaceInput(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
503
|
+
cwd: string,
|
|
504
|
+
config: StarshipConfig,
|
|
505
|
+
reason: WorkspaceRefreshInput["reason"],
|
|
506
|
+
previous: WorkspaceSnapshot | undefined,
|
|
534
507
|
): WorkspaceRefreshInput {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
508
|
+
return {
|
|
509
|
+
cwd,
|
|
510
|
+
config,
|
|
511
|
+
environment: allowlistedEnvironment(config),
|
|
512
|
+
homeDir: homedir(),
|
|
513
|
+
platform: process.platform,
|
|
514
|
+
hostname: hostname(),
|
|
515
|
+
username: safeUsername(),
|
|
516
|
+
exec: execWorkspaceCommand,
|
|
517
|
+
reason,
|
|
518
|
+
previous,
|
|
519
|
+
};
|
|
547
520
|
}
|
|
548
521
|
|
|
549
522
|
const ENVIRONMENT_ALLOWLIST = [
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
523
|
+
"AWS_CONFIG_FILE",
|
|
524
|
+
"AWS_DEFAULT_PROFILE",
|
|
525
|
+
"AWS_DEFAULT_REGION",
|
|
526
|
+
"AWS_PROFILE",
|
|
527
|
+
"AWS_REGION",
|
|
528
|
+
"AZURE_CONFIG_DIR",
|
|
529
|
+
"CLOUDSDK_ACTIVE_CONFIG_NAME",
|
|
530
|
+
"CLOUDSDK_CONFIG",
|
|
531
|
+
"CODESPACES",
|
|
532
|
+
"CONDA_DEFAULT_ENV",
|
|
533
|
+
"DOCKER_CONFIG",
|
|
534
|
+
"DOCKER_CONTEXT",
|
|
535
|
+
"GUIX_ENVIRONMENT",
|
|
536
|
+
"IN_NIX_SHELL",
|
|
537
|
+
"KUBECONFIG",
|
|
538
|
+
"LOGNAME",
|
|
539
|
+
"NIX_SHELL_LEVEL",
|
|
540
|
+
"NIX_SHELL_NAME",
|
|
541
|
+
"OS_CLIENT_CONFIG_FILE",
|
|
542
|
+
"OS_CLOUD",
|
|
543
|
+
"OS_PROJECT_NAME",
|
|
544
|
+
"PATH",
|
|
545
|
+
"PIXI_ENVIRONMENT_NAME",
|
|
546
|
+
"PIXI_PROJECT_NAME",
|
|
547
|
+
"PYENV_VERSION",
|
|
548
|
+
"REMOTE_CONTAINERS",
|
|
549
|
+
"RUSTC",
|
|
550
|
+
"RUSTUP_TOOLCHAIN",
|
|
551
|
+
"SSH_CONNECTION",
|
|
552
|
+
"SSH_TTY",
|
|
553
|
+
"TF_DATA_DIR",
|
|
554
|
+
"TF_WORKSPACE",
|
|
555
|
+
"USER",
|
|
556
|
+
"USERNAME",
|
|
557
|
+
"VIRTUAL_ENV",
|
|
558
|
+
"WSL_DISTRO_NAME",
|
|
586
559
|
] as const;
|
|
587
560
|
|
|
588
561
|
function allowlistedEnvironment(config: StarshipConfig): Record<string, string | undefined> {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
for (const name of names) result[name] = process.env[name];
|
|
598
|
-
return result;
|
|
562
|
+
const result: Record<string, string | undefined> = {};
|
|
563
|
+
const configured = config.modules.username.options.detect_env_vars;
|
|
564
|
+
const names = new Set([
|
|
565
|
+
...ENVIRONMENT_ALLOWLIST,
|
|
566
|
+
...(Array.isArray(configured) ? configured.filter((name): name is string => typeof name === "string") : []),
|
|
567
|
+
]);
|
|
568
|
+
for (const name of names) result[name] = process.env[name];
|
|
569
|
+
return result;
|
|
599
570
|
}
|
|
600
571
|
|
|
601
572
|
function safeUsername(): string {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
573
|
+
try {
|
|
574
|
+
return userInfo().username;
|
|
575
|
+
} catch {
|
|
576
|
+
return process.env.USER ?? process.env.USERNAME ?? "";
|
|
577
|
+
}
|
|
607
578
|
}
|
|
608
579
|
|
|
609
580
|
function runtimeSnapshot(
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
581
|
+
ctx: ExtensionContext,
|
|
582
|
+
footerData: ReadonlyFooterDataProvider,
|
|
583
|
+
runtime: RuntimeState,
|
|
613
584
|
): StarshipRuntimeSnapshot {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
585
|
+
return {
|
|
586
|
+
cwd: ctx.cwd,
|
|
587
|
+
homeDir: homedir(),
|
|
588
|
+
gitRoot: runtime.git?.root,
|
|
589
|
+
model: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,
|
|
590
|
+
thinkingLevel: runtime.thinkingLevel,
|
|
591
|
+
turnCount: userTurnCount(ctx),
|
|
592
|
+
activeTools: runtime.activeTools,
|
|
593
|
+
isStreaming: runtime.isStreaming,
|
|
594
|
+
uiPrompt: runtime.uiPrompt,
|
|
595
|
+
lastCompletedTool: runtime.lastCompletedTool,
|
|
596
|
+
contextUsage: ctx.getContextUsage() ?? undefined,
|
|
597
|
+
tokenTotals: summarizeFooterUsage(ctx.sessionManager.getEntries()),
|
|
598
|
+
usingSubscription: isSubscriptionBacked(ctx),
|
|
599
|
+
gitBranch: runtime.git?.branch?.name ?? footerData.getGitBranch(),
|
|
600
|
+
gitBranchDetails: runtime.git?.branch,
|
|
601
|
+
gitCommit: runtime.git?.commit,
|
|
602
|
+
gitState: runtime.git?.state,
|
|
603
|
+
gitMetrics: runtime.git?.metrics,
|
|
604
|
+
gitStatus: runtime.git?.status,
|
|
605
|
+
gitWorktree: runtime.git?.worktree,
|
|
606
|
+
githubPr: runtime.githubPr,
|
|
607
|
+
workspace: runtime.workspace,
|
|
608
|
+
extensionStatuses: footerData.getExtensionStatuses(),
|
|
609
|
+
now: new Date(),
|
|
610
|
+
};
|
|
640
611
|
}
|
|
641
612
|
|
|
642
613
|
function userTurnCount(ctx: ExtensionContext): number {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
.filter((entry) => entry.type === "message" && entry.message.role === "user").length;
|
|
614
|
+
return ctx.sessionManager.getBranch().filter((entry) => entry.type === "message" && entry.message.role === "user")
|
|
615
|
+
.length;
|
|
646
616
|
}
|
|
647
617
|
|
|
648
618
|
function isSubscriptionBacked(ctx: ExtensionContext): boolean {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
model !== undefined &&
|
|
652
|
-
(model.provider === "kimi-coding" || ctx.modelRegistry.isUsingOAuth(model))
|
|
653
|
-
);
|
|
619
|
+
const model = ctx.model;
|
|
620
|
+
return model !== undefined && (model.provider === "kimi-coding" || ctx.modelRegistry.isUsingOAuth(model));
|
|
654
621
|
}
|
|
655
622
|
|
|
656
623
|
function formatDiagnostics(loaded: LoadedStarshipConfig): string {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
`pi-starship settings: ${details.join("; ")}`,
|
|
661
|
-
...(remaining > 0 ? [`+${remaining} more`] : []),
|
|
662
|
-
].join(" ");
|
|
624
|
+
const details = loaded.diagnostics.slice(0, 5).map((item) => item.message);
|
|
625
|
+
const remaining = loaded.diagnostics.length - details.length;
|
|
626
|
+
return [`pi-starship settings: ${details.join("; ")}`, ...(remaining > 0 ? [`+${remaining} more`] : [])].join(" ");
|
|
663
627
|
}
|
|
664
628
|
|
|
665
629
|
export function wrapFormattedStatusline(format: string, width: number): string[] {
|
|
666
|
-
|
|
667
|
-
|
|
630
|
+
if (width <= 0) return [];
|
|
631
|
+
return wrapTextWithAnsi(format, width);
|
|
668
632
|
}
|
|
669
633
|
|
|
670
634
|
export {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
635
|
+
parseGitDiffShortstat,
|
|
636
|
+
parseGitState,
|
|
637
|
+
parseGitStatusPorcelain,
|
|
638
|
+
parseGitStatusPorcelainV2,
|
|
639
|
+
parseGitWorktree,
|
|
676
640
|
} from "./modules/git/runtime.js";
|