@narumitw/pi-starship 0.24.0 → 0.29.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 +18 -1
- package/README.md +202 -16
- package/package.json +4 -3
- package/src/commands.ts +405 -22
- package/src/config.ts +113 -11
- package/src/format/formatter.ts +26 -11
- package/src/format/style.ts +13 -1
- package/src/index.ts +1 -0
- package/src/modules/catalog.ts +20 -0
- package/src/modules/cloud.ts +74 -0
- package/src/modules/deployment.ts +61 -0
- package/src/modules/development.ts +95 -0
- package/src/modules/execution.ts +73 -0
- package/src/modules/extension-status.ts +33 -1
- package/src/modules/fill.ts +14 -0
- package/src/modules/git/branch.ts +7 -3
- package/src/modules/git/commit.ts +22 -0
- package/src/modules/git/metrics.ts +20 -0
- package/src/modules/git/runtime.ts +320 -41
- package/src/modules/git/state.ts +21 -0
- package/src/modules/git/status.ts +62 -11
- package/src/modules/index.ts +7 -1
- package/src/modules/languages.ts +87 -0
- package/src/modules/package.ts +17 -0
- package/src/modules/render.ts +97 -9
- package/src/modules/types.ts +65 -2
- package/src/modules/workspace-helpers.ts +10 -0
- package/src/pi-starship.ts +230 -104
- package/src/runtime/cloud.ts +166 -0
- package/src/runtime/command.ts +85 -0
- package/src/runtime/deployment.ts +201 -0
- package/src/runtime/development.ts +154 -0
- package/src/runtime/execution.ts +141 -0
- package/src/runtime/helpers.ts +273 -0
- package/src/runtime/languages.ts +205 -0
- package/src/runtime/package.ts +112 -0
- package/src/runtime/refresh-controller.ts +85 -0
- package/src/runtime/types.ts +59 -0
- package/src/runtime/workspace.ts +110 -0
|
@@ -1,20 +1,104 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
2
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
GitBranchSnapshot,
|
|
6
|
+
GitCommitSnapshot,
|
|
7
|
+
GitMetricsSnapshot,
|
|
8
|
+
GitSnapshot,
|
|
9
|
+
GitStateSnapshot,
|
|
10
|
+
GitStatusSnapshot,
|
|
11
|
+
GitWorktreeSnapshot,
|
|
12
|
+
} from "../types.js";
|
|
4
13
|
|
|
5
14
|
const GIT_TIMEOUT_MS = 3_000;
|
|
6
15
|
|
|
16
|
+
export interface ReadGitSnapshotOptions {
|
|
17
|
+
includeMetrics: boolean;
|
|
18
|
+
includeTag: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function readGitSnapshot(
|
|
22
|
+
pi: ExtensionAPI,
|
|
23
|
+
cwd: string,
|
|
24
|
+
options: ReadGitSnapshotOptions,
|
|
25
|
+
): Promise<GitSnapshot | undefined> {
|
|
26
|
+
const statusPromise = pi.exec(
|
|
27
|
+
"git",
|
|
28
|
+
[
|
|
29
|
+
"--no-optional-locks",
|
|
30
|
+
"status",
|
|
31
|
+
"--porcelain=v2",
|
|
32
|
+
"--branch",
|
|
33
|
+
"--show-stash",
|
|
34
|
+
"--untracked-files=normal",
|
|
35
|
+
],
|
|
36
|
+
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
37
|
+
);
|
|
38
|
+
const metadataPromise = pi.exec(
|
|
39
|
+
"git",
|
|
40
|
+
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
41
|
+
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
42
|
+
);
|
|
43
|
+
const metricsPromise = options.includeMetrics
|
|
44
|
+
? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
|
|
45
|
+
cwd,
|
|
46
|
+
timeout: GIT_TIMEOUT_MS,
|
|
47
|
+
})
|
|
48
|
+
: Promise.resolve(undefined);
|
|
49
|
+
const tagPromise = options.includeTag
|
|
50
|
+
? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
|
|
51
|
+
cwd,
|
|
52
|
+
timeout: GIT_TIMEOUT_MS,
|
|
53
|
+
})
|
|
54
|
+
: Promise.resolve(undefined);
|
|
55
|
+
|
|
56
|
+
const [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([
|
|
57
|
+
statusPromise,
|
|
58
|
+
metadataPromise,
|
|
59
|
+
metricsPromise,
|
|
60
|
+
tagPromise,
|
|
61
|
+
]);
|
|
62
|
+
if (statusResult.code !== 0 || statusResult.killed) return undefined;
|
|
63
|
+
|
|
64
|
+
const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
|
|
65
|
+
const metadata =
|
|
66
|
+
metadataResult.code === 0 && !metadataResult.killed
|
|
67
|
+
? parseGitRepositoryMetadata(metadataResult.stdout)
|
|
68
|
+
: undefined;
|
|
69
|
+
const commit = withTag(parsed.commit, tagResult);
|
|
70
|
+
const metrics =
|
|
71
|
+
metricsResult && metricsResult.code === 0 && !metricsResult.killed
|
|
72
|
+
? parseGitDiffShortstat(metricsResult.stdout)
|
|
73
|
+
: undefined;
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
...parsed,
|
|
77
|
+
commit,
|
|
78
|
+
state: metadata ? parseGitState(metadata.gitDirectory) : undefined,
|
|
79
|
+
metrics,
|
|
80
|
+
worktree: metadata?.worktree,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
7
84
|
export async function readGitStatus(
|
|
8
85
|
pi: ExtensionAPI,
|
|
9
86
|
cwd: string,
|
|
10
87
|
): Promise<GitStatusSnapshot | undefined> {
|
|
11
88
|
const result = await pi.exec(
|
|
12
89
|
"git",
|
|
13
|
-
[
|
|
90
|
+
[
|
|
91
|
+
"--no-optional-locks",
|
|
92
|
+
"status",
|
|
93
|
+
"--porcelain=v2",
|
|
94
|
+
"--branch",
|
|
95
|
+
"--show-stash",
|
|
96
|
+
"--untracked-files=normal",
|
|
97
|
+
],
|
|
14
98
|
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
15
99
|
);
|
|
16
100
|
if (result.code !== 0 || result.killed) return undefined;
|
|
17
|
-
return
|
|
101
|
+
return parseGitStatusPorcelainV2(result.stdout).status;
|
|
18
102
|
}
|
|
19
103
|
|
|
20
104
|
export async function readGitWorktree(
|
|
@@ -27,51 +111,251 @@ export async function readGitWorktree(
|
|
|
27
111
|
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
28
112
|
);
|
|
29
113
|
if (result.code !== 0 || result.killed) return undefined;
|
|
30
|
-
return
|
|
114
|
+
return parseGitRepositoryMetadata(result.stdout)?.worktree;
|
|
31
115
|
}
|
|
32
116
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
117
|
+
interface ParsedGitStatus {
|
|
118
|
+
branch?: GitBranchSnapshot;
|
|
119
|
+
commit?: GitCommitSnapshot;
|
|
120
|
+
status: GitStatusSnapshot;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {
|
|
124
|
+
const status = emptyGitStatus();
|
|
125
|
+
let branchName: string | undefined;
|
|
126
|
+
let commitHash: string | undefined;
|
|
127
|
+
let upstream: string | undefined;
|
|
128
|
+
|
|
129
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
130
|
+
if (!line) continue;
|
|
131
|
+
if (line.startsWith("# branch.oid ")) {
|
|
132
|
+
const value = line.slice("# branch.oid ".length).trim();
|
|
133
|
+
if (value && value !== "(initial)") commitHash = value;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (line.startsWith("# branch.head ")) {
|
|
137
|
+
branchName = line.slice("# branch.head ".length).trim();
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (line.startsWith("# branch.upstream ")) {
|
|
141
|
+
upstream = line.slice("# branch.upstream ".length).trim();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (line.startsWith("# branch.ab ")) {
|
|
145
|
+
const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(line);
|
|
146
|
+
status.ahead = match?.[1] ? Number(match[1]) : 0;
|
|
147
|
+
status.behind = match?.[2] ? Number(match[2]) : 0;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (line.startsWith("# stash ")) {
|
|
151
|
+
const count = Number(line.slice("# stash ".length));
|
|
152
|
+
status.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
addPorcelainV2Status(status, line);
|
|
156
|
+
}
|
|
157
|
+
finalizeStatus(status);
|
|
158
|
+
|
|
159
|
+
const detached = branchName === "(detached)";
|
|
160
|
+
const remote = splitUpstream(upstream);
|
|
161
|
+
const branch = branchName
|
|
162
|
+
? {
|
|
163
|
+
name: detached ? "HEAD" : branchName,
|
|
164
|
+
...remote,
|
|
165
|
+
detached,
|
|
166
|
+
}
|
|
167
|
+
: undefined;
|
|
168
|
+
const commit = commitHash ? { hash: commitHash, detached } : undefined;
|
|
169
|
+
return { branch, commit, status };
|
|
41
170
|
}
|
|
42
171
|
|
|
43
172
|
export function parseGitStatusPorcelain(output: string): GitStatusSnapshot {
|
|
44
|
-
const
|
|
45
|
-
ahead: 0,
|
|
46
|
-
behind: 0,
|
|
47
|
-
staged: 0,
|
|
48
|
-
modified: 0,
|
|
49
|
-
untracked: 0,
|
|
50
|
-
conflicted: 0,
|
|
51
|
-
};
|
|
173
|
+
const status = emptyGitStatus();
|
|
52
174
|
for (const line of output.split(/\r?\n/u)) {
|
|
53
175
|
if (!line) continue;
|
|
54
176
|
if (line.startsWith("## ")) {
|
|
55
177
|
const ahead = /\bahead (\d+)/u.exec(line);
|
|
56
178
|
const behind = /\bbehind (\d+)/u.exec(line);
|
|
57
|
-
|
|
58
|
-
|
|
179
|
+
status.ahead = ahead?.[1] ? Number(ahead[1]) : 0;
|
|
180
|
+
status.behind = behind?.[1] ? Number(behind[1]) : 0;
|
|
59
181
|
continue;
|
|
60
182
|
}
|
|
61
183
|
const indexStatus = line[0] ?? " ";
|
|
62
184
|
const worktreeStatus = line[1] ?? " ";
|
|
63
185
|
if (indexStatus === "?" && worktreeStatus === "?") {
|
|
64
|
-
|
|
186
|
+
status.untracked += 1;
|
|
65
187
|
continue;
|
|
66
188
|
}
|
|
67
189
|
if (isConflict(indexStatus, worktreeStatus)) {
|
|
68
|
-
|
|
190
|
+
status.conflicted += 1;
|
|
69
191
|
continue;
|
|
70
192
|
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
193
|
+
addNormalStatus(status, indexStatus, worktreeStatus);
|
|
194
|
+
if (indexStatus === "R" || indexStatus === "C") status.renamed += 1;
|
|
195
|
+
}
|
|
196
|
+
finalizeStatus(status);
|
|
197
|
+
return status;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function parseGitDiffShortstat(output: string): GitMetricsSnapshot {
|
|
201
|
+
const added = /(\d+) insertions?\(\+\)/u.exec(output)?.[1];
|
|
202
|
+
const deleted = /(\d+) deletions?\(-\)/u.exec(output)?.[1];
|
|
203
|
+
return {
|
|
204
|
+
added: added ? Number(added) : 0,
|
|
205
|
+
deleted: deleted ? Number(deleted) : 0,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function parseGitState(gitDirectory: string): GitStateSnapshot | undefined {
|
|
210
|
+
const rebaseMerge = join(gitDirectory, "rebase-merge");
|
|
211
|
+
if (existsSync(rebaseMerge))
|
|
212
|
+
return operationWithProgress("REBASING", rebaseMerge, "msgnum", "end");
|
|
213
|
+
|
|
214
|
+
const rebaseApply = join(gitDirectory, "rebase-apply");
|
|
215
|
+
if (existsSync(rebaseApply)) {
|
|
216
|
+
const state = existsSync(join(rebaseApply, "applying"))
|
|
217
|
+
? "AM"
|
|
218
|
+
: existsSync(join(rebaseApply, "rebasing"))
|
|
219
|
+
? "REBASING"
|
|
220
|
+
: "AM/REBASE";
|
|
221
|
+
return operationWithProgress(state, rebaseApply, "next", "last");
|
|
222
|
+
}
|
|
223
|
+
if (existsSync(join(gitDirectory, "MERGE_HEAD"))) return { state: "MERGING" };
|
|
224
|
+
if (existsSync(join(gitDirectory, "REVERT_HEAD"))) return { state: "REVERTING" };
|
|
225
|
+
if (existsSync(join(gitDirectory, "CHERRY_PICK_HEAD"))) return { state: "CHERRY-PICKING" };
|
|
226
|
+
if (existsSync(join(gitDirectory, "BISECT_LOG"))) return { state: "BISECTING" };
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
interface GitRepositoryMetadata {
|
|
231
|
+
gitDirectory: string;
|
|
232
|
+
worktree?: GitWorktreeSnapshot;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function parseGitRepositoryMetadata(output: string): GitRepositoryMetadata | undefined {
|
|
236
|
+
const lines = output.trimEnd().split(/\r?\n/u);
|
|
237
|
+
if (lines.length !== 3) return undefined;
|
|
238
|
+
const [path, commonDir, gitDirectory] = lines;
|
|
239
|
+
if (!path || !commonDir || !gitDirectory) return undefined;
|
|
240
|
+
if (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;
|
|
241
|
+
return {
|
|
242
|
+
gitDirectory,
|
|
243
|
+
worktree: samePath(commonDir, gitDirectory)
|
|
244
|
+
? undefined
|
|
245
|
+
: { name: basename(path) || path, path },
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function parseGitWorktree(output: string): GitWorktreeSnapshot | undefined {
|
|
250
|
+
return parseGitRepositoryMetadata(output)?.worktree;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function addPorcelainV2Status(status: GitStatusSnapshot, line: string) {
|
|
254
|
+
const kind = line[0];
|
|
255
|
+
if (kind === "?") {
|
|
256
|
+
status.untracked += 1;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (kind === "u") {
|
|
260
|
+
status.conflicted += 1;
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (kind !== "1" && kind !== "2") return;
|
|
264
|
+
const indexStatus = line[2] ?? ".";
|
|
265
|
+
const worktreeStatus = line[3] ?? ".";
|
|
266
|
+
addNormalStatus(status, indexStatus, worktreeStatus);
|
|
267
|
+
if (kind === "2") status.renamed += 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function addNormalStatus(status: GitStatusSnapshot, indexStatus: string, worktreeStatus: string) {
|
|
271
|
+
if (indexStatus === "A") status.indexAdded += 1;
|
|
272
|
+
if (indexStatus === "D") status.indexDeleted += 1;
|
|
273
|
+
if (indexStatus === "M") status.indexModified += 1;
|
|
274
|
+
if (indexStatus === "T") status.indexTypechanged += 1;
|
|
275
|
+
if (worktreeStatus === "A") status.worktreeAdded += 1;
|
|
276
|
+
if (worktreeStatus === "D") status.worktreeDeleted += 1;
|
|
277
|
+
if (worktreeStatus === "M") status.worktreeModified += 1;
|
|
278
|
+
if (worktreeStatus === "T") status.worktreeTypechanged += 1;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function finalizeStatus(status: GitStatusSnapshot) {
|
|
282
|
+
status.deleted = status.worktreeDeleted + status.indexDeleted;
|
|
283
|
+
status.modified = status.worktreeModified + status.worktreeAdded;
|
|
284
|
+
status.staged = status.indexModified + status.indexAdded + status.indexTypechanged;
|
|
285
|
+
status.typechanged = status.worktreeTypechanged;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function emptyGitStatus(): GitStatusSnapshot {
|
|
289
|
+
return {
|
|
290
|
+
ahead: 0,
|
|
291
|
+
behind: 0,
|
|
292
|
+
stashed: 0,
|
|
293
|
+
conflicted: 0,
|
|
294
|
+
deleted: 0,
|
|
295
|
+
renamed: 0,
|
|
296
|
+
modified: 0,
|
|
297
|
+
staged: 0,
|
|
298
|
+
typechanged: 0,
|
|
299
|
+
untracked: 0,
|
|
300
|
+
worktreeAdded: 0,
|
|
301
|
+
worktreeDeleted: 0,
|
|
302
|
+
worktreeModified: 0,
|
|
303
|
+
worktreeTypechanged: 0,
|
|
304
|
+
indexAdded: 0,
|
|
305
|
+
indexDeleted: 0,
|
|
306
|
+
indexModified: 0,
|
|
307
|
+
indexTypechanged: 0,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function splitUpstream(upstream: string | undefined): {
|
|
312
|
+
remoteName?: string;
|
|
313
|
+
remoteBranch?: string;
|
|
314
|
+
} {
|
|
315
|
+
if (!upstream) return {};
|
|
316
|
+
const separator = upstream.indexOf("/");
|
|
317
|
+
if (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };
|
|
318
|
+
return {
|
|
319
|
+
remoteName: upstream.slice(0, separator),
|
|
320
|
+
remoteBranch: upstream.slice(separator + 1),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function withTag(
|
|
325
|
+
commit: GitCommitSnapshot | undefined,
|
|
326
|
+
result:
|
|
327
|
+
| {
|
|
328
|
+
stdout: string;
|
|
329
|
+
code: number;
|
|
330
|
+
killed: boolean;
|
|
331
|
+
}
|
|
332
|
+
| undefined,
|
|
333
|
+
): GitCommitSnapshot | undefined {
|
|
334
|
+
if (!commit || !result || result.code !== 0 || result.killed) return commit;
|
|
335
|
+
const tag = result.stdout.trim();
|
|
336
|
+
return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function operationWithProgress(
|
|
340
|
+
state: string,
|
|
341
|
+
directory: string,
|
|
342
|
+
currentName: string,
|
|
343
|
+
totalName: string,
|
|
344
|
+
): GitStateSnapshot {
|
|
345
|
+
const progressCurrent = readPositiveInteger(join(directory, currentName));
|
|
346
|
+
const progressTotal = readPositiveInteger(join(directory, totalName));
|
|
347
|
+
return progressCurrent !== undefined && progressTotal !== undefined
|
|
348
|
+
? { state, progressCurrent, progressTotal }
|
|
349
|
+
: { state };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function readPositiveInteger(path: string): number | undefined {
|
|
353
|
+
try {
|
|
354
|
+
const value = Number(readFileSync(path, "utf8").trim());
|
|
355
|
+
return Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
356
|
+
} catch {
|
|
357
|
+
return undefined;
|
|
73
358
|
}
|
|
74
|
-
return summary;
|
|
75
359
|
}
|
|
76
360
|
|
|
77
361
|
function samePath(left: string, right: string): boolean {
|
|
@@ -91,21 +375,16 @@ function isConflict(indexStatus: string, worktreeStatus: string): boolean {
|
|
|
91
375
|
);
|
|
92
376
|
}
|
|
93
377
|
|
|
94
|
-
function isChanged(status: string): boolean {
|
|
95
|
-
return status !== " " && status !== "?" && status !== "!";
|
|
96
|
-
}
|
|
97
|
-
|
|
98
378
|
export function gitStatusEqual(
|
|
99
379
|
left: GitStatusSnapshot | undefined,
|
|
100
380
|
right: GitStatusSnapshot | undefined,
|
|
101
381
|
): boolean {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
382
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export function gitSnapshotEqual(
|
|
386
|
+
left: GitSnapshot | undefined,
|
|
387
|
+
right: GitSnapshot | undefined,
|
|
388
|
+
): boolean {
|
|
389
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
111
390
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineModule } from "../types.js";
|
|
2
|
+
|
|
3
|
+
export const gitStateModule = defineModule({
|
|
4
|
+
name: "git_state",
|
|
5
|
+
variables: ["symbol", "state", "progress_current", "progress_total"],
|
|
6
|
+
defaults: {
|
|
7
|
+
format: "[ ($state( $progress_current/$progress_total)) ]($style)",
|
|
8
|
+
symbol: "",
|
|
9
|
+
style: "bold yellow bg:git",
|
|
10
|
+
disabled: false,
|
|
11
|
+
},
|
|
12
|
+
values: ({ runtime }) => {
|
|
13
|
+
const state = runtime.gitState;
|
|
14
|
+
if (!state) return undefined;
|
|
15
|
+
return {
|
|
16
|
+
state: state.state,
|
|
17
|
+
progress_current: state.progressCurrent?.toString() ?? "",
|
|
18
|
+
progress_total: state.progressTotal?.toString() ?? "",
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -6,15 +6,30 @@ export const gitStatusModule = defineModule({
|
|
|
6
6
|
variables: [
|
|
7
7
|
"symbol",
|
|
8
8
|
"all_status",
|
|
9
|
+
"ahead_behind",
|
|
9
10
|
"ahead",
|
|
10
11
|
"behind",
|
|
11
|
-
"
|
|
12
|
+
"up_to_date",
|
|
13
|
+
"diverged",
|
|
14
|
+
"conflicted",
|
|
15
|
+
"stashed",
|
|
16
|
+
"deleted",
|
|
17
|
+
"renamed",
|
|
12
18
|
"modified",
|
|
19
|
+
"typechanged",
|
|
20
|
+
"staged",
|
|
13
21
|
"untracked",
|
|
14
|
-
"
|
|
22
|
+
"worktree_added",
|
|
23
|
+
"worktree_deleted",
|
|
24
|
+
"worktree_modified",
|
|
25
|
+
"worktree_typechanged",
|
|
26
|
+
"index_added",
|
|
27
|
+
"index_deleted",
|
|
28
|
+
"index_modified",
|
|
29
|
+
"index_typechanged",
|
|
15
30
|
],
|
|
16
31
|
defaults: {
|
|
17
|
-
format: "[$all_status ]($style)",
|
|
32
|
+
format: "[$all_status( $ahead_behind) ]($style)",
|
|
18
33
|
symbol: "",
|
|
19
34
|
style: "fg:git_fg bg:git",
|
|
20
35
|
disabled: false,
|
|
@@ -22,15 +37,51 @@ export const gitStatusModule = defineModule({
|
|
|
22
37
|
values: ({ runtime }) => {
|
|
23
38
|
if (!runtime.gitBranch || !runtime.gitStatus) return undefined;
|
|
24
39
|
const status = runtime.gitStatus;
|
|
40
|
+
const ahead = count("⇡", status.ahead);
|
|
41
|
+
const behind = count("⇣", status.behind);
|
|
42
|
+
const diverged =
|
|
43
|
+
status.ahead > 0 && status.behind > 0
|
|
44
|
+
? `⇕⇡${formatCount(status.ahead)}⇣${formatCount(status.behind)}`
|
|
45
|
+
: "";
|
|
25
46
|
const values = {
|
|
26
|
-
ahead
|
|
27
|
-
behind
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
conflicted:
|
|
47
|
+
ahead,
|
|
48
|
+
behind,
|
|
49
|
+
up_to_date: "",
|
|
50
|
+
diverged,
|
|
51
|
+
ahead_behind: diverged || ahead || behind,
|
|
52
|
+
conflicted: count("=", status.conflicted),
|
|
53
|
+
stashed: count("$", status.stashed),
|
|
54
|
+
deleted: count("✘", status.deleted),
|
|
55
|
+
renamed: count("»", status.renamed),
|
|
56
|
+
modified: count("!", status.modified),
|
|
57
|
+
typechanged: count("T", status.typechanged),
|
|
58
|
+
staged: count("+", status.staged),
|
|
59
|
+
untracked: count("?", status.untracked),
|
|
60
|
+
worktree_added: count("A", status.worktreeAdded),
|
|
61
|
+
worktree_deleted: count("D", status.worktreeDeleted),
|
|
62
|
+
worktree_modified: count("M", status.worktreeModified),
|
|
63
|
+
worktree_typechanged: count("T", status.worktreeTypechanged),
|
|
64
|
+
index_added: count("A", status.indexAdded),
|
|
65
|
+
index_deleted: count("D", status.indexDeleted),
|
|
66
|
+
index_modified: count("M", status.indexModified),
|
|
67
|
+
index_typechanged: count("T", status.indexTypechanged),
|
|
32
68
|
};
|
|
33
|
-
const allStatus =
|
|
34
|
-
|
|
69
|
+
const allStatus = [
|
|
70
|
+
values.conflicted,
|
|
71
|
+
values.stashed,
|
|
72
|
+
values.deleted,
|
|
73
|
+
values.renamed,
|
|
74
|
+
values.modified,
|
|
75
|
+
values.typechanged,
|
|
76
|
+
values.staged,
|
|
77
|
+
values.untracked,
|
|
78
|
+
]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(" ");
|
|
81
|
+
return allStatus || values.ahead_behind ? { ...values, all_status: allStatus } : undefined;
|
|
35
82
|
},
|
|
36
83
|
});
|
|
84
|
+
|
|
85
|
+
function count(symbol: string, value: number): string {
|
|
86
|
+
return value > 0 ? `${symbol}${formatCount(value)}` : "";
|
|
87
|
+
}
|
package/src/modules/index.ts
CHANGED
|
@@ -6,11 +6,17 @@ export {
|
|
|
6
6
|
export { prContextFromStatuses } from "./git/branch.js";
|
|
7
7
|
export { formatCount } from "./helpers.js";
|
|
8
8
|
export { shortenModel } from "./model.js";
|
|
9
|
-
export { renderStatusline } from "./render.js";
|
|
9
|
+
export { reachableModuleRequirements, renderStatusline } from "./render.js";
|
|
10
10
|
export type {
|
|
11
11
|
ExtensionStatusIconAliasMap,
|
|
12
|
+
GitBranchSnapshot,
|
|
13
|
+
GitCommitSnapshot,
|
|
14
|
+
GitMetricsSnapshot,
|
|
15
|
+
GitSnapshot,
|
|
16
|
+
GitStateSnapshot,
|
|
12
17
|
GitStatusSnapshot,
|
|
13
18
|
GitWorktreeSnapshot,
|
|
14
19
|
RenderedStatusline,
|
|
15
20
|
StarshipRuntimeSnapshot,
|
|
21
|
+
WorkspaceSnapshot,
|
|
16
22
|
} from "./types.js";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { defineModule, type ModuleDefinition } from "./types.js";
|
|
2
|
+
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
3
|
+
|
|
4
|
+
const detectionOptions = {
|
|
5
|
+
version_format: { kind: "string", default: "v$raw" },
|
|
6
|
+
detect_files: { kind: "string-array", default: [], allowNegative: true },
|
|
7
|
+
detect_extensions: { kind: "string-array", default: [], allowNegative: true },
|
|
8
|
+
detect_folders: { kind: "string-array", default: [], allowNegative: true },
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
function languageModule<const Name extends string>(definition: {
|
|
12
|
+
name: Name;
|
|
13
|
+
variables: readonly string[];
|
|
14
|
+
format: string;
|
|
15
|
+
symbol: string;
|
|
16
|
+
style: string;
|
|
17
|
+
}): ModuleDefinition<Name> {
|
|
18
|
+
return defineModule({
|
|
19
|
+
name: definition.name,
|
|
20
|
+
variables: ["symbol", ...definition.variables],
|
|
21
|
+
defaults: {
|
|
22
|
+
format: definition.format,
|
|
23
|
+
symbol: definition.symbol,
|
|
24
|
+
style: definition.style,
|
|
25
|
+
disabled: false,
|
|
26
|
+
},
|
|
27
|
+
options: detectionOptions,
|
|
28
|
+
values: (context) => workspaceModuleValues(definition.name, context),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const nodejsModule = languageModule({
|
|
33
|
+
name: "nodejs",
|
|
34
|
+
variables: ["version", "engines_version"],
|
|
35
|
+
format: "via [$symbol($version )]($style)",
|
|
36
|
+
symbol: " ",
|
|
37
|
+
style: "bold green",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const pythonModule = languageModule({
|
|
41
|
+
name: "python",
|
|
42
|
+
variables: ["version", "virtualenv", "pyenv_prefix"],
|
|
43
|
+
format: "via [$symbol$pyenv_prefix($version )(\\($virtualenv\\) )]($style)",
|
|
44
|
+
symbol: " ",
|
|
45
|
+
style: "yellow bold",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const rustModule = languageModule({
|
|
49
|
+
name: "rust",
|
|
50
|
+
variables: ["version", "numver", "toolchain"],
|
|
51
|
+
format: "via [$symbol($version )]($style)",
|
|
52
|
+
symbol: " ",
|
|
53
|
+
style: "bold red",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const golangModule = languageModule({
|
|
57
|
+
name: "golang",
|
|
58
|
+
variables: ["version", "mod_version"],
|
|
59
|
+
format: "via [$symbol($version )]($style)",
|
|
60
|
+
symbol: " ",
|
|
61
|
+
style: "bold cyan",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const bunModule = languageModule({
|
|
65
|
+
name: "bun",
|
|
66
|
+
variables: ["version"],
|
|
67
|
+
format: "via [$symbol($version )]($style)",
|
|
68
|
+
symbol: "🍞 ",
|
|
69
|
+
style: "bold red",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const denoModule = languageModule({
|
|
73
|
+
name: "deno",
|
|
74
|
+
variables: ["version"],
|
|
75
|
+
format: "via [$symbol($version )]($style)",
|
|
76
|
+
symbol: "🦕 ",
|
|
77
|
+
style: "green bold",
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const languageModules = [
|
|
81
|
+
nodejsModule,
|
|
82
|
+
pythonModule,
|
|
83
|
+
rustModule,
|
|
84
|
+
golangModule,
|
|
85
|
+
bunModule,
|
|
86
|
+
denoModule,
|
|
87
|
+
] as const;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineModule } from "./types.js";
|
|
2
|
+
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
3
|
+
|
|
4
|
+
export const packageModule = defineModule({
|
|
5
|
+
name: "package",
|
|
6
|
+
variables: ["symbol", "version", "source"],
|
|
7
|
+
defaults: {
|
|
8
|
+
format: "via [$symbol$version]($style) ",
|
|
9
|
+
symbol: "📦 ",
|
|
10
|
+
style: "bold 208",
|
|
11
|
+
disabled: false,
|
|
12
|
+
},
|
|
13
|
+
options: {
|
|
14
|
+
version_format: { kind: "string", default: "v$raw" },
|
|
15
|
+
},
|
|
16
|
+
values: (context) => workspaceModuleValues("package", context),
|
|
17
|
+
});
|