@narumitw/pi-worktree 0.51.7 → 0.51.9

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/src/status.ts CHANGED
@@ -3,382 +3,369 @@ import type { ExecResult, ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
3
  import { pathsEqual, stripTerminalControls, type WorktreeRecord } from "./git.js";
4
4
 
5
5
  const GIT_STATUS_TIMEOUT_MS = 15_000;
6
+ // Status can contain every repository path; the last-commit query returns only a date and subject.
7
+ const GIT_STATUS_MAX_BUFFER = 8 * 1024 * 1024;
8
+ const GIT_LAST_COMMIT_MAX_BUFFER = 64 * 1024;
6
9
  const DEFAULT_STATUS_CONCURRENCY = 4;
7
10
  const OID_PATTERN = /^[0-9a-fA-F]{40,64}$/u;
8
11
  const STATUS_XY_PATTERN = /^[.MADRCUT]{2}$/u;
9
12
 
10
13
  export interface WorktreeStatusSnapshot {
11
- headOid?: string;
12
- branch?: string;
13
- detached: boolean;
14
- upstream?: string;
15
- ahead?: number;
16
- behind?: number;
17
- staged: number;
18
- unstaged: number;
19
- untracked: number;
20
- conflicts: number;
14
+ headOid?: string;
15
+ branch?: string;
16
+ detached: boolean;
17
+ upstream?: string;
18
+ ahead?: number;
19
+ behind?: number;
20
+ staged: number;
21
+ unstaged: number;
22
+ untracked: number;
23
+ conflicts: number;
21
24
  }
22
25
 
23
26
  export interface LastCommitSummary {
24
- committedAt: string;
25
- subject: string;
27
+ committedAt: string;
28
+ subject: string;
26
29
  }
27
30
 
28
31
  export type WorktreeStatusResult =
29
- | {
30
- kind: "available";
31
- snapshot: WorktreeStatusSnapshot;
32
- lastCommit?: LastCommitSummary;
33
- }
34
- | { kind: "unavailable"; reason: string };
32
+ | {
33
+ kind: "available";
34
+ snapshot: WorktreeStatusSnapshot;
35
+ lastCommit?: LastCommitSummary;
36
+ }
37
+ | { kind: "unavailable"; reason: string };
35
38
 
36
39
  export interface WorktreeStatusCard {
37
- id: string;
38
- label: string;
39
- description: string;
40
- statusText: string;
41
- searchText: string;
42
- details: string[];
40
+ id: string;
41
+ label: string;
42
+ description: string;
43
+ statusText: string;
44
+ searchText: string;
45
+ details: string[];
43
46
  }
44
47
 
45
48
  interface LoadStatusOptions {
46
- concurrency?: number;
49
+ concurrency?: number;
47
50
  }
48
51
 
49
52
  export function parseWorktreeStatusPorcelain(output: string): WorktreeStatusSnapshot {
50
- if (output && !output.endsWith("\0")) {
51
- throw new Error("Git status porcelain output is not NUL-terminated.");
52
- }
53
- const entries = output ? output.slice(0, -1).split("\0") : [];
54
- const snapshot: WorktreeStatusSnapshot = {
55
- detached: false,
56
- staged: 0,
57
- unstaged: 0,
58
- untracked: 0,
59
- conflicts: 0,
60
- };
53
+ if (output && !output.endsWith("\0")) {
54
+ throw new Error("Git status porcelain output is not NUL-terminated.");
55
+ }
56
+ const entries = output ? output.slice(0, -1).split("\0") : [];
57
+ const snapshot: WorktreeStatusSnapshot = {
58
+ detached: false,
59
+ staged: 0,
60
+ unstaged: 0,
61
+ untracked: 0,
62
+ conflicts: 0,
63
+ };
61
64
 
62
- for (let index = 0; index < entries.length; index += 1) {
63
- const entry = entries[index] ?? "";
64
- if (entry.startsWith("# ")) {
65
- parseBranchHeader(snapshot, entry);
66
- continue;
67
- }
68
- if (entry.startsWith("1 ")) {
69
- assertFieldCount(entry, 9, "ordinary");
70
- countTrackedState(snapshot, statusCode(entry));
71
- continue;
72
- }
73
- if (entry.startsWith("2 ")) {
74
- assertFieldCount(entry, 10, "renamed");
75
- countTrackedState(snapshot, statusCode(entry));
76
- const originalPath = entries[index + 1];
77
- if (!originalPath) throw new Error("Git status returned a malformed renamed record.");
78
- index += 1;
79
- continue;
80
- }
81
- if (entry.startsWith("u ")) {
82
- assertFieldCount(entry, 11, "unmerged");
83
- statusCode(entry);
84
- snapshot.conflicts += 1;
85
- continue;
86
- }
87
- if (entry.startsWith("? ")) {
88
- if (entry.length === 2) throw new Error("Git status returned a malformed untracked record.");
89
- snapshot.untracked += 1;
90
- continue;
91
- }
92
- if (entry.startsWith("! ")) continue;
93
- throw new Error("Git status returned an unknown porcelain-v2 record.");
94
- }
95
- return snapshot;
65
+ for (let index = 0; index < entries.length; index += 1) {
66
+ const entry = entries[index] ?? "";
67
+ if (entry.startsWith("# ")) {
68
+ parseBranchHeader(snapshot, entry);
69
+ continue;
70
+ }
71
+ if (entry.startsWith("1 ")) {
72
+ assertFieldCount(entry, 9, "ordinary");
73
+ countTrackedState(snapshot, statusCode(entry));
74
+ continue;
75
+ }
76
+ if (entry.startsWith("2 ")) {
77
+ assertFieldCount(entry, 10, "renamed");
78
+ countTrackedState(snapshot, statusCode(entry));
79
+ const originalPath = entries[index + 1];
80
+ if (!originalPath) throw new Error("Git status returned a malformed renamed record.");
81
+ index += 1;
82
+ continue;
83
+ }
84
+ if (entry.startsWith("u ")) {
85
+ assertFieldCount(entry, 11, "unmerged");
86
+ statusCode(entry);
87
+ snapshot.conflicts += 1;
88
+ continue;
89
+ }
90
+ if (entry.startsWith("? ")) {
91
+ if (entry.length === 2) throw new Error("Git status returned a malformed untracked record.");
92
+ snapshot.untracked += 1;
93
+ continue;
94
+ }
95
+ if (entry.startsWith("! ")) continue;
96
+ throw new Error("Git status returned an unknown porcelain-v2 record.");
97
+ }
98
+ return snapshot;
96
99
  }
97
100
 
98
101
  export function formatWorktreeStatusCard(
99
- record: WorktreeRecord,
100
- currentPath: string,
101
- result: WorktreeStatusResult,
102
+ record: WorktreeRecord,
103
+ currentPath: string,
104
+ result: WorktreeStatusResult,
102
105
  ): WorktreeStatusCard {
103
- const path = safeDisplay(record.path);
104
- const identity = [
105
- pathsEqual(record.path, currentPath) ? "current" : undefined,
106
- record.isMain ? "main" : undefined,
107
- record.bare ? "bare" : undefined,
108
- record.detached ? "detached" : undefined,
109
- ].filter((value): value is string => value !== undefined);
110
- const label = safeDisplay(
111
- record.branch ??
112
- (record.detached
113
- ? `Detached ${record.head?.slice(0, 8) ?? "HEAD"}`
114
- : record.bare
115
- ? "Bare worktree"
116
- : "Unknown worktree"),
117
- );
118
- const statePrefix = identity.length > 0 ? `${identity.join(" · ")} · ` : "";
119
- const baseDetails = [
120
- `Path: ${path}`,
121
- `Identity: ${identity.join(" · ") || "linked"}`,
122
- `Registered HEAD: ${safeDisplay(record.head ?? "unavailable")}`,
123
- ];
124
- if (record.lockedReason !== undefined) {
125
- baseDetails.push(
126
- record.lockedReason
127
- ? `Locked: ${safeDisplay(record.lockedReason)}`
128
- : "Locked: no reason provided",
129
- );
130
- }
131
- if (record.prunableReason !== undefined) {
132
- baseDetails.push(
133
- record.prunableReason
134
- ? `Prunable: ${safeDisplay(record.prunableReason)}`
135
- : "Prunable: no reason provided",
136
- );
137
- }
106
+ const path = safeDisplay(record.path);
107
+ const identity = [
108
+ pathsEqual(record.path, currentPath) ? "current" : undefined,
109
+ record.isMain ? "main" : undefined,
110
+ record.bare ? "bare" : undefined,
111
+ record.detached ? "detached" : undefined,
112
+ ].filter((value): value is string => value !== undefined);
113
+ const label = safeDisplay(
114
+ record.branch ??
115
+ (record.detached
116
+ ? `Detached ${record.head?.slice(0, 8) ?? "HEAD"}`
117
+ : record.bare
118
+ ? "Bare worktree"
119
+ : "Unknown worktree"),
120
+ );
121
+ const statePrefix = identity.length > 0 ? `${identity.join(" · ")} · ` : "";
122
+ const baseDetails = [
123
+ `Path: ${path}`,
124
+ `Identity: ${identity.join(" · ") || "linked"}`,
125
+ `Registered HEAD: ${safeDisplay(record.head ?? "unavailable")}`,
126
+ ];
127
+ if (record.lockedReason !== undefined) {
128
+ baseDetails.push(
129
+ record.lockedReason ? `Locked: ${safeDisplay(record.lockedReason)}` : "Locked: no reason provided",
130
+ );
131
+ }
132
+ if (record.prunableReason !== undefined) {
133
+ baseDetails.push(
134
+ record.prunableReason ? `Prunable: ${safeDisplay(record.prunableReason)}` : "Prunable: no reason provided",
135
+ );
136
+ }
138
137
 
139
- if (result.kind === "unavailable") {
140
- const reason = safeDisplay(result.reason);
141
- return {
142
- id: record.path,
143
- label,
144
- description: path,
145
- statusText: `${statePrefix}unavailable`,
146
- searchText: `${label} ${path} ${identity.join(" ")} unavailable ${reason}`,
147
- details: [
148
- ...baseDetails,
149
- `Status: ${reason}`,
150
- "Snapshot: local Git state; no fetch performed.",
151
- ],
152
- };
153
- }
138
+ if (result.kind === "unavailable") {
139
+ const reason = safeDisplay(result.reason);
140
+ return {
141
+ id: record.path,
142
+ label,
143
+ description: path,
144
+ statusText: `${statePrefix}unavailable`,
145
+ searchText: `${label} ${path} ${identity.join(" ")} unavailable ${reason}`,
146
+ details: [...baseDetails, `Status: ${reason}`, "Snapshot: local Git state; no fetch performed."],
147
+ };
148
+ }
154
149
 
155
- const { snapshot, lastCommit } = result;
156
- const workingState = formatWorkingState(snapshot);
157
- const upstream = snapshot.upstream
158
- ? snapshot.ahead !== undefined && snapshot.behind !== undefined
159
- ? `${safeDisplay(snapshot.upstream)} · ahead ${snapshot.ahead} · behind ${snapshot.behind}`
160
- : `${safeDisplay(snapshot.upstream)} · ahead/behind unavailable`
161
- : "not configured; ahead/behind unavailable";
162
- const details = [
163
- ...baseDetails,
164
- `Snapshot HEAD: ${safeDisplay(snapshot.headOid ?? "unborn")}`,
165
- `Working tree: ${workingState}`,
166
- `Upstream: ${upstream}`,
167
- lastCommit
168
- ? `Last commit: ${safeDisplay(lastCommit.committedAt)} · ${safeDisplay(lastCommit.subject || "(no subject)")}`
169
- : "Last commit: unavailable",
170
- "Snapshot: local Git state; no fetch performed; removal uses stricter checks.",
171
- ];
172
- return {
173
- id: record.path,
174
- label,
175
- description: path,
176
- statusText: `${statePrefix}${workingState}`,
177
- searchText: `${label} ${path} ${identity.join(" ")} ${workingState} ${safeDisplay(snapshot.upstream ?? "")}`,
178
- details,
179
- };
150
+ const { snapshot, lastCommit } = result;
151
+ const workingState = formatWorkingState(snapshot);
152
+ const upstream = snapshot.upstream
153
+ ? snapshot.ahead !== undefined && snapshot.behind !== undefined
154
+ ? `${safeDisplay(snapshot.upstream)} · ahead ${snapshot.ahead} · behind ${snapshot.behind}`
155
+ : `${safeDisplay(snapshot.upstream)} · ahead/behind unavailable`
156
+ : "not configured; ahead/behind unavailable";
157
+ const details = [
158
+ ...baseDetails,
159
+ `Snapshot HEAD: ${safeDisplay(snapshot.headOid ?? "unborn")}`,
160
+ `Working tree: ${workingState}`,
161
+ `Upstream: ${upstream}`,
162
+ lastCommit
163
+ ? `Last commit: ${safeDisplay(lastCommit.committedAt)} · ${safeDisplay(lastCommit.subject || "(no subject)")}`
164
+ : "Last commit: unavailable",
165
+ "Snapshot: local Git state; no fetch performed; removal uses stricter checks.",
166
+ ];
167
+ return {
168
+ id: record.path,
169
+ label,
170
+ description: path,
171
+ statusText: `${statePrefix}${workingState}`,
172
+ searchText: `${label} ${path} ${identity.join(" ")} ${workingState} ${safeDisplay(snapshot.upstream ?? "")}`,
173
+ details,
174
+ };
180
175
  }
181
176
 
182
177
  export async function loadWorktreeStatusCards(
183
- pi: Pick<ExtensionAPI, "exec">,
184
- records: readonly WorktreeRecord[],
185
- currentPath: string,
186
- signal?: AbortSignal,
187
- options: LoadStatusOptions = {},
178
+ pi: Pick<ExtensionAPI, "exec">,
179
+ records: readonly WorktreeRecord[],
180
+ currentPath: string,
181
+ signal?: AbortSignal,
182
+ options: LoadStatusOptions = {},
188
183
  ): Promise<WorktreeStatusCard[]> {
189
- const concurrency = Math.max(
190
- 1,
191
- Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1),
192
- );
193
- const cards = new Array<WorktreeStatusCard>(records.length);
194
- let nextIndex = 0;
184
+ const concurrency = Math.max(1, Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1));
185
+ const cards = new Array<WorktreeStatusCard>(records.length);
186
+ let nextIndex = 0;
195
187
 
