@narumitw/pi-starship 0.55.0 → 0.55.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +21 -36
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  3. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  11. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +38 -53
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
  26. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  27. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  28. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  29. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  30. package/src/command-configuration.ts +267 -286
  31. package/src/command-contract.ts +6 -6
  32. package/src/command-inspector.ts +27 -27
  33. package/src/command-preset-picker.ts +45 -50
  34. package/src/command-preview.ts +153 -166
  35. package/src/commands.ts +588 -618
  36. package/src/config.ts +580 -660
  37. package/src/effective-config.ts +46 -48
  38. package/src/format/formatter.ts +211 -227
  39. package/src/format/style.ts +205 -216
  40. package/src/modules/activity.ts +74 -74
  41. package/src/modules/brand.ts +9 -9
  42. package/src/modules/cache.ts +18 -18
  43. package/src/modules/catalog.ts +79 -83
  44. package/src/modules/cloud.ts +54 -54
  45. package/src/modules/context.ts +27 -27
  46. package/src/modules/cost.ts +23 -23
  47. package/src/modules/deployment.ts +45 -45
  48. package/src/modules/development.ts +80 -81
  49. package/src/modules/directory.ts +89 -113
  50. package/src/modules/display.ts +9 -9
  51. package/src/modules/execution.ts +62 -69
  52. package/src/modules/extension-status.ts +59 -64
  53. package/src/modules/fill.ts +10 -10
  54. package/src/modules/git/branch.ts +26 -26
  55. package/src/modules/git/commit.ts +21 -23
  56. package/src/modules/git/metrics.ts +22 -22
  57. package/src/modules/git/runtime.ts +299 -334
  58. package/src/modules/git/state.ts +17 -17
  59. package/src/modules/git/status.ts +77 -79
  60. package/src/modules/git/worktree.ts +10 -12
  61. package/src/modules/github-pr.ts +20 -20
  62. package/src/modules/helpers.ts +3 -3
  63. package/src/modules/index.ts +21 -21
  64. package/src/modules/inspection.ts +101 -108
  65. package/src/modules/languages.ts +52 -59
  66. package/src/modules/model.ts +57 -67
  67. package/src/modules/package.ts +12 -12
  68. package/src/modules/provider.ts +22 -24
  69. package/src/modules/render.ts +124 -140
  70. package/src/modules/thinking.ts +27 -26
  71. package/src/modules/time.ts +10 -13
  72. package/src/modules/tokens.ts +13 -13
  73. package/src/modules/truncation.ts +14 -17
  74. package/src/modules/turn.ts +9 -9
  75. package/src/modules/types.ts +125 -132
  76. package/src/modules/workspace-helpers.ts +4 -7
  77. package/src/pi-starship.ts +567 -571
  78. package/src/presets/catalog.ts +113 -113
  79. package/src/runtime/cloud.ts +122 -150
  80. package/src/runtime/command.ts +106 -108
  81. package/src/runtime/deployment.ts +150 -179
  82. package/src/runtime/development.ts +107 -124
  83. package/src/runtime/execution.ts +110 -124
  84. package/src/runtime/github-pr.ts +223 -252
  85. package/src/runtime/helpers.ts +186 -199
  86. package/src/runtime/languages.ts +149 -180
  87. package/src/runtime/package.ts +74 -87
  88. package/src/runtime/refresh-controller.ts +82 -86
  89. package/src/runtime/types.ts +38 -38
  90. package/src/runtime/workspace.ts +108 -116
  91. package/src/usage.ts +40 -40
  92. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  93. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  94. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  95. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  96. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  97. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  98. package/dist/chunks/development-BERD42HW.js.map +0 -7
  99. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  100. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  101. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -2,414 +2,379 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { basename, isAbsolute, join, resolve } from "node:path";
3
3
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
4
  import type {
5
- GitBranchSnapshot,
6
- GitCommitSnapshot,
7
- GitMetricsSnapshot,
8
- GitSnapshot,
9
- GitStateSnapshot,
10
- GitStatusSnapshot,
11
- GitWorktreeSnapshot,
5
+ GitBranchSnapshot,
6
+ GitCommitSnapshot,
7
+ GitMetricsSnapshot,
8
+ GitSnapshot,
9
+ GitStateSnapshot,
10
+ GitStatusSnapshot,
11
+ GitWorktreeSnapshot,
12
12
  } from "../types.js";
