@narumitw/pi-worktree 0.51.8 → 0.51.10

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/CHANGELOG.md ADDED
@@ -0,0 +1,85 @@
1
+ # @narumitw/pi-worktree
2
+
3
+ ## 0.51.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [cf7b63d]
8
+ - @narumitw/pi-tui-kit@0.70.0
9
+
10
+ ## 0.51.9
11
+
12
+ ### Patch Changes
13
+
14
+ - e484010: Include the existing package-root CHANGELOG.md in extension tarballs so Pi can show native update notices. Keep Changesets version headings and Pi's first-observation and collapseChangelog behavior unchanged.
15
+ - 5120d4d: Preserve TypeBox enum inference for direct imports and Pi's extension loader without changing provider-visible schemas or validation rules. Import Notes schemas from TypeBox, declare its host-provided peer, and complete Worktree's command result contract for the updated Pi APIs.
16
+ - 0339567: Bound Git command output by operation and report output overflow separately from timeouts. Reject incomplete results before parsing or sparse-checkout fallbacks, and do not use them to approve removal, pruning, or successful creation.
17
+ - Updated dependencies [54f2700]
18
+ - Updated dependencies [6c76ef1]
19
+ - @narumitw/pi-tui-kit@0.69.0
20
+
21
+ ## 0.51.8
22
+
23
+ ### Patch Changes
24
+
25
+ - 8abd5b7: Keep generated extension runtime graphs inside Pi's Jiti-loaded TypeScript path to avoid duplicate peer-runtime evaluation during startup. Add measured generated runtimes for Context Management, Herdr, and TypeSafe Search.
26
+
27
+ ## 0.51.7
28
+
29
+ ### Patch Changes
30
+
31
+ - 7f56adf: Normalize the cwd comparison in `writeTargetSession` so `/worktree` workspace switching works on Windows, where Git reports forward-slash paths but session headers store backslashes.
32
+
33
+ ## 0.51.6
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [40182e5]
38
+ - @narumitw/pi-tui-kit@0.59.0
39
+
40
+ ## 0.51.5
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [b9eba3a]
45
+ - @narumitw/pi-tui-kit@0.58.0
46
+
47
+ ## 0.51.4
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies [6574232]
52
+ - Updated dependencies [cddc265]
53
+ - @narumitw/pi-tui-kit@0.57.0
54
+
55
+ ## 0.51.3
56
+
57
+ ### Patch Changes
58
+
59
+ - dc4f90e: Load each extension from a generated source-mapped Jiti runtime while preserving first-use feature boundaries.
60
+
61
+ ## 0.51.2
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [8bead31]
66
+ - @narumitw/pi-tui-kit@0.56.0
67
+
68
+ ## 0.51.1
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [3176172]
73
+ - @narumitw/pi-tui-kit@0.55.0
74
+
75
+ ## 0.51.0
76
+
77
+ ### Minor Changes
78
+
79
+ - 5fd422d: Add local fuzzy search to worktree identity selectors.
80
+
81
+ ## 0.50.0
82
+
83
+ ### Minor Changes
84
+
85
+ - 0ad0f9f: Add an on-demand worktree status browser and exact commit provenance checks to the Add flow.
package/dist/index.ts CHANGED
@@ -11,6 +11,9 @@ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync } from "
11
11
  import { basename, dirname, resolve } from "node:path";
12
12
  var GIT_TIMEOUT_MS = 15e3;
13
13
  var GIT_MUTATION_TIMEOUT_MS = 6e4;
14
+ var GIT_METADATA_MAX_BUFFER = 64 * 1024;
15
+ var GIT_RECORDS_MAX_BUFFER = 8 * 1024 * 1024;
16
+ var GIT_MUTATION_MAX_BUFFER = 1024 * 1024;
14
17
  var LOCAL_BRANCH_PREFIX = "refs/heads/";
