@narumitw/pi-starship 0.55.1 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +2 -0
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
  3. package/dist/chunks/chunk-SD7TUSSU.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-MJCAK6JL.js} +18 -42
  11. package/dist/chunks/commands-MJCAK6JL.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +20 -55
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/SKILL.md +18 -4
  26. package/skills/configuring-pi-starship/references/configuration.md +70 -2
  27. package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
  28. package/skills/configuring-pi-starship/references/modules.md +2 -0
  29. package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
  30. package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
  31. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  32. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  33. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  34. package/src/command-configuration.ts +267 -286
  35. package/src/command-contract.ts +6 -6
  36. package/src/command-inspector.ts +27 -27
  37. package/src/command-preset-picker.ts +45 -50
  38. package/src/command-preview.ts +153 -166
  39. package/src/commands.ts +590 -618
  40. package/src/config.ts +635 -660
  41. package/src/effective-config.ts +49 -48
  42. package/src/format/formatter.ts +211 -227
  43. package/src/format/style.ts +205 -216
  44. package/src/modules/activity.ts +74 -74
  45. package/src/modules/brand.ts +9 -9
  46. package/src/modules/cache.ts +18 -18
  47. package/src/modules/catalog.ts +79 -83
  48. package/src/modules/cloud.ts +54 -54
  49. package/src/modules/context.ts +27 -27
  50. package/src/modules/cost.ts +23 -23
  51. package/src/modules/deployment.ts +45 -45
  52. package/src/modules/development.ts +80 -81
  53. package/src/modules/directory.ts +89 -113
  54. package/src/modules/display.ts +9 -9
  55. package/src/modules/execution.ts +62 -69
  56. package/src/modules/extension-status.ts +59 -64
  57. package/src/modules/fill.ts +10 -10
  58. package/src/modules/git/branch.ts +26 -26
  59. package/src/modules/git/commit.ts +21 -23
  60. package/src/modules/git/metrics.ts +22 -22
  61. package/src/modules/git/runtime.ts +299 -334
  62. package/src/modules/git/state.ts +17 -17
  63. package/src/modules/git/status.ts +77 -79
  64. package/src/modules/git/worktree.ts +10 -12
  65. package/src/modules/github-pr.ts +20 -20
  66. package/src/modules/helpers.ts +3 -3
  67. package/src/modules/index.ts +21 -21
  68. package/src/modules/inspection.ts +105 -108
  69. package/src/modules/languages.ts +52 -59
  70. package/src/modules/model.ts +61 -67
  71. package/src/modules/package.ts +12 -12
  72. package/src/modules/provider.ts +25 -24
  73. package/src/modules/render.ts +131 -141
  74. package/src/modules/style-rules.ts +21 -0
  75. package/src/modules/thinking.ts +31 -26
  76. package/src/modules/time.ts +10 -13
  77. package/src/modules/tokens.ts +13 -13
  78. package/src/modules/truncation.ts +14 -17
  79. package/src/modules/turn.ts +9 -9
  80. package/src/modules/types.ts +133 -132
  81. package/src/modules/workspace-helpers.ts +4 -7
  82. package/src/pi-starship.ts +567 -603
  83. package/src/presets/catalog.ts +113 -113
  84. package/src/runtime/cloud.ts +122 -150
  85. package/src/runtime/command.ts +106 -108
  86. package/src/runtime/deployment.ts +150 -179
  87. package/src/runtime/development.ts +107 -124
  88. package/src/runtime/execution.ts +110 -124
  89. package/src/runtime/github-pr.ts +223 -252
  90. package/src/runtime/helpers.ts +186 -199
  91. package/src/runtime/languages.ts +149 -180
  92. package/src/runtime/package.ts +74 -87
  93. package/src/runtime/refresh-controller.ts +82 -86
  94. package/src/runtime/types.ts +38 -38
  95. package/src/runtime/workspace.ts +108 -116
  96. package/src/usage.ts +40 -40
  97. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  98. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  99. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  100. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  101. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  102. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  103. package/dist/chunks/development-BERD42HW.js.map +0 -7
  104. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  105. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  106. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -1,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,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