196
- const worker = async () => {
197
- while (true) {
198
- throwIfAborted(signal);
199
- const index = nextIndex;
200
- if (index >= records.length) return;
201
- nextIndex += 1;
202
- const record = records[index];
203
- if (!record) return;
204
- const unavailable = unavailableReason(record);
205
- if (unavailable) {
206
- cards[index] = formatWorktreeStatusCard(record, currentPath, {
207
- kind: "unavailable",
208
- reason: unavailable,
209
- });
210
- continue;
211
- }
212
- try {
213
- const status = await runGit(
214
- pi,
215
- [
216
- "status",
217
- "--porcelain=v2",
218
- "--branch",
219
- "-z",
220
- "--untracked-files=all",
221
- "--ignore-submodules=none",
222
- ],
223
- record.path,
224
- signal,
225
- );
226
- const snapshot = parseWorktreeStatusPorcelain(status.stdout);
227
- const lastCommit = snapshot.headOid
228
- ? parseLastCommit(
229
- (
230
- await runGit(
231
- pi,
232
- ["show", "-s", "--format=%aI%x00%s", "--end-of-options", snapshot.headOid],
233
- record.path,
234
- signal,
235
- )
236
- ).stdout,
237
- )
238
- : undefined;
239
- cards[index] = formatWorktreeStatusCard(record, currentPath, {
240
- kind: "available",
241
- snapshot,
242
- lastCommit,
243
- });
244
- } catch (error) {
245
- throwIfAborted(signal);
246
- cards[index] = formatWorktreeStatusCard(record, currentPath, {
247
- kind: "unavailable",
248
- reason: `Status failed: ${formatError(error)}`,
249
- });
250
- }
251
- }
252
- };
188
+ const worker = async () => {
189
+ while (true) {
190
+ throwIfAborted(signal);
191
+ const index = nextIndex;
192
+ if (index >= records.length) return;
193
+ nextIndex += 1;
194
+ const record = records[index];
195
+ if (!record) return;
196
+ const unavailable = unavailableReason(record);
197
+ if (unavailable) {
198
+ cards[index] = formatWorktreeStatusCard(record, currentPath, {
199
+ kind: "unavailable",
200
+ reason: unavailable,
201
+ });
202
+ continue;
203
+ }
204
+ try {
205
+ const status = await runGit(
206
+ pi,
207
+ ["status", "--porcelain=v2", "--branch", "-z", "--untracked-files=all", "--ignore-submodules=none"],
208
+ record.path,
209
+ GIT_STATUS_MAX_BUFFER,
210
+ signal,
211
+ );
212
+ const snapshot = parseWorktreeStatusPorcelain(status.stdout);
213
+ const lastCommit = snapshot.headOid
214
+ ? parseLastCommit(
215
+ (
216
+ await runGit(
217
+ pi,
218
+ ["show", "-s", "--format=%aI%x00%s", "--end-of-options", snapshot.headOid],
219
+ record.path,
220
+ GIT_LAST_COMMIT_MAX_BUFFER,
221
+ signal,
222
+ )
223
+ ).stdout,
224
+ )
225
+ : undefined;
226
+ cards[index] = formatWorktreeStatusCard(record, currentPath, {
227
+ kind: "available",
228
+ snapshot,
229
+ lastCommit,
230
+ });
231
+ } catch (error) {
232
+ throwIfAborted(signal);
233
+ cards[index] = formatWorktreeStatusCard(record, currentPath, {
234
+ kind: "unavailable",
235
+ reason: `Status failed: ${formatError(error)}`,
236
+ });
237
+ }
238
+ }
239
+ };
253
240
 
