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