13
13
 
14
14
  const GIT_TIMEOUT_MS = 3_000;
15
15
 
16
16
  export interface ReadGitSnapshotOptions {
17
- includeMetrics: boolean;
18
- includeTag: boolean;
19
- signal?: AbortSignal;
17
+ includeMetrics: boolean;
18
+ includeTag: boolean;
19
+ signal?: AbortSignal;
20
20
  }
21
21
 
22
22
  export async function readGitSnapshot(
23
- pi: ExtensionAPI,
24
- cwd: string,
25
- options: ReadGitSnapshotOptions,
23
+ pi: ExtensionAPI,
24
+ cwd: string,
25
+ options: ReadGitSnapshotOptions,
26
26
  ): Promise<GitSnapshot | undefined> {
27
- const statusPromise = pi.exec(
28
- "git",
29
- [
30
- "--no-optional-locks",
31
- "status",
32
- "--porcelain=v2",
33
- "--branch",
34
- "--show-stash",
35
- "--untracked-files=normal",
36
- ],
37
- { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
38
- );
39
- const metadataPromise = pi.exec(
40
- "git",
41
- ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
42
- { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
43
- );
44
- const metricsPromise = options.includeMetrics
45
- ? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
46
- cwd,
47
- signal: options.signal,
48
- timeout: GIT_TIMEOUT_MS,
49
- })
50
- : Promise.resolve(undefined);
51
- const tagPromise = options.includeTag
52
- ? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
53
- cwd,
54
- signal: options.signal,
55
- timeout: GIT_TIMEOUT_MS,
56
- })
57
- : Promise.resolve(undefined);
58
-
59
- const [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([
60
- statusPromise,
61
- metadataPromise,
62
- metricsPromise,
63
- tagPromise,
64
- ]);
65
- if (statusResult.code !== 0 || statusResult.killed) return undefined;
66
-
67
- const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
68
- const metadata =
69
- metadataResult.code === 0 && !metadataResult.killed
70
- ? parseGitRepositoryMetadata(metadataResult.stdout)
71
- : undefined;
72
- const commit = withTag(parsed.commit, tagResult);
73
- const metrics =
74
- metricsResult && metricsResult.code === 0 && !metricsResult.killed
75
- ? parseGitDiffShortstat(metricsResult.stdout)
76
- : undefined;
77
-
78
- return {
79
- ...parsed,
80
- root: metadata?.root,
81
- commit,
82
- state: metadata ? parseGitState(metadata.gitDirectory) : undefined,
83
- metrics,
84
- worktree: metadata?.worktree,
85
- };
27
+ const statusPromise = pi.exec(
28
+ "git",
29
+ ["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
30
+ { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
31
+ );
32
+ const metadataPromise = pi.exec(
33
+ "git",
34
+ ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
35
+ { cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
36
+ );
37
+ const metricsPromise = options.includeMetrics
38
+ ? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
39
+ cwd,
40
+ signal: options.signal,
41
+ timeout: GIT_TIMEOUT_MS,
42
+ })
43
+ : Promise.resolve(undefined);
44
+ const tagPromise = options.includeTag
45
+ ? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
46
+ cwd,
47
+ signal: options.signal,
48
+ timeout: GIT_TIMEOUT_MS,
49
+ })
50
+ : Promise.resolve(undefined);
51
+
52
+ const [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([
53
+ statusPromise,
54
+ metadataPromise,
55
+ metricsPromise,
56
+ tagPromise,
57
+ ]);
58
+ if (statusResult.code !== 0 || statusResult.killed) return undefined;
59
+
60
+ const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
61
+ const metadata =
62
+ metadataResult.code === 0 && !metadataResult.killed ? parseGitRepositoryMetadata(metadataResult.stdout) : undefined;
63
+ const commit = withTag(parsed.commit, tagResult);
64
+ const metrics =
65
+ metricsResult && metricsResult.code === 0 && !metricsResult.killed
66
+ ? parseGitDiffShortstat(metricsResult.stdout)
67
+ : undefined;
68
+
69
+ return {
70
+ ...parsed,
71
+ root: metadata?.root,
72
+ commit,
73
+ state: metadata ? parseGitState(metadata.gitDirectory) : undefined,
74
+ metrics,
75
+ worktree: metadata?.worktree,
76
+ };
86
77
  }