254
- await Promise.all(Array.from({ length: concurrency }, worker));
255
- throwIfAborted(signal);
256
- return cards;
241
+ await Promise.all(Array.from({ length: concurrency }, worker));
242
+ throwIfAborted(signal);
243
+ return cards;
257
244
  }
258
245
 
259
246
  function parseBranchHeader(snapshot: WorktreeStatusSnapshot, entry: string): void {
260
- if (entry.startsWith("# branch.oid ")) {
261
- const oid = entry.slice("# branch.oid ".length);
262
- if (oid === "(initial)") {
263
- snapshot.headOid = undefined;
264
- return;
265
- }
266
- if (!OID_PATTERN.test(oid)) throw new Error("Git status returned a malformed branch OID.");
267
- snapshot.headOid = oid;
268
- return;
269
- }
270
- if (entry.startsWith("# branch.head ")) {
271
- const branch = entry.slice("# branch.head ".length);
272
- if (!branch) throw new Error("Git status returned a malformed branch head.");
273
- snapshot.detached = branch === "(detached)";
274
- snapshot.branch = snapshot.detached || branch === "(unknown)" ? undefined : branch;
275
- return;
276
- }
277
- if (entry.startsWith("# branch.upstream ")) {
278
- const upstream = entry.slice("# branch.upstream ".length);
279
- if (!upstream) throw new Error("Git status returned a malformed upstream.");
280
- snapshot.upstream = upstream;
281
- return;
282
- }
283
- if (entry.startsWith("# branch.ab ")) {
284
- const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(entry);
285
- if (!match?.[1] || !match[2]) {
286
- throw new Error("Git status returned malformed ahead/behind counts.");
287
- }
288
- snapshot.ahead = Number.parseInt(match[1], 10);
289
- snapshot.behind = Number.parseInt(match[2], 10);
290
- }
247
+ if (entry.startsWith("# branch.oid ")) {
248
+ const oid = entry.slice("# branch.oid ".length);
249
+ if (oid === "(initial)") {
250
+ snapshot.headOid = undefined;
251
+ return;
252
+ }
253
+ if (!OID_PATTERN.test(oid)) throw new Error("Git status returned a malformed branch OID.");
254
+ snapshot.headOid = oid;
255
+ return;
256
+ }
257
+ if (entry.startsWith("# branch.head ")) {
258
+ const branch = entry.slice("# branch.head ".length);
259
+ if (!branch) throw new Error("Git status returned a malformed branch head.");
260
+ snapshot.detached = branch === "(detached)";
261
+ snapshot.branch = snapshot.detached || branch === "(unknown)" ? undefined : branch;
262
+ return;
263
+ }
264
+ if (entry.startsWith("# branch.upstream ")) {
265
+ const upstream = entry.slice("# branch.upstream ".length);
266
+ if (!upstream) throw new Error("Git status returned a malformed upstream.");
267
+ snapshot.upstream = upstream;
268
+ return;
269
+ }
270
+ if (entry.startsWith("# branch.ab ")) {
271
+ const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(entry);
272
+ if (!match?.[1] || !match[2]) {
273
+ throw new Error("Git status returned malformed ahead/behind counts.");
274
+ }
275
+ snapshot.ahead = Number.parseInt(match[1], 10);
276
+ snapshot.behind = Number.parseInt(match[2], 10);
277
+ }
291
278
  }
