@narumitw/pi-starship 0.49.2 → 0.49.3

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