- 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
- let lastRender:
306
- | {
307
- snapshot: StarshipRuntimeSnapshot;
308
- lines: string[];
309
- config: StarshipConfig;
310
- width: number;
311
- }
312
- | undefined;
313
- const timer = setInterval(() => {
314
- if (!isActiveTarget(target)) return;
315
- clearDebounce();
316
- requestRefresh(target, "periodic");
317
- // Collectors publish only changed snapshots. The clock is the sole value
318
- // that changes without publication; reuse the last render's session data.
319
- if (!lastRender || !reachableModuleRequirements(lastRender.config).get("time")?.has("time"))
320
- return;
321
- const now = new Date();
322
- const previous = lastRender.snapshot.now;
323
- if (now.getHours() === previous.getHours() && now.getMinutes() === previous.getMinutes())
324
- return;
325
- const lines = wrapFormattedStatusline(
326
- renderStatusline(
327
- lastRender.config,
328
- { ...lastRender.snapshot, now },
329
- lastRender.width,
330
- getCapabilities().trueColor,
331
- ).ansi,
332
- lastRender.width,
333
- );
334
- const previousLines = lastRender.lines;
335
- if (
336
- lines.length !== previousLines.length ||
337
- lines.some((line, index) => line !== previousLines[index])
338
- )
339
- tui.requestRender();
340
- }, REFRESH_INTERVAL_MS);
341
- let disposed = false;
342
-
343
- return {
344
- dispose() {
345
- if (disposed) return;
346
- disposed = true;
347
- unsubscribe();
348
- clearInterval(timer);
349
- if (isActiveTarget(target)) {
350
- activeTarget = undefined;
351
- clearDebounce();
352
- gitController.stop();
353
- workspaceController.stop();
354
- stopGithubPr();
355
- runtime.git = undefined;
356
- runtime.workspace = undefined;
357
- runtime.requestRender = undefined;
358
- runtime.renderPreview = undefined;
359
- runtime.inspect = undefined;
360
- runtime.footerWidth = undefined;
361
- }
362
- },
363
- invalidate() {},
364
- render(width: number): string[] {
365
- runtime.footerWidth = width;
366
- const current = previewLoaded ?? loaded;
367
- if (!current) return [];
368
- const snapshot = runtimeSnapshot(ctx, footerData, runtime);
369
- const lines = wrapFormattedStatusline(
370
- renderStatusline(current.config, snapshot, width, getCapabilities().trueColor).ansi,
371
- width,
372
- );
373
- lastRender = { snapshot, lines, config: current.config, width };
374
- return lines;
375
- },
376
- };
377
- });
378
- requestRefresh(target, "initial");
379
- requestGithubPr(target);
380
- };
381
-
382
- const configPath = settingsFilePath(getAgentDir());
383
- const commandOptions: StarshipCommandOptions = {
384
- settingsPath: configPath,
385
- getLoaded: () => loaded ?? loadStarshipConfig(configPath),
386
- getLoadedRevision: () => loadedRevision,
387
- getInspection: () => {
388
- const current = loaded ?? loadStarshipConfig(configPath);
389
- return runtime.inspect?.(current);
390
- },
391
- getMenuOwner: () => {
392
- const generation = sessionGeneration;
393
- return {
394
- signal: menuController.signal,
395
- isCurrent: () => generation === sessionGeneration && !menuController.signal.aborted,
396
- };
397
- },
398
- apply(next, ctx) {
399
- if (sessionOwner !== ctx.sessionManager) {
400
- throw new Error("Starship session context was replaced");
401
- }
402
- previewLoaded = undefined;
403
- loaded = next;
404
- loadedRevision += 1;
405
- const target = activeTarget;
406
- if (target) {
407
- restartLocalControllers(target);
408
- startGithubPr(target);
409
- requestRefresh(target);
410
- requestGithubPr(target);
411
- }
412
- refresh();
413
- },
414
- preview(next, ctx) {
415
- if (sessionOwner !== ctx.sessionManager) return;
416
- previewLoaded = next;
417
- refresh();
418
- },
419
- renderPreview(preview, width) {
420
- return (
421
- runtime.renderPreview?.(preview, width) ?? [
422
- "Live preview is unavailable until the footer is ready.",
423
- ]
424
- );
425
- },
426
- };
427
- pi.registerCommand("starship", {
428
- description: "Customize or inspect the native Starship-style footer",
429
- getArgumentCompletions: completeStarshipArguments,
430
- handler: async (args, ctx) => {
431
- const commands = await loadStarshipCommands();
432
- if (sessionOwner !== ctx.sessionManager) return;
433
- await commands.handleStarshipCommand(args, ctx, commandOptions);
434
- },
435
- });
436
-
437
- pi.on("session_start", (_event, ctx) => {
438
- runtime.activeTools.clear();
439
- runtime.isStreaming = false;
440
- runtime.uiPrompt = undefined;
441
- runtime.lastCompletedTool = undefined;
442
- loaded = loadStarshipConfig(configPath);
443
- loadedRevision += 1;
444
- if (loaded.diagnostics.length > 0 && (ctx.mode === "tui" || ctx.hasUI)) {
445
- ctx.ui.notify(formatDiagnostics(loaded), "warning");
446
- }
447
- runtime.thinkingLevel = pi.getThinkingLevel();
448
- installFooter(ctx);
449
- });
450
-
451
- pi.on("session_tree", (_event, ctx) => {
452
- installFooter(ctx);
453
- refresh();
454
- });
455
-
456
- pi.on("session_shutdown", (_event, ctx) => {
457
- if (sessionOwner !== ctx.sessionManager) return;
458
- sessionOwner = undefined;
459
- previewLoaded = undefined;
460
- sessionGeneration += 1;
461
- menuController.abort(new DOMException("Starship session shut down", "AbortError"));
462
- activeTarget = undefined;
463
- clearDebounce();
464
- gitController.stop();
465
- workspaceController.stop();
466
- stopGithubPr();
467
- runtime.git = undefined;
468
- runtime.workspace = undefined;
469
- runtime.activeTools.clear();
470
- runtime.isStreaming = false;
471
- runtime.uiPrompt = undefined;
472
- runtime.lastCompletedTool = undefined;
473
- runtime.requestRender = undefined;
474
- runtime.renderPreview = undefined;
475
- runtime.inspect = undefined;
476
- runtime.footerWidth = undefined;
477
- ctx.ui.setFooter(undefined);
478
- ctx.ui.setStatus("starship", undefined);
479
- });
480
-
481
- pi.on("model_select", () => refresh());
482
- pi.on("thinking_level_select", (event) => {
483
- runtime.thinkingLevel = event.level;
484
- refresh();
485
- });
486
- pi.on("agent_start", () => {
487
- runtime.isStreaming = true;
488
- refresh();
489
- });
490
- pi.on("agent_end", (_event, ctx) => {
491
- runtime.isStreaming = false;
492
- scheduleRefresh(ctx);
493
- const target = activeTarget;
494
- if (target?.sessionManager === ctx.sessionManager) requestGithubPr(target);
495
- refresh();
496
- });
497
- pi.on("ui_prompt_start", (event, ctx) => {
498
- if (!ownsRuntime(ctx)) return;
499
- runtime.uiPrompt = { kind: event.kind, title: event.title };
500
- refresh();
501
- });
502
- pi.on("ui_prompt_end", (_event, ctx) => {
503
- if (!ownsRuntime(ctx)) return;
504
- runtime.uiPrompt = undefined;
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
- cwd: string,
531
- config: StarshipConfig,
532
- reason: WorkspaceRefreshInput["reason"],
533
- previous: WorkspaceSnapshot | undefined,
503
+ cwd: string,
504
+ config: StarshipConfig,
505
+ reason: WorkspaceRefreshInput["reason"],
506
+ previous: WorkspaceSnapshot | undefined,
534
507
  ): WorkspaceRefreshInput {
535
- return {
536
- cwd,
537
- config,
538
- environment: allowlistedEnvironment(config),
539
- homeDir: homedir(),
540
- platform: process.platform,
541
- hostname: hostname(),
542
- username: safeUsername(),
543
- exec: execWorkspaceCommand,
544
- reason,
545
- previous,
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
- "AWS_CONFIG_FILE",
551
- "AWS_DEFAULT_PROFILE",
552
- "AWS_DEFAULT_REGION",
553
- "AWS_PROFILE",
554
- "AWS_REGION",
555
- "AZURE_CONFIG_DIR",
556
- "CLOUDSDK_ACTIVE_CONFIG_NAME",
557
- "CLOUDSDK_CONFIG",
558
- "CODESPACES",
559
- "CONDA_DEFAULT_ENV",
560
- "DOCKER_CONFIG",
561
- "DOCKER_CONTEXT",
562
- "GUIX_ENVIRONMENT",
563
- "IN_NIX_SHELL",
564
- "KUBECONFIG",
565
- "LOGNAME",
566
- "NIX_SHELL_LEVEL",
567
- "NIX_SHELL_NAME",
568
- "OS_CLIENT_CONFIG_FILE",
569
- "OS_CLOUD",
570
- "OS_PROJECT_NAME",
571
- "PATH",
572
- "PIXI_ENVIRONMENT_NAME",
573
- "PIXI_PROJECT_NAME",
574
- "PYENV_VERSION",
575
- "REMOTE_CONTAINERS",
576
- "RUSTC",
577
- "RUSTUP_TOOLCHAIN",
578
- "SSH_CONNECTION",
579
- "SSH_TTY",
580
- "TF_DATA_DIR",
581
- "TF_WORKSPACE",
582
- "USER",
583
- "USERNAME",
584
- "VIRTUAL_ENV",
585
- "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",
586
559
  ] as const;
587
560
 
588
561
  function allowlistedEnvironment(config: StarshipConfig): Record<string, string | undefined> {
589
- const result: Record<string, string | undefined> = {};
590
- const configured = config.modules.username.options.detect_env_vars;
591
- const names = new Set([
592
- ...ENVIRONMENT_ALLOWLIST,
593
- ...(Array.isArray(configured)
594
- ? configured.filter((name): name is string => typeof name === "string")
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
- try {
603
- return userInfo().username;
604
- } catch {
605
- return process.env.USER ?? process.env.USERNAME ?? "";
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
- ctx: ExtensionContext,
611
- footerData: ReadonlyFooterDataProvider,
612
- runtime: RuntimeState,
581
+ ctx: ExtensionContext,
582
+ footerData: ReadonlyFooterDataProvider,
583
+ runtime: RuntimeState,
613
584
  ): StarshipRuntimeSnapshot {
614
- return {
615
- cwd: ctx.cwd,
616
- homeDir: homedir(),
617
- gitRoot: runtime.git?.root,
618
- model: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,
619
- thinkingLevel: runtime.thinkingLevel,
620
- turnCount: userTurnCount(ctx),
621
- activeTools: runtime.activeTools,
622
- isStreaming: runtime.isStreaming,
623
- uiPrompt: runtime.uiPrompt,
624
- lastCompletedTool: runtime.lastCompletedTool,
625
- contextUsage: ctx.getContextUsage() ?? undefined,
626
- tokenTotals: summarizeFooterUsage(ctx.sessionManager.getEntries()),
627
- usingSubscription: isSubscriptionBacked(ctx),
628
- gitBranch: runtime.git?.branch?.name ?? footerData.getGitBranch(),
629
- gitBranchDetails: runtime.git?.branch,
630
- gitCommit: runtime.git?.commit,
631
- gitState: runtime.git?.state,
632
- gitMetrics: runtime.git?.metrics,
633
- gitStatus: runtime.git?.status,
634
- gitWorktree: runtime.git?.worktree,
635
- githubPr: runtime.githubPr,
636
- workspace: runtime.workspace,
637
- extensionStatuses: footerData.getExtensionStatuses(),
638
- now: new Date(),
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
- return ctx.sessionManager
644
- .getBranch()
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
- const model = ctx.model;
650
- return (
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
- const details = loaded.diagnostics.slice(0, 5).map((item) => item.message);
658
- const remaining = loaded.diagnostics.length - details.length;
659
- return [
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
- if (width <= 0) return [];
667
- return wrapTextWithAnsi(format, width);
630
+ if (width <= 0) return [];
631
+ return wrapTextWithAnsi(format, width);
668
632
  }
669
633
 
670
634
  export {
671
- parseGitDiffShortstat,
672
- parseGitState,
673
- parseGitStatusPorcelain,
674
- parseGitStatusPorcelainV2,
675
- parseGitWorktree,
635
+ parseGitDiffShortstat,
636
+ parseGitState,
637
+ parseGitStatusPorcelain,
638
+ parseGitStatusPorcelainV2,
639
+ parseGitWorktree,
676
640
  } from "./modules/git/runtime.js";