292
279
 
293
280
  function statusCode(entry: string): string {
294
- const code = entry.slice(2, 4);
295
- if (!STATUS_XY_PATTERN.test(code)) {
296
- throw new Error("Git status returned a malformed tracked status code.");
297
- }
298
- return code;
281
+ const code = entry.slice(2, 4);
282
+ if (!STATUS_XY_PATTERN.test(code)) {
283
+ throw new Error("Git status returned a malformed tracked status code.");
284
+ }
285
+ return code;
299
286
  }
300
287
 
301
288
  function countTrackedState(snapshot: WorktreeStatusSnapshot, code: string): void {
302
- if (code[0] !== ".") snapshot.staged += 1;
303
- if (code[1] !== ".") snapshot.unstaged += 1;
289
+ if (code[0] !== ".") snapshot.staged += 1;
290
+ if (code[1] !== ".") snapshot.unstaged += 1;
304
291
  }
305
292
 
306
293
  function assertFieldCount(entry: string, minimum: number, kind: string): void {
307
- if (entry.split(" ").length < minimum) {
308
- throw new Error(`Git status returned a malformed ${kind} record.`);
309
- }
294
+ if (entry.split(" ").length < minimum) {
295
+ throw new Error(`Git status returned a malformed ${kind} record.`);
296
+ }
310
297
  }