87
78
 
88
- export async function readGitStatus(
89
- pi: ExtensionAPI,
90
- cwd: string,
91
- ): Promise<GitStatusSnapshot | undefined> {
92
- const result = await pi.exec(
93
- "git",
94
- [
95
- "--no-optional-locks",
96
- "status",
97
- "--porcelain=v2",
98
- "--branch",
99
- "--show-stash",
100
- "--untracked-files=normal",
101
- ],
102
- { cwd, timeout: GIT_TIMEOUT_MS },
103
- );
104
- if (result.code !== 0 || result.killed) return undefined;
105
- return parseGitStatusPorcelainV2(result.stdout).status;
79
+ export async function readGitStatus(pi: ExtensionAPI, cwd: string): Promise<GitStatusSnapshot | undefined> {
80
+ const result = await pi.exec(
81
+ "git",
82
+ ["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
83
+ { cwd, timeout: GIT_TIMEOUT_MS },
84
+ );
85
+ if (result.code !== 0 || result.killed) return undefined;
86
+ return parseGitStatusPorcelainV2(result.stdout).status;
106
87
  }
107
88
 
108
- export async function readGitWorktree(
109
- pi: ExtensionAPI,
110
- cwd: string,
111
- ): Promise<GitWorktreeSnapshot | undefined> {
112
- const result = await pi.exec(
113
- "git",
114
- ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
115
- { cwd, timeout: GIT_TIMEOUT_MS },
116
- );
117
- if (result.code !== 0 || result.killed) return undefined;
118
- return parseGitRepositoryMetadata(result.stdout)?.worktree;
89
+ export async function readGitWorktree(pi: ExtensionAPI, cwd: string): Promise<GitWorktreeSnapshot | undefined> {
90
+ const result = await pi.exec(
91
+ "git",
92
+ ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
93
+ { cwd, timeout: GIT_TIMEOUT_MS },
94
+ );
95
+ if (result.code !== 0 || result.killed) return undefined;
96
+ return parseGitRepositoryMetadata(result.stdout)?.worktree;
119
97
  }
120
98
 
121
99
  interface ParsedGitStatus {
122
- branch?: GitBranchSnapshot;
123
- commit?: GitCommitSnapshot;
124
- status: GitStatusSnapshot;
100
+ branch?: GitBranchSnapshot;
101
+ commit?: GitCommitSnapshot;
102
+ status: GitStatusSnapshot;
125
103
  }
126
104
 
127
105
  export function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {
128
- const status = emptyGitStatus();
129
- let branchName: string | undefined;
130
- let commitHash: string | undefined;
131
- let upstream: string | undefined;
132
-
133
- for (const line of output.split(/\r?\n/u)) {
134
- if (!line) continue;
135
- if (line.startsWith("# branch.oid ")) {
136
- const value = line.slice("# branch.oid ".length).trim();
137
- if (value && value !== "(initial)") commitHash = value;
138
- continue;
139
- }
140
- if (line.startsWith("# branch.head ")) {
141
- branchName = line.slice("# branch.head ".length).trim();
142
- continue;
143
- }
144
- if (line.startsWith("# branch.upstream ")) {
145
- upstream = line.slice("# branch.upstream ".length).trim();
146
- continue;
147
- }
148
- if (line.startsWith("# branch.ab ")) {
149
- const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(line);
150
- status.ahead = match?.[1] ? Number(match[1]) : 0;
151
- status.behind = match?.[2] ? Number(match[2]) : 0;
152
- continue;
153
- }
154
- if (line.startsWith("# stash ")) {
155
- const count = Number(line.slice("# stash ".length));
156
- status.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;
157
- continue;
158
- }
159
- addPorcelainV2Status(status, line);
160
- }
161
- finalizeStatus(status);
162
-
163
- const detached = branchName === "(detached)";
164
- const remote = splitUpstream(upstream);
165
- const branch = branchName
166
- ? {
167
- name: detached ? "HEAD" : branchName,
168
- ...remote,
169
- detached,
170
- }
171
- : undefined;
172
- const commit = commitHash ? { hash: commitHash, detached } : undefined;
173
- return { branch, commit, status };
106
+ const status = emptyGitStatus();
107
+ let branchName: string | undefined;
108
+ let commitHash: string | undefined;
109
+ let upstream: string | undefined;
110
+
111
+ for (const line of output.split(/\r?\n/u)) {
112
+ if (!line) continue;
113
+ if (line.startsWith("# branch.oid ")) {
114
+ const value = line.slice("# branch.oid ".length).trim();
115
+ if (value && value !== "(initial)") commitHash = value;
116
+ continue;
117
+ }
118
+ if (line.startsWith("# branch.head ")) {
119
+ branchName = line.slice("# branch.head ".length).trim();
120
+ continue;
121
+ }
122
+ if (line.startsWith("# branch.upstream ")) {
123
+ upstream = line.slice("# branch.upstream ".length).trim();
124
+ continue;
125
+ }
126
+ if (line.startsWith("# branch.ab ")) {
127
+ const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(line);
128
+ status.ahead = match?.[1] ? Number(match[1]) : 0;
129
+ status.behind = match?.[2] ? Number(match[2]) : 0;
130
+ continue;
131
+ }
132
+ if (line.startsWith("# stash ")) {
133
+ const count = Number(line.slice("# stash ".length));
134
+ status.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;
135
+ continue;
136
+ }
137
+ addPorcelainV2Status(status, line);
138
+ }
139
+ finalizeStatus(status);
140
+
141
+ const detached = branchName === "(detached)";
142
+ const remote = splitUpstream(upstream);
143
+ const branch = branchName
144
+ ? {
145
+ name: detached ? "HEAD" : branchName,
146
+ ...remote,
147
+ detached,
148
+ }
149
+ : undefined;
150
+ const commit = commitHash ? { hash: commitHash, detached } : undefined;
151
+ return { branch, commit, status };
174
152
  }
175
153
 
176
154
  export function parseGitStatusPorcelain(output: string): GitStatusSnapshot {
177
- const status = emptyGitStatus();
178
- for (const line of output.split(/\r?\n/u)) {
179
- if (!line) continue;
180
- if (line.startsWith("## ")) {
181
- const ahead = /\bahead (\d+)/u.exec(line);
182
- const behind = /\bbehind (\d+)/u.exec(line);
183
- status.ahead = ahead?.[1] ? Number(ahead[1]) : 0;
184
- status.behind = behind?.[1] ? Number(behind[1]) : 0;
185
- continue;
186
- }
187
- const indexStatus = line[0] ?? " ";
188
- const worktreeStatus = line[1] ?? " ";
189
- if (indexStatus === "?" && worktreeStatus === "?") {
190
- status.untracked += 1;
191
- continue;
192
- }
193
- if (isConflict(indexStatus, worktreeStatus)) {
194
- status.conflicted += 1;
195
- continue;
196
- }
197
- addNormalStatus(status, indexStatus, worktreeStatus);
198
- if (indexStatus === "R" || indexStatus === "C") status.renamed += 1;
199
- }
200
- finalizeStatus(status);
201
- return status;
155
+ const status = emptyGitStatus();
156
+ for (const line of output.split(/\r?\n/u)) {
157
+ if (!line) continue;
158
+ if (line.startsWith("## ")) {
159
+ const ahead = /\bahead (\d+)/u.exec(line);
160
+ const behind = /\bbehind (\d+)/u.exec(line);
161
+ status.ahead = ahead?.[1] ? Number(ahead[1]) : 0;
162
+ status.behind = behind?.[1] ? Number(behind[1]) : 0;
163
+ continue;
164
+ }
165
+ const indexStatus = line[0] ?? " ";
166
+ const worktreeStatus = line[1] ?? " ";
167
+ if (indexStatus === "?" && worktreeStatus === "?") {
168
+ status.untracked += 1;
169
+ continue;
170
+ }
171
+ if (isConflict(indexStatus, worktreeStatus)) {
172
+ status.conflicted += 1;
173
+ continue;
174
+ }
175
+ addNormalStatus(status, indexStatus, worktreeStatus);
176
+ if (indexStatus === "R" || indexStatus === "C") status.renamed += 1;
177
+ }
178
+ finalizeStatus(status);
179
+ return status;
202
180
  }
203
181
 
204
182
  export function parseGitDiffShortstat(output: string): GitMetricsSnapshot {
205
- return {
206
- added: parseShortstatMetric(output, "insertion(+)", "insertions(+)") ?? 0,
207
- deleted: parseShortstatMetric(output, "deletion(-)", "deletions(-)") ?? 0,
208
- };
183
+ return {
184
+ added: parseShortstatMetric(output, "insertion(+)", "insertions(+)") ?? 0,
185
+ deleted: parseShortstatMetric(output, "deletion(-)", "deletions(-)") ?? 0,
186
+ };
209
187
  }
210
188
 
211
- function parseShortstatMetric(
212
- output: string,
213
- singularLabel: string,
214
- pluralLabel: string,
215
- ): number | undefined {
216
- for (const field of output.split(",")) {
217
- const trimmed = field.trim();
218
- const separator = trimmed.indexOf(" ");
219
- if (separator <= 0) continue;
220
- const label = trimmed.slice(separator + 1).trimStart();
221
- if (label !== singularLabel && label !== pluralLabel) continue;
222
- const countText = trimmed.slice(0, separator);
223
- for (const character of countText) {
224
- if (character < "0" || character > "9") return undefined;
225
- }
226
- const count = Number(countText);
227
- return Number.isSafeInteger(count) ? count : undefined;
228
- }
229
- return undefined;
189
+ function parseShortstatMetric(output: string, singularLabel: string, pluralLabel: string): number | undefined {
190
+ for (const field of output.split(",")) {
191
+ const trimmed = field.trim();
192
+ const separator = trimmed.indexOf(" ");
193
+ if (separator <= 0) continue;
194
+ const label = trimmed.slice(separator + 1).trimStart();
195
+ if (label !== singularLabel && label !== pluralLabel) continue;
196
+ const countText = trimmed.slice(0, separator);
197
+ for (const character of countText) {
198
+ if (character < "0" || character > "9") return undefined;
199
+ }
200
+ const count = Number(countText);
201
+ return Number.isSafeInteger(count) ? count : undefined;
202
+ }
203
+ return undefined;
230
204
  }
231
205
 
232
206
  export function parseGitState(gitDirectory: string): GitStateSnapshot | undefined {
233
- const rebaseMerge = join(gitDirectory, "rebase-merge");
234
- if (existsSync(rebaseMerge))
235
- return operationWithProgress("REBASING", rebaseMerge, "msgnum", "end");
236
-
237
- const rebaseApply = join(gitDirectory, "rebase-apply");
238
- if (existsSync(rebaseApply)) {
239
- const state = existsSync(join(rebaseApply, "applying"))
240
- ? "AM"
241
- : existsSync(join(rebaseApply, "rebasing"))
242
- ? "REBASING"
243
- : "AM/REBASE";
244
- return operationWithProgress(state, rebaseApply, "next", "last");
245
- }
246
- if (existsSync(join(gitDirectory, "MERGE_HEAD"))) return { state: "MERGING" };
247
- if (existsSync(join(gitDirectory, "REVERT_HEAD"))) return { state: "REVERTING" };
248
- if (existsSync(join(gitDirectory, "CHERRY_PICK_HEAD"))) return { state: "CHERRY-PICKING" };
249
- if (existsSync(join(gitDirectory, "BISECT_LOG"))) return { state: "BISECTING" };
250
- return undefined;
207
+ const rebaseMerge = join(gitDirectory, "rebase-merge");
208
+ if (existsSync(rebaseMerge)) return operationWithProgress("REBASING", rebaseMerge, "msgnum", "end");
209
+
210
+ const rebaseApply = join(gitDirectory, "rebase-apply");
211
+ if (existsSync(rebaseApply)) {
212
+ const state = existsSync(join(rebaseApply, "applying"))
213
+ ? "AM"
214
+ : existsSync(join(rebaseApply, "rebasing"))
215
+ ? "REBASING"
216
+ : "AM/REBASE";
217
+ return operationWithProgress(state, rebaseApply, "next", "last");
218
+ }
219
+ if (existsSync(join(gitDirectory, "MERGE_HEAD"))) return { state: "MERGING" };
220
+ if (existsSync(join(gitDirectory, "REVERT_HEAD"))) return { state: "REVERTING" };
221
+ if (existsSync(join(gitDirectory, "CHERRY_PICK_HEAD"))) return { state: "CHERRY-PICKING" };
222
+ if (existsSync(join(gitDirectory, "BISECT_LOG"))) return { state: "BISECTING" };
223
+ return undefined;
251
224
  }
252
225
 
253
226
  interface GitRepositoryMetadata {
254
- root: string;
255
- gitDirectory: string;
256
- worktree?: GitWorktreeSnapshot;
227
+ root: string;
228
+ gitDirectory: string;
229
+ worktree?: GitWorktreeSnapshot;
257
230
  }
258
231
 
259
232
  function parseGitRepositoryMetadata(output: string): GitRepositoryMetadata | undefined {
260
- const lines = output.trimEnd().split(/\r?\n/u);
261
- if (lines.length !== 3) return undefined;
262
- const [path, commonDir, gitDirectory] = lines;
263
- if (!path || !commonDir || !gitDirectory) return undefined;
264
- if (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;
265
- return {
266
- root: path,
267
- gitDirectory,
268
- worktree: samePath(commonDir, gitDirectory)
269
- ? undefined
270
- : { name: basename(path) || path, path },
271
- };
233
+ const lines = output.trimEnd().split(/\r?\n/u);
234
+ if (lines.length !== 3) return undefined;
235
+ const [path, commonDir, gitDirectory] = lines;
236
+ if (!path || !commonDir || !gitDirectory) return undefined;
237
+ if (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;
238
+ return {
239
+ root: path,
240
+ gitDirectory,
241
+ worktree: samePath(commonDir, gitDirectory) ? undefined : { name: basename(path) || path, path },
242
+ };
272
243
  }
273
244
 
274
245
  export function parseGitWorktree(output: string): GitWorktreeSnapshot | undefined {
275
- return parseGitRepositoryMetadata(output)?.worktree;
246
+ return parseGitRepositoryMetadata(output)?.worktree;
276
247
  }
277
248
 
278
249
  function addPorcelainV2Status(status: GitStatusSnapshot, line: string) {
279
- const kind = line[0];
280
- if (kind === "?") {
281
- status.untracked += 1;
282
- return;
283
- }
284
- if (kind === "u") {
285
- status.conflicted += 1;
286
- return;
287
- }
288
- if (kind !== "1" && kind !== "2") return;
289
- const indexStatus = line[2] ?? ".";
290
- const worktreeStatus = line[3] ?? ".";
291
- addNormalStatus(status, indexStatus, worktreeStatus);
292
- if (kind === "2") status.renamed += 1;
250
+ const kind = line[0];
251
+ if (kind === "?") {
252
+ status.untracked += 1;
253
+ return;
254
+ }
255
+ if (kind === "u") {
256
+ status.conflicted += 1;
257
+ return;
258
+ }
259
+ if (kind !== "1" && kind !== "2") return;
260
+ const indexStatus = line[2] ?? ".";
261
+ const worktreeStatus = line[3] ?? ".";
262
+ addNormalStatus(status, indexStatus, worktreeStatus);
263
+ if (kind === "2") status.renamed += 1;
293
264
  }
294
265
 
295
266
  function addNormalStatus(status: GitStatusSnapshot, indexStatus: string, worktreeStatus: string) {
296
- if (indexStatus === "A") status.indexAdded += 1;
297
- if (indexStatus === "D") status.indexDeleted += 1;
298
- if (indexStatus === "M") status.indexModified += 1;
299
- if (indexStatus === "T") status.indexTypechanged += 1;
300
- if (worktreeStatus === "A") status.worktreeAdded += 1;
301
- if (worktreeStatus === "D") status.worktreeDeleted += 1;
302
- if (worktreeStatus === "M") status.worktreeModified += 1;
303
- if (worktreeStatus === "T") status.worktreeTypechanged += 1;
267
+ if (indexStatus === "A") status.indexAdded += 1;
268
+ if (indexStatus === "D") status.indexDeleted += 1;
269
+ if (indexStatus === "M") status.indexModified += 1;
270
+ if (indexStatus === "T") status.indexTypechanged += 1;
271
+ if (worktreeStatus === "A") status.worktreeAdded += 1;
272
+ if (worktreeStatus === "D") status.worktreeDeleted += 1;
273
+ if (worktreeStatus === "M") status.worktreeModified += 1;
274
+ if (worktreeStatus === "T") status.worktreeTypechanged += 1;
304
275
  }
305
276
 
306
277
  function finalizeStatus(status: GitStatusSnapshot) {
307
- status.deleted = status.worktreeDeleted + status.indexDeleted;
308
- status.modified = status.worktreeModified + status.worktreeAdded;
309
- status.staged = status.indexModified + status.indexAdded + status.indexTypechanged;
310
- status.typechanged = status.worktreeTypechanged;
278
+ status.deleted = status.worktreeDeleted + status.indexDeleted;
279
+ status.modified = status.worktreeModified + status.worktreeAdded;
280
+ status.staged = status.indexModified + status.indexAdded + status.indexTypechanged;
281
+ status.typechanged = status.worktreeTypechanged;
311
282
  }
312
283
 
313
284
  function emptyGitStatus(): GitStatusSnapshot {
314
- return {
315
- ahead: 0,
316
- behind: 0,
317
- stashed: 0,
318
- conflicted: 0,
319
- deleted: 0,
320
- renamed: 0,
321
- modified: 0,
322
- staged: 0,
323
- typechanged: 0,
324
- untracked: 0,
325
- worktreeAdded: 0,
326
- worktreeDeleted: 0,
327
- worktreeModified: 0,
328
- worktreeTypechanged: 0,
329
- indexAdded: 0,
330
- indexDeleted: 0,
331
- indexModified: 0,
332
- indexTypechanged: 0,
333
- };
285
+ return {
286
+ ahead: 0,
287
+ behind: 0,
288
+ stashed: 0,
289
+ conflicted: 0,
290
+ deleted: 0,
291
+ renamed: 0,
292
+ modified: 0,
293
+ staged: 0,
294
+ typechanged: 0,
295
+ untracked: 0,
296
+ worktreeAdded: 0,
297
+ worktreeDeleted: 0,
298
+ worktreeModified: 0,
299
+ worktreeTypechanged: 0,
300
+ indexAdded: 0,
301
+ indexDeleted: 0,
302
+ indexModified: 0,
303
+ indexTypechanged: 0,
304
+ };
334
305
  }
335
306
 
336
307
  function splitUpstream(upstream: string | undefined): {
337
- remoteName?: string;
338
- remoteBranch?: string;
308
+ remoteName?: string;
309
+ remoteBranch?: string;
339
310
  } {
340
- if (!upstream) return {};
341
- const separator = upstream.indexOf("/");
342
- if (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };
343
- return {
344
- remoteName: upstream.slice(0, separator),
345
- remoteBranch: upstream.slice(separator + 1),
346
- };
311
+ if (!upstream) return {};
312
+ const separator = upstream.indexOf("/");
313
+ if (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };
314
+ return {
315
+ remoteName: upstream.slice(0, separator),
316
+ remoteBranch: upstream.slice(separator + 1),
317
+ };
347
318
  }
348
319
 
349
320
  function withTag(
350
- commit: GitCommitSnapshot | undefined,
351
- result:
352
- | {
353
- stdout: string;
354
- code: number;
355
- killed: boolean;
356
- }
357
- | undefined,
321
+ commit: GitCommitSnapshot | undefined,
322
+ result:
323
+ | {
324
+ stdout: string;
325
+ code: number;
326
+ killed: boolean;
327
+ }
328
+ | undefined,
358
329
  ): GitCommitSnapshot | undefined {
359
- if (!commit || !result || result.code !== 0 || result.killed) return commit;
360
- const tag = result.stdout.trim();
361
- return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
330
+ if (!commit || !result || result.code !== 0 || result.killed) return commit;
331
+ const tag = result.stdout.trim();
332
+ return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
362
333
  }
363
334
 
364
335
  function operationWithProgress(
365
- state: string,
366
- directory: string,
367
- currentName: string,
368
- totalName: string,
336
+ state: string,
337
+ directory: string,
338
+ currentName: string,
339
+ totalName: string,
369
340
  ): GitStateSnapshot {
370
- const progressCurrent = readPositiveInteger(join(directory, currentName));
371
- const progressTotal = readPositiveInteger(join(directory, totalName));
372
- return progressCurrent !== undefined && progressTotal !== undefined
373
- ? { state, progressCurrent, progressTotal }
374
- : { state };
341
+ const progressCurrent = readPositiveInteger(join(directory, currentName));
342
+ const progressTotal = readPositiveInteger(join(directory, totalName));
343
+ return progressCurrent !== undefined && progressTotal !== undefined
344
+ ? { state, progressCurrent, progressTotal }
345
+ : { state };
375
346
  }
376
347
 
377
348
  function readPositiveInteger(path: string): number | undefined {
378
- try {
379
- const value = Number(readFileSync(path, "utf8").trim());
380
- return Number.isSafeInteger(value) && value > 0 ? value : undefined;
381
- } catch {
382
- return undefined;
383
- }
349
+ try {
350
+ const value = Number(readFileSync(path, "utf8").trim());
351
+ return Number.isSafeInteger(value) && value > 0 ? value : undefined;
352
+ } catch {
353
+ return undefined;
354
+ }
384
355
  }
385
356
 
386
357
  function samePath(left: string, right: string): boolean {
387
- const normalizedLeft = resolve(left);
388
- const normalizedRight = resolve(right);
389
- return process.platform === "win32"
390
- ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()
391
- : normalizedLeft === normalizedRight;
358
+ const normalizedLeft = resolve(left);
359
+ const normalizedRight = resolve(right);
360
+ return process.platform === "win32"
361
+ ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()
362
+ : normalizedLeft === normalizedRight;
392
363
  }
393
364
 
394
365
  function isConflict(indexStatus: string, worktreeStatus: string): boolean {
395
- return (
396
- (indexStatus === "D" && worktreeStatus === "D") ||
397
- (indexStatus === "A" && worktreeStatus === "A") ||
398
- indexStatus === "U" ||
399
- worktreeStatus === "U"
400
- );
366
+ return (
367
+ (indexStatus === "D" && worktreeStatus === "D") ||
368
+ (indexStatus === "A" && worktreeStatus === "A") ||
369
+ indexStatus === "U" ||
370
+ worktreeStatus === "U"
371
+ );
401
372
  }
402
373
 
403
- export function gitStatusEqual(
404
- left: GitStatusSnapshot | undefined,
405
- right: GitStatusSnapshot | undefined,
406
- ): boolean {
407
- return JSON.stringify(left) === JSON.stringify(right);
374
+ export function gitStatusEqual(left: GitStatusSnapshot | undefined, right: GitStatusSnapshot | undefined): boolean {
375
+ return JSON.stringify(left) === JSON.stringify(right);
408
376
  }
409
377
 
410
- export function gitSnapshotEqual(
411
- left: GitSnapshot | undefined,
412
- right: GitSnapshot | undefined,
413
- ): boolean {
414
- return JSON.stringify(left) === JSON.stringify(right);
378
+ export function gitSnapshotEqual(left: GitSnapshot | undefined, right: GitSnapshot | undefined): boolean {
379
+ return JSON.stringify(left) === JSON.stringify(right);
415
380
  }