15
18
  var GitWorktreeError = class extends Error {
16
19
  args;
@@ -131,23 +134,29 @@ function sameWorktreeIdentity(left, right) {
131
134
  return pathsEqual(left.path, right.path) && left.head === right.head && left.branchRef === right.branchRef && left.detached === right.detached && left.isMain === right.isMain && left.bare === right.bare;
132
135
  }
133
136
  async function listWorktrees(pi, cwd, signal) {
134
- const result = await runGit(pi, ["worktree", "list", "--porcelain", "-z"], cwd, signal);
137
+ const result = await runGit(pi, ["worktree", "list", "--porcelain", "-z"], cwd, GIT_RECORDS_MAX_BUFFER, signal);
135
138
  return parseWorktreePorcelain(result.stdout);
136
139
  }
137
140
  async function currentWorktreePath(pi, cwd, signal) {
138
- const result = await runGit(pi, ["rev-parse", "--show-toplevel"], cwd, signal);
141
+ const result = await runGit(pi, ["rev-parse", "--show-toplevel"], cwd, GIT_METADATA_MAX_BUFFER, signal);
139
142
  const path = removeLineEnding(result.stdout);
140
143
  if (!path) throw new GitWorktreeError("Git did not return the current worktree path.");
141
144
  return pathIdentity(path);
142
145
  }
143
146
  async function symbolicBranch(pi, cwd, signal) {
144
- const result = await runGitAllowFailure(pi, ["symbolic-ref", "--quiet", "--short", "HEAD"], cwd, signal);
147
+ const result = await runGitAllowFailure(
148
+ pi,
149
+ ["symbolic-ref", "--quiet", "--short", "HEAD"],
150
+ cwd,
151
+ GIT_METADATA_MAX_BUFFER,
152
+ signal
153
+ );
145
154
  if (result.killed) throw killedError(["symbolic-ref", "--quiet", "--short", "HEAD"]);
146
155
  if (result.code !== 0) return void 0;
147
156
  return result.stdout.trim() || void 0;
148
157
  }
149
158
  async function validateBranch(pi, cwd, branch, signal) {
150
- const result = await runGit(pi, ["check-ref-format", "--branch", branch], cwd, signal);
159
+ const result = await runGit(pi, ["check-ref-format", "--branch", branch], cwd, GIT_METADATA_MAX_BUFFER, signal);
151
160
  const normalized = result.stdout.trim();
152
161
  if (!normalized) throw new GitWorktreeError("Git returned an empty branch name.");
153
162
  return normalized;
@@ -157,6 +166,7 @@ async function localBranchExists(pi, cwd, branch, signal) {
157
166
  pi,
158
167
  ["show-ref", "--verify", "--quiet", `${LOCAL_BRANCH_PREFIX}${branch}`],
159
168
  cwd,
169
+ GIT_METADATA_MAX_BUFFER,
160
170
  signal
161
171
  );
162
172
  if (result.killed) throw killedError(["show-ref", "--verify", "--quiet"]);
@@ -165,7 +175,13 @@ async function localBranchExists(pi, cwd, branch, signal) {
165
175
  throw gitFailure(["show-ref", "--verify", "--quiet"], result);
166
176
  }
167
177
  async function resolveCommit(pi, cwd, startPoint, signal) {
168
- const result = await runGit(pi, ["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`], cwd, signal);
178
+ const result = await runGit(
179
+ pi,
180
+ ["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`],
181
+ cwd,
182
+ GIT_METADATA_MAX_BUFFER,
183
+ signal
184
+ );
169
185
  const oid = result.stdout.trim();
170
186
  if (!/^[0-9a-fA-F]{40,64}$/u.test(oid)) {
171
187
  throw new GitWorktreeError(`Git returned an invalid commit object for ${startPoint}.`);
@@ -173,10 +189,10 @@ async function resolveCommit(pi, cwd, startPoint, signal) {
173
189
  return oid;
174
190
  }
175
191
  async function addWorktree(pi, cwd, input, signal) {
176
- await runGit(pi, buildAddArguments(input), cwd, signal, GIT_MUTATION_TIMEOUT_MS);
192
+ await runGit(pi, buildAddArguments(input), cwd, GIT_MUTATION_MAX_BUFFER, signal, GIT_MUTATION_TIMEOUT_MS);
177
193
  }
178
194
  async function removeWorktree(pi, cwd, path, signal) {
179
- await runGit(pi, ["worktree", "remove", path], cwd, signal, GIT_MUTATION_TIMEOUT_MS);
195
+ await runGit(pi, ["worktree", "remove", path], cwd, GIT_MUTATION_MAX_BUFFER, signal, GIT_MUTATION_TIMEOUT_MS);
180
196
  }
181
197
  async function worktreeInventory(pi, path, signal) {
182
198
  const statusArgs = [
@@ -186,10 +202,16 @@ async function worktreeInventory(pi, path, signal) {
186
202
  "--ignored=matching",
187
203
  "--ignore-submodules=none"
188
204
  ];
189
- const status = await runGit(pi, statusArgs, path, signal);
190
- const indexFlags = await runGit(pi, ["ls-files", "-v", "-z"], path, signal);
205
+ const status = await runGit(pi, statusArgs, path, GIT_RECORDS_MAX_BUFFER, signal);
206
+ const indexFlags = await runGit(pi, ["ls-files", "-v", "-z"], path, GIT_RECORDS_MAX_BUFFER, signal);
191
207
  const indexInventory = await indexFlagInventory(pi, indexFlags.stdout, path, signal);
192
- const submoduleStatus = await runGit(pi, ["submodule", "status", "--recursive"], path, signal);
208
+ const submoduleStatus = await runGit(
209
+ pi,
210
+ ["submodule", "status", "--recursive"],
211
+ path,
212
+ GIT_RECORDS_MAX_BUFFER,
213
+ signal
214
+ );
193
215
  const initializedSubmodules = nonEmptyLines(submoduleStatus.stdout).filter((line) => !line.startsWith("-")).map((line) => `initialized submodule: ${line.slice(1).trimStart()}`);
194
216
  const submodules = await runGit(
195
217
  pi,
@@ -201,6 +223,7 @@ async function worktreeInventory(pi, path, signal) {
201
223
  "git status --porcelain=v1 --untracked-files=all --ignored=matching --ignore-submodules=none"
202
224
  ],
203
225
  path,
226
+ GIT_RECORDS_MAX_BUFFER,
204
227
  signal
205
228
  );
206
229
  return [
@@ -211,7 +234,13 @@ async function worktreeInventory(pi, path, signal) {
211
234
  ];
212
235
  }
213
236
  async function worktreeAdministrativeDirectory(pi, cwd, signal) {
214
- const result = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-dir"], cwd, signal);
237
+ const result = await runGit(
238
+ pi,
239
+ ["rev-parse", "--path-format=absolute", "--git-dir"],
240
+ cwd,
241
+ GIT_METADATA_MAX_BUFFER,
242
+ signal
243
+ );
215
244
  const value = removeLineEnding(result.stdout);
216
245
  if (!value) throw new GitWorktreeError("Git did not return its worktree administrative path.");
217
246
  return resolve(cwd, value);
@@ -223,6 +252,7 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
223
252
  pi,
224
253
  [gitDirArgument, "for-each-ref", "--format=%(objectname)", "refs/worktree", "refs/bisect"],
225
254
  cwd,
255
+ GIT_RECORDS_MAX_BUFFER,
226
256
  signal
227
257
  );
228
258
  values.push(...splitAdministrativeOids(refs.stdout, "per-worktree refs"));
@@ -238,7 +268,13 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
238
268
  return [...new Set(values)];
239
269
  }
240
270
  async function administrativePruneCandidates(pi, cwd, signal) {
241
- const commonResult = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd, signal);
271
+ const commonResult = await runGit(
272
+ pi,
273
+ ["rev-parse", "--path-format=absolute", "--git-common-dir"],
274
+ cwd,
275
+ GIT_METADATA_MAX_BUFFER,
276
+ signal
277
+ );
242
278
  const commonValue = removeLineEnding(commonResult.stdout);
243
279
  if (!commonValue) throw new GitWorktreeError("Git did not return its common directory.");
244
280
  const commonDirectory = resolve(cwd, commonValue);
@@ -310,7 +346,7 @@ async function administrativeIndexIsDirty(pi, cwd, administrativePath, signal) {
310
346
  "--ignore-submodules=none",
311
347
  "--"
312
348
  ];
313
- const result = await runGitAllowFailure(pi, args, cwd, signal);
349
+ const result = await runGitAllowFailure(pi, args, cwd, GIT_METADATA_MAX_BUFFER, signal);
314
350
  if (result.killed) throw killedError(args);
315
351
  if (result.code === 0) return false;
316
352
  if (result.code === 1) return true;
@@ -320,7 +356,13 @@ async function durableRefExists(pi, cwd, ref, signal) {
320
356
  if (!ref.startsWith("refs/") || ref.includes("\0")) {
321
357
  throw new GitWorktreeError("Git worktree administrative HEAD contains an invalid ref.");
322
358
  }
323
- const result = await runGitAllowFailure(pi, ["show-ref", "--verify", "--quiet", ref], cwd, signal);
359
+ const result = await runGitAllowFailure(
360
+ pi,
361
+ ["show-ref", "--verify", "--quiet", ref],
362
+ cwd,
363
+ GIT_METADATA_MAX_BUFFER,
364
+ signal
365
+ );
324
366
  if (result.killed) throw killedError(["show-ref", "--verify", "--quiet"]);
325
367
  if (result.code === 0) return true;
326
368
  if (result.code === 1) return false;
@@ -334,16 +376,24 @@ async function durableRefsContaining(pi, cwd, head, signal) {
334
376
  pi,
335
377
  ["for-each-ref", "--format=%(refname)", `--contains=${head}`, "refs/heads", "refs/tags", "refs/remotes"],
336
378
  cwd,
379
+ GIT_RECORDS_MAX_BUFFER,
337
380
  signal
338
381
  );
339
382
  return nonEmptyLines(result.stdout);
340
383
  }
341
384
  async function prunePreview(pi, cwd, signal) {
342
- const result = await runGit(pi, ["worktree", "prune", "--dry-run", "--verbose"], cwd, signal);
385
+ const result = await runGit(pi, ["worktree", "prune", "--dry-run", "--verbose"], cwd, GIT_RECORDS_MAX_BUFFER, signal);
343
386
  return combineOutput(result);
344
387
  }
345
388
  async function pruneWorktrees(pi, cwd, signal) {
346
- const result = await runGit(pi, ["worktree", "prune", "--verbose"], cwd, signal, GIT_MUTATION_TIMEOUT_MS);
389
+ const result = await runGit(
390
+ pi,
391
+ ["worktree", "prune", "--verbose"],
392
+ cwd,
393
+ GIT_MUTATION_MAX_BUFFER,
394
+ signal,
395
+ GIT_MUTATION_TIMEOUT_MS
396
+ );
347
397
  return combineOutput(result);
348
398
  }
349
399
  function formatWorktree(record, currentPath) {
@@ -364,15 +414,16 @@ function stripTerminalControls(value) {
364
414
  return code > 31 && (code < 127 || code > 159);
365
415
  }).join("");
366
416
  }
367
- async function runGit(pi, args, cwd, signal, timeout = GIT_TIMEOUT_MS) {
368
- const result = await runGitAllowFailure(pi, args, cwd, signal, timeout);
417
+ async function runGit(pi, args, cwd, maxBuffer, signal, timeout = GIT_TIMEOUT_MS) {
418
+ const result = await runGitAllowFailure(pi, args, cwd, maxBuffer, signal, timeout);
369
419
  if (result.killed) throw killedError(args);
370
420
  if (result.code !== 0) throw gitFailure(args, result);
371
421
  return result;
372
422
  }
373
- async function runGitAllowFailure(pi, args, cwd, signal, timeout = GIT_TIMEOUT_MS) {
423
+ async function runGitAllowFailure(pi, args, cwd, maxBuffer, signal, timeout = GIT_TIMEOUT_MS) {
424
+ let result;
374
425
  try {
375
- return await pi.exec("git", args, { cwd, signal, timeout });
426
+ result = await pi.exec("git", args, { cwd, signal, timeout, maxBuffer });
376
427
  } catch (error) {
377
428
  const message = formatError(error);
378
429
  if (/\bENOENT\b|not found/i.test(message)) {
@@ -380,6 +431,14 @@ async function runGitAllowFailure(pi, args, cwd, signal, timeout = GIT_TIMEOUT_M
380
431
  }
381
432
  throw new GitWorktreeError(`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`, args);
382
433
  }
434
+ if (result.truncated) throw outputLimitError(args, maxBuffer);
435
+ return result;
436
+ }
437
+ function outputLimitError(args, maxBuffer) {
438
+ return new GitWorktreeError(
439
+ `git ${args.slice(0, 2).join(" ")} output exceeded the ${maxBuffer}-byte limit. Partial output was not used; inspect Git state before retrying.`,
440
+ args
441
+ );
383
442
  }
384
443
  function gitFailure(args, result) {
385
444
  const detail = stripTerminalControls([result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n"));
@@ -429,12 +488,13 @@ function parseIndexFlagEntries(value) {
429
488
  async function sparseManagedSkipWorktreePaths(pi, cwd, paths, signal) {
430
489
  if (paths.length === 0) return /* @__PURE__ */ new Set();
431
490
  const configArgs = ["config", "--bool", "--get", "core.sparseCheckout"];
432
- const config = await runGitAllowFailure(pi, configArgs, cwd, signal);
491
+ const config = await runGitAllowFailure(pi, configArgs, cwd, GIT_METADATA_MAX_BUFFER, signal);
433
492
  if (config.killed) throw killedError(configArgs);
434
493
  if (config.code !== 0 || config.stdout.trim() !== "true") return /* @__PURE__ */ new Set();
435
494
  const candidates = new Set(paths);
436
495
  const checkArgs = ["sparse-checkout", "check-rules", "-z"];
437
496
  const checked = await runGitWithInputAllowFailure(checkArgs, cwd, `${[...candidates].join("\0")}\0`, signal);
497
+ if (checked.truncated) throw outputLimitError(checkArgs, GIT_RECORDS_MAX_BUFFER);
438
498
  if (checked.killed) throw killedError(checkArgs);
439
499
  if (checked.code !== 0) return /* @__PURE__ */ new Set();
440
500
  const included = new Set(nulSeparatedPaths(checked.stdout, "sparse-checkout rules"));
@@ -445,13 +505,15 @@ async function sparseManagedSkipWorktreePaths(pi, cwd, paths, signal) {
445
505
  }
446
506
  function runGitWithInputAllowFailure(args, cwd, input, signal, timeout = GIT_TIMEOUT_MS) {
447
507
  if (signal?.aborted) {
448
- return Promise.resolve({ stdout: "", stderr: "", code: 1, killed: true });
508
+ return Promise.resolve({ stdout: "", stderr: "", code: 1, killed: true, truncated: false });
449
509
  }
450
510
  return new Promise((resolveResult, reject) => {
451
511
  const child = spawn("git", args, { cwd, stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
452
512
  let stdout = "";
453
513
  let stderr = "";
454
514
  let killed = false;
515
+ let truncated = false;
516
+ let outputBytes = 0;
455
517
  let settled = false;
456
518
  const finish = (result) => {
457
519
  if (settled) return;
@@ -476,20 +538,36 @@ function runGitWithInputAllowFailure(args, cwd, input, signal, timeout = GIT_TIM
476
538
  child.kill();
477
539
  };
478
540
  const timeoutHandle = setTimeout(stop, timeout);
541
+ const acceptChunk = (chunk) => {
542
+ if (truncated) return false;
543
+ outputBytes += Buffer.byteLength(chunk);
544
+ if (outputBytes <= GIT_RECORDS_MAX_BUFFER) return true;
545
+ truncated = true;
546
+ child.stdout.destroy();
547
+ child.stderr.destroy();
548
+ stop();
549
+ return false;
550
+ };
479
551
  child.stdout.setEncoding("utf8");
480
552
  child.stderr.setEncoding("utf8");
481
553
  child.stdout.on("data", (chunk) => {
482
- stdout += chunk;
554
+ if (acceptChunk(chunk)) stdout += chunk;
483
555
  });
484
556
  child.stderr.on("data", (chunk) => {
485
- stderr += chunk;
557
+ if (acceptChunk(chunk)) stderr += chunk;
486
558
  });
487
559
  child.stdin.on("error", (error) => {
488
560
  if (!isNodeError(error) || error.code !== "EPIPE") fail(error);
489
561
  });
490
562
  child.once("error", fail);
491
563
  child.once("close", (code, closeSignal) => {
492
- finish({ stdout, stderr, code: code ?? 1, killed: killed || closeSignal !== null });
564
+ finish({
565
+ stdout,
566
+ stderr,
567
+ code: truncated && code === 0 ? 1 : code ?? 1,
568
+ killed: killed || closeSignal !== null,
569
+ truncated
570
+ });
493
571
  });
494
572
  signal?.addEventListener("abort", stop, { once: true });
495
573
  if (signal?.aborted) stop();
@@ -680,6 +758,8 @@ function formatError2(error) {
680
758
  // src/status.ts
681
759
  import { existsSync as existsSync3 } from "node:fs";
682
760
  var GIT_STATUS_TIMEOUT_MS = 15e3;
761
+ var GIT_STATUS_MAX_BUFFER = 8 * 1024 * 1024;
762
+ var GIT_LAST_COMMIT_MAX_BUFFER = 64 * 1024;
683
763
  var DEFAULT_STATUS_CONCURRENCY = 4;
684
764
  var OID_PATTERN = /^[0-9a-fA-F]{40,64}$/u;
685
765
  var STATUS_XY_PATTERN = /^[.MADRCUT]{2}$/u;
@@ -813,6 +893,7 @@ async function loadWorktreeStatusCards(pi, records, currentPath, signal, options
813
893
  pi,
814
894
  ["status", "--porcelain=v2", "--branch", "-z", "--untracked-files=all", "--ignore-submodules=none"],
815
895
  record.path,
896
+ GIT_STATUS_MAX_BUFFER,
816
897
  signal
817
898
  );
818
899
  const snapshot = parseWorktreeStatusPorcelain(status.stdout);
@@ -821,6 +902,7 @@ async function loadWorktreeStatusCards(pi, records, currentPath, signal, options
821
902
  pi,
822
903
  ["show", "-s", "--format=%aI%x00%s", "--end-of-options", snapshot.headOid],
823
904
  record.path,
905
+ GIT_LAST_COMMIT_MAX_BUFFER,
824
906
  signal
825
907
  )).stdout
826
908
  ) : void 0;
@@ -908,9 +990,12 @@ function unavailableReason(record) {
908
990
  if (!existsSync3(record.path)) return "Worktree path is missing";
909
991
  return void 0;
910
992
  }
911
- async function runGit2(pi, args, cwd, signal) {
993
+ async function runGit2(pi, args, cwd, maxBuffer, signal) {
912
994
  throwIfAborted(signal);
913
- const result = await pi.exec("git", args, { cwd, signal, timeout: GIT_STATUS_TIMEOUT_MS });
995
+ const result = await pi.exec("git", args, { cwd, signal, timeout: GIT_STATUS_TIMEOUT_MS, maxBuffer });
996
+ if (result.truncated) {
997
+ throw new Error(`git ${args.slice(0, 2).join(" ")} output exceeded the ${maxBuffer}-byte limit.`);
998
+ }
914
999
  if (result.killed) {
915
1000
  throwIfAborted(signal);
916
1001
  throw new Error(`git ${args.slice(0, 2).join(" ")} timed out.`);