311
298
 
312
299
  function formatWorkingState(snapshot: WorktreeStatusSnapshot): string {
313
- const values = [
314
- snapshot.conflicts > 0
315
- ? `${snapshot.conflicts} conflict${snapshot.conflicts === 1 ? "" : "s"}`
316
- : undefined,
317
- snapshot.staged > 0 ? `${snapshot.staged} staged` : undefined,
318
- snapshot.unstaged > 0 ? `${snapshot.unstaged} unstaged` : undefined,
319
- snapshot.untracked > 0 ? `${snapshot.untracked} untracked` : undefined,
320
- ].filter((value): value is string => value !== undefined);
321
- return values.join(" · ") || "clean";
300
+ const values = [
301
+ snapshot.conflicts > 0 ? `${snapshot.conflicts} conflict${snapshot.conflicts === 1 ? "" : "s"}` : undefined,
302
+ snapshot.staged > 0 ? `${snapshot.staged} staged` : undefined,
303
+ snapshot.unstaged > 0 ? `${snapshot.unstaged} unstaged` : undefined,
304
+ snapshot.untracked > 0 ? `${snapshot.untracked} untracked` : undefined,
305
+ ].filter((value): value is string => value !== undefined);
306
+ return values.join(" · ") || "clean";
322
307
  }
