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