323
308
 
324
309
  function unavailableReason(record: WorktreeRecord): string | undefined {
325
- if (record.bare) return "Bare worktree cannot be inspected";
326
- if (record.prunableReason !== undefined) {
327
- return record.prunableReason
328
- ? `Prunable: ${record.prunableReason}`
329
- : "Prunable worktree metadata";
330
- }
331
- if (!existsSync(record.path)) return "Worktree path is missing";
332
- return undefined;
310
+ if (record.bare) return "Bare worktree cannot be inspected";
311
+ if (record.prunableReason !== undefined) {
312
+ return record.prunableReason ? `Prunable: ${record.prunableReason}` : "Prunable worktree metadata";
313
+ }
314
+ if (!existsSync(record.path)) return "Worktree path is missing";
315
+ return undefined;
333
316
  }
334
317
 
335
318
  async function runGit(
336
- pi: Pick<ExtensionAPI, "exec">,
337
- args: string[],
338
- cwd: string,
339
- signal?: AbortSignal,
319
+ pi: Pick<ExtensionAPI, "exec">,
320
+ args: string[],
321
+ cwd: string,
322
+ maxBuffer: number,
323
+ signal?: AbortSignal,
340
324
  ): Promise<ExecResult> {
341
- throwIfAborted(signal);
342
- const result = await pi.exec("git", args, { cwd, signal, timeout: GIT_STATUS_TIMEOUT_MS });
343
- if (result.killed) {
344
- throwIfAborted(signal);
345
- throw new Error(`git ${args.slice(0, 2).join(" ")} timed out.`);
346
- }
347
- if (result.code !== 0) {
348
- const detail = [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join(" ");
349
- throw new Error(detail || `git ${args.slice(0, 2).join(" ")} exited with code ${result.code}.`);
350
- }
351
- return result;
325
+ throwIfAborted(signal);
326
+ const result = await pi.exec("git", args, { cwd, signal, timeout: GIT_STATUS_TIMEOUT_MS, maxBuffer });
327
+ if (result.truncated) {
328
+ throw new Error(`git ${args.slice(0, 2).join(" ")} output exceeded the ${maxBuffer}-byte limit.`);
329
+ }
330
+ if (result.killed) {
331
+ throwIfAborted(signal);
332
+ throw new Error(`git ${args.slice(0, 2).join(" ")} timed out.`);
333
+ }
334
+ if (result.code !== 0) {
335
+ const detail = [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join(" ");
336
+ throw new Error(detail || `git ${args.slice(0, 2).join(" ")} exited with code ${result.code}.`);
337
+ }
338
+ return result;
352
339
  }
353
340
 
354
341
  function parseLastCommit(output: string): LastCommitSummary {
355
- const separator = output.indexOf("\0");
356
- if (separator <= 0 || output.indexOf("\0", separator + 1) >= 0) {
357
- throw new Error("Git returned malformed last-commit details.");
358
- }
359
- const committedAt = output.slice(0, separator);
360
- const subject = removeLineEnding(output.slice(separator + 1));
361
- if (!committedAt) throw new Error("Git returned an empty last-commit timestamp.");
362
- return { committedAt, subject };
342
+ const separator = output.indexOf("\0");
343
+ if (separator <= 0 || output.indexOf("\0", separator + 1) >= 0) {
344
+ throw new Error("Git returned malformed last-commit details.");
345
+ }
346
+ const committedAt = output.slice(0, separator);
347
+ const subject = removeLineEnding(output.slice(separator + 1));
348
+ if (!committedAt) throw new Error("Git returned an empty last-commit timestamp.");
349
+ return { committedAt, subject };
363
350
  }
364
351
 
365
352
  function safeDisplay(value: string): string {
366
- return stripTerminalControls(value);
353
+ return stripTerminalControls(value);
367
354
  }
368
355
 
369
356
  function throwIfAborted(signal?: AbortSignal): void {
370
- if (signal?.aborted) {
371
- throw new DOMException("Worktree status loading was aborted.", "AbortError");
372
- }
357
+ if (signal?.aborted) {
358
+ throw new DOMException("Worktree status loading was aborted.", "AbortError");
359
+ }
373
360
  }
374
361
 
375
362
  function removeLineEnding(value: string): string {
376
- if (value.endsWith("\r\n")) return value.slice(0, -2);
377
- if (value.endsWith("\n")) return value.slice(0, -1);
378
- return value;
363
+ if (value.endsWith("\r\n")) return value.slice(0, -2);
364
+ if (value.endsWith("\n")) return value.slice(0, -1);
365
+ return value;
379
366
  }
380
367
 
381
368
  function formatError(error: unknown): string {
382
- const message = error instanceof Error ? error.message : String(error);
383
- return safeDisplay(message).slice(0, 500);
369
+ const message = error instanceof Error ? error.message : String(error);
370
+ return safeDisplay(message).slice(0, 500);
384
371
  }