@narumitw/pi-worktree 0.51.6 → 0.51.8

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/dist/index.ts CHANGED
@@ -43,9 +43,7 @@ function parseWorktreePorcelain(output) {
43
43
  continue;
44
44
  }
45
45
  if (!current) {
46
- throw new GitWorktreeError(
47
- `Worktree porcelain field ${JSON.stringify(key)} appears before worktree.`
48
- );
46
+ throw new GitWorktreeError(`Worktree porcelain field ${JSON.stringify(key)} appears before worktree.`);
49
47
  }
50
48
  switch (key) {
51
49
  case "HEAD":
@@ -113,16 +111,12 @@ function unresolvableSymlinkAncestor(path) {
113
111
  if (isNodeError(error) && (error.code === "ENOENT" || error.code === "ELOOP")) {
114
112
  return current;
115
113
  }
116
- throw new GitWorktreeError(
117
- `Cannot resolve filesystem ancestor ${current}: ${formatError(error)}`
118
- );
114
+ throw new GitWorktreeError(`Cannot resolve filesystem ancestor ${current}: ${formatError(error)}`);
119
115
  }
120
116
  } catch (error) {
121
117
  if (!isNodeError(error) || error.code !== "ENOENT") {
122
118
  if (error instanceof GitWorktreeError) throw error;
123
- throw new GitWorktreeError(
124
- `Cannot inspect filesystem ancestor ${current}: ${formatError(error)}`
125
- );
119
+ throw new GitWorktreeError(`Cannot inspect filesystem ancestor ${current}: ${formatError(error)}`);
126
120
  }
127
121
  const parent = dirname(current);
128
122
  if (parent === current) return void 0;
@@ -147,12 +141,7 @@ async function currentWorktreePath(pi, cwd, signal) {
147
141
  return pathIdentity(path);
148
142
  }
149
143
  async function symbolicBranch(pi, cwd, signal) {
150
- const result = await runGitAllowFailure(
151
- pi,
152
- ["symbolic-ref", "--quiet", "--short", "HEAD"],
153
- cwd,
154
- signal
155
- );
144
+ const result = await runGitAllowFailure(pi, ["symbolic-ref", "--quiet", "--short", "HEAD"], cwd, signal);
156
145
  if (result.killed) throw killedError(["symbolic-ref", "--quiet", "--short", "HEAD"]);
157
146
  if (result.code !== 0) return void 0;
158
147
  return result.stdout.trim() || void 0;
@@ -176,12 +165,7 @@ async function localBranchExists(pi, cwd, branch, signal) {
176
165
  throw gitFailure(["show-ref", "--verify", "--quiet"], result);
177
166
  }
178
167
  async function resolveCommit(pi, cwd, startPoint, signal) {
179
- const result = await runGit(
180
- pi,
181
- ["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`],
182
- cwd,
183
- signal
184
- );
168
+ const result = await runGit(pi, ["rev-parse", "--verify", "--end-of-options", `${startPoint}^{commit}`], cwd, signal);
185
169
  const oid = result.stdout.trim();
186
170
  if (!/^[0-9a-fA-F]{40,64}$/u.test(oid)) {
187
171
  throw new GitWorktreeError(`Git returned an invalid commit object for ${startPoint}.`);
@@ -227,12 +211,7 @@ async function worktreeInventory(pi, path, signal) {
227
211
  ];
228
212
  }
229
213
  async function worktreeAdministrativeDirectory(pi, cwd, signal) {
230
- const result = await runGit(
231
- pi,
232
- ["rev-parse", "--path-format=absolute", "--git-dir"],
233
- cwd,
234
- signal
235
- );
214
+ const result = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-dir"], cwd, signal);
236
215
  const value = removeLineEnding(result.stdout);
237
216
  if (!value) throw new GitWorktreeError("Git did not return its worktree administrative path.");
238
217
  return resolve(cwd, value);
@@ -247,14 +226,7 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
247
226
  signal
248
227
  );
249
228
  values.push(...splitAdministrativeOids(refs.stdout, "per-worktree refs"));
250
- for (const name of [
251
- "ORIG_HEAD",
252
- "MERGE_HEAD",
253
- "REBASE_HEAD",
254
- "CHERRY_PICK_HEAD",
255
- "REVERT_HEAD",
256
- "BISECT_HEAD"
257
- ]) {
229
+ for (const name of ["ORIG_HEAD", "MERGE_HEAD", "REBASE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "BISECT_HEAD"]) {
258
230
  const contents = readAdministrativeFile(administrativePath, name);
259
231
  if (contents === void 0) continue;
260
232
  values.push(...splitAdministrativeOids(contents, name));
@@ -266,12 +238,7 @@ async function administrativeHistoryOids(pi, cwd, administrativePath, signal) {
266
238
  return [...new Set(values)];
267
239
  }
268
240
  async function administrativePruneCandidates(pi, cwd, signal) {
269
- const commonResult = await runGit(
270
- pi,
271
- ["rev-parse", "--path-format=absolute", "--git-common-dir"],
272
- cwd,
273
- signal
274
- );
241
+ const commonResult = await runGit(pi, ["rev-parse", "--path-format=absolute", "--git-common-dir"], cwd, signal);
275
242
  const commonValue = removeLineEnding(commonResult.stdout);
276
243
  if (!commonValue) throw new GitWorktreeError("Git did not return its common directory.");
277
244
  const commonDirectory = resolve(cwd, commonValue);
@@ -281,9 +248,7 @@ async function administrativePruneCandidates(pi, cwd, signal) {
281
248
  for (const entry of readdirSync(administrativeRoot, { withFileTypes: true })) {
282
249
  const administrativePath = resolve(administrativeRoot, entry.name);
283
250
  if (!entry.isDirectory() || entry.isSymbolicLink()) {
284
- throw new GitWorktreeError(
285
- `Unexpected Git worktree administrative entry: ${administrativePath}.`
286
- );
251
+ throw new GitWorktreeError(`Unexpected Git worktree administrative entry: ${administrativePath}.`);
287
252
  }
288
253
  if (existsSync(resolve(administrativePath, "locked"))) continue;
289
254
  const gitdirPath = resolve(administrativePath, "gitdir");
@@ -306,17 +271,13 @@ async function administrativePruneCandidates(pi, cwd, signal) {
306
271
  headValue = removeLineEnding(readFileSync(headPath, "utf8"));
307
272
  } catch (error) {
308
273
  if (error instanceof GitWorktreeError) throw error;
309
- throw new GitWorktreeError(
310
- `Cannot inspect Git worktree administrative HEAD ${headPath}: ${formatError(error)}`
311
- );
274
+ throw new GitWorktreeError(`Cannot inspect Git worktree administrative HEAD ${headPath}: ${formatError(error)}`);
312
275
  }
313
276
  const indexDirty = await administrativeIndexIsDirty(pi, cwd, administrativePath, signal);
314
277
  if (headValue.startsWith("ref: ")) {
315
278
  const branchRef = headValue.slice("ref: ".length);
316
279
  if (!branchRef) {
317
- throw new GitWorktreeError(
318
- `Git worktree administrative HEAD has an empty ref: ${headPath}.`
319
- );
280
+ throw new GitWorktreeError(`Git worktree administrative HEAD has an empty ref: ${headPath}.`);
320
281
  }
321
282
  candidates.push({
322
283
  id: entry.name,
@@ -359,12 +320,7 @@ async function durableRefExists(pi, cwd, ref, signal) {
359
320
  if (!ref.startsWith("refs/") || ref.includes("\0")) {
360
321
  throw new GitWorktreeError("Git worktree administrative HEAD contains an invalid ref.");
361
322
  }
362
- const result = await runGitAllowFailure(
363
- pi,
364
- ["show-ref", "--verify", "--quiet", ref],
365
- cwd,
366
- signal
367
- );
323
+ const result = await runGitAllowFailure(pi, ["show-ref", "--verify", "--quiet", ref], cwd, signal);
368
324
  if (result.killed) throw killedError(["show-ref", "--verify", "--quiet"]);
369
325
  if (result.code === 0) return true;
370
326
  if (result.code === 1) return false;
@@ -376,14 +332,7 @@ async function durableRefsContaining(pi, cwd, head, signal) {
376
332
  }
377
333
  const result = await runGit(
378
334
  pi,
379
- [
380
- "for-each-ref",
381
- "--format=%(refname)",
382
- `--contains=${head}`,
383
- "refs/heads",
384
- "refs/tags",
385
- "refs/remotes"
386
- ],
335
+ ["for-each-ref", "--format=%(refname)", `--contains=${head}`, "refs/heads", "refs/tags", "refs/remotes"],
387
336
  cwd,
388
337
  signal
389
338
  );
@@ -394,13 +343,7 @@ async function prunePreview(pi, cwd, signal) {
394
343
  return combineOutput(result);
395
344
  }
396
345
  async function pruneWorktrees(pi, cwd, signal) {
397
- const result = await runGit(
398
- pi,
399
- ["worktree", "prune", "--verbose"],
400
- cwd,
401
- signal,
402
- GIT_MUTATION_TIMEOUT_MS
403
- );
346
+ const result = await runGit(pi, ["worktree", "prune", "--verbose"], cwd, signal, GIT_MUTATION_TIMEOUT_MS);
404
347
  return combineOutput(result);
405
348
  }
406
349
  function formatWorktree(record, currentPath) {
@@ -435,24 +378,16 @@ async function runGitAllowFailure(pi, args, cwd, signal, timeout = GIT_TIMEOUT_M
435
378
  if (/\bENOENT\b|not found/i.test(message)) {
436
379
  throw new GitWorktreeError("Git executable was not found. Install Git and retry.", args);
437
380
  }
438
- throw new GitWorktreeError(
439
- `Could not start git ${args.slice(0, 2).join(" ")}: ${message}`,
440
- args
441
- );
381
+ throw new GitWorktreeError(`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`, args);
442
382
  }
443
383
  }
444
384
  function gitFailure(args, result) {
445
- const detail = stripTerminalControls(
446
- [result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n")
447
- );
385
+ const detail = stripTerminalControls([result.stderr.trim(), result.stdout.trim()].filter(Boolean).join("\n"));
448
386
  const hint = /not a git repository/i.test(detail) ? "The current Pi workspace is not inside a Git repository." : detail || `Git exited with code ${result.code}.`;
449
387
  return new GitWorktreeError(`git ${args.slice(0, 2).join(" ")} failed: ${hint}`, args);
450
388
  }
451
389
  function killedError(args) {
452
- return new GitWorktreeError(
453
- `git ${args.slice(0, 2).join(" ")} timed out or was cancelled.`,
454
- args
455
- );
390
+ return new GitWorktreeError(`git ${args.slice(0, 2).join(" ")} timed out or was cancelled.`, args);
456
391
  }
457
392
  function nonEmptyLines(value) {
458
393
  return value.split(/\r?\n/u).filter((line) => line.length > 0);
@@ -499,12 +434,7 @@ async function sparseManagedSkipWorktreePaths(pi, cwd, paths, signal) {
499
434
  if (config.code !== 0 || config.stdout.trim() !== "true") return /* @__PURE__ */ new Set();
500
435
  const candidates = new Set(paths);
501
436
  const checkArgs = ["sparse-checkout", "check-rules", "-z"];
502
- const checked = await runGitWithInputAllowFailure(
503
- checkArgs,
504
- cwd,
505
- `${[...candidates].join("\0")}\0`,
506
- signal
507
- );
437
+ const checked = await runGitWithInputAllowFailure(checkArgs, cwd, `${[...candidates].join("\0")}\0`, signal);
508
438
  if (checked.killed) throw killedError(checkArgs);
509
439
  if (checked.code !== 0) return /* @__PURE__ */ new Set();
510
440
  const included = new Set(nulSeparatedPaths(checked.stdout, "sparse-checkout rules"));
@@ -538,10 +468,7 @@ function runGitWithInputAllowFailure(args, cwd, input, signal, timeout = GIT_TIM
538
468
  child.kill();
539
469
  const message = formatError(error);
540
470
  reject(
541
- /\bENOENT\b|not found/i.test(message) ? new GitWorktreeError("Git executable was not found. Install Git and retry.", args) : new GitWorktreeError(
542
- `Could not start git ${args.slice(0, 2).join(" ")}: ${message}`,
543
- args
544
- )
471
+ /\bENOENT\b|not found/i.test(message) ? new GitWorktreeError("Git executable was not found. Install Git and retry.", args) : new GitWorktreeError(`Could not start git ${args.slice(0, 2).join(" ")}: ${message}`, args)
545
472
  );
546
473
  };
547
474
  const stop = () => {
@@ -610,21 +537,15 @@ function readAdministrativeFile(administrativePath, name) {
610
537
  stat = lstatSync(path);
611
538
  } catch (error) {
612
539
  if (isNodeError(error) && error.code === "ENOENT") return void 0;
613
- throw new GitWorktreeError(
614
- `Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`
615
- );
540
+ throw new GitWorktreeError(`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`);
616
541
  }
617
542
  if (stat.isSymbolicLink() || !stat.isFile()) {
618
- throw new GitWorktreeError(
619
- `Git worktree administrative ${name} must be a regular file: ${path}.`
620
- );
543
+ throw new GitWorktreeError(`Git worktree administrative ${name} must be a regular file: ${path}.`);
621
544
  }
622
545
  try {
623
546
  return readFileSync(path, "utf8");
624
547
  } catch (error) {
625
- throw new GitWorktreeError(
626
- `Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`
627
- );
548
+ throw new GitWorktreeError(`Cannot inspect Git worktree administrative ${name}: ${formatError(error)}`);
628
549
  }
629
550
  }
630
551
  function readAdministrativeReflogOids(logPath) {
@@ -677,6 +598,7 @@ function formatError(error) {
677
598
 
678
599
  // src/session.ts
679
600
  import { existsSync as existsSync2, writeFileSync } from "node:fs";
601
+ import { resolve as normalizeTargetPath } from "node:path";
680
602
  import { SessionManager } from "@earendil-works/pi-coding-agent";
681
603
  async function switchToWorktree(ctx, targetPath) {
682
604
  let sessionPath;
@@ -684,10 +606,7 @@ async function switchToWorktree(ctx, targetPath) {
684
606
  sessionPath = createTargetSession(ctx, targetPath);
685
607
  const result = await ctx.switchSession(sessionPath, {
686
608
  withSession: async (replacementCtx) => {
687
- replacementCtx.ui.notify(
688
- stripTerminalControls(`Switched Pi workspace to ${targetPath}.`),
689
- "info"
690
- );
609
+ replacementCtx.ui.notify(stripTerminalControls(`Switched Pi workspace to ${targetPath}.`), "info");
691
610
  }
692
611
  });
693
612
  if (result.cancelled) {
@@ -732,12 +651,7 @@ function createTargetSession(ctx, targetPath) {
732
651
  return writeTargetSession(targetPath, ctx.sessionManager.getBranch(), sourceFile, activeLeaf);
733
652
  }
734
653
  if (ctx.sessionManager.getEntries().length > 0) {
735
- return writeTargetSession(
736
- targetPath,
737
- ctx.sessionManager.getBranch(),
738
- void 0,
739
- ctx.sessionManager.getLeafId()
740
- );
654
+ return writeTargetSession(targetPath, ctx.sessionManager.getBranch(), void 0, ctx.sessionManager.getLeafId());
741
655
  }
742
656
  return writeTargetSession(targetPath, [], void 0, null);
743
657
  }
@@ -754,7 +668,7 @@ function writeTargetSession(targetPath, entries, parentSession, expectedLeaf) {
754
668
  mode: 384
755
669
  });
756
670
  const verified = SessionManager.open(targetFile);
757
- if (verified.getCwd() !== targetPath || verified.getLeafId() !== expectedLeaf) {
671
+ if (normalizeTargetPath(verified.getCwd()) !== normalizeTargetPath(targetPath) || verified.getLeafId() !== expectedLeaf) {
758
672
  throw new Error("Pi could not verify the target session cwd and active branch.");
759
673
  }
760
674
  return targetFile;
@@ -851,11 +765,7 @@ function formatWorktreeStatusCard(record, currentPath, result) {
851
765
  description: path,
852
766
  statusText: `${statePrefix}unavailable`,
853
767
  searchText: `${label} ${path} ${identity.join(" ")} unavailable ${reason}`,
854
- details: [
855
- ...baseDetails,
856
- `Status: ${reason}`,
857
- "Snapshot: local Git state; no fetch performed."
858
- ]
768
+ details: [...baseDetails, `Status: ${reason}`, "Snapshot: local Git state; no fetch performed."]
859
769
  };
860
770
  }
861
771
  const { snapshot, lastCommit } = result;
@@ -879,10 +789,7 @@ function formatWorktreeStatusCard(record, currentPath, result) {
879
789
  };
880
790
  }
881
791
  async function loadWorktreeStatusCards(pi, records, currentPath, signal, options = {}) {
882
- const concurrency = Math.max(
883
- 1,
884
- Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1)
885
- );
792
+ const concurrency = Math.max(1, Math.min(options.concurrency ?? DEFAULT_STATUS_CONCURRENCY, records.length || 1));
886
793
  const cards = new Array(records.length);
887
794
  let nextIndex = 0;
888
795
  const worker = async () => {
@@ -904,14 +811,7 @@ async function loadWorktreeStatusCards(pi, records, currentPath, signal, options
904
811
  try {
905
812
  const status = await runGit2(
906
813
  pi,
907
- [
908
- "status",
909
- "--porcelain=v2",
910
- "--branch",
911
- "-z",
912
- "--untracked-files=all",
913
- "--ignore-submodules=none"
914
- ],
814
+ ["status", "--porcelain=v2", "--branch", "-z", "--untracked-files=all", "--ignore-submodules=none"],
915
815
  record.path,
916
816
  signal
917
817
  );
@@ -1069,11 +969,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
1069
969
  description: "Interactively manage Git worktrees and their default root",
1070
970
  handler: async (args, ctx) => {
1071
971
  if (args.trim()) {
1072
- safeNotify(
1073
- ctx,
1074
- "/worktree does not accept arguments; run it without arguments to open the menu.",
1075
- "warning"
1076
- );
972
+ safeNotify(ctx, "/worktree does not accept arguments; run it without arguments to open the menu.", "warning");
1077
973
  return;
1078
974
  }
1079
975
  if (!ctx.hasUI) {
@@ -1130,12 +1026,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
1130
1026
  status: async ({ signal }) => {
1131
1027
  try {
1132
1028
  const statusRecords = await listWorktrees(pi, ctx.cwd, signal);
1133
- state.statusCards = await loadWorktreeStatusCards(
1134
- pi,
1135
- statusRecords,
1136
- currentPath,
1137
- signal
1138
- );
1029
+ state.statusCards = await loadWorktreeStatusCards(pi, statusRecords, currentPath, signal);
1139
1030
  if (signal.aborted || !owner.isCurrent()) return { kind: "close" };
1140
1031
  return { kind: "to", screen: "status" };
1141
1032
  } catch (error) {
@@ -1165,9 +1056,7 @@ function registerWorktreeCommand(pi, settings, getMenuOwner) {
1165
1056
  async function configureRootFlow(ctx, settings) {
1166
1057
  const current = await settings.reload();
1167
1058
  if (!current.canSave) {
1168
- throw new Error(
1169
- current.warning ?? `Fix ${settings.getPath()} before changing pi-worktree settings.`
1170
- );
1059
+ throw new Error(current.warning ?? `Fix ${settings.getPath()} before changing pi-worktree settings.`);
1171
1060
  }
1172
1061
  const requested = await ctx.ui.input(
1173
1062
  "Worktree root (blank restores ~/.worktrees)",
@@ -1189,9 +1078,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
1189
1078
  throw new Error("The main worktree is bare; pi-worktree cannot derive a safe default path.");
1190
1079
  }
1191
1080
  if (!existsSync4(main.path)) {
1192
- throw new Error(
1193
- `The registered main worktree path is stale: ${main.path}. Repair it with Git first.`
1194
- );
1081
+ throw new Error(`The registered main worktree path is stale: ${main.path}. Repair it with Git first.`);
1195
1082
  }
1196
1083
  const requestedBranch = await ctx.ui.input("Branch for the new worktree", "feat/my-change");
1197
1084
  if (requestedBranch === void 0) return;
@@ -1236,9 +1123,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
1236
1123
  stripTerminalControls(suggestedPath)
1237
1124
  );
1238
1125
  if (requestedPath === void 0) return;
1239
- const targetPath = pathIdentity(
1240
- requestedPath.trim() ? resolve2(ctx.cwd, requestedPath.trim()) : suggestedPath
1241
- );
1126
+ const targetPath = pathIdentity(requestedPath.trim() ? resolve2(ctx.cwd, requestedPath.trim()) : suggestedPath);
1242
1127
  assertTargetFilesystemAvailable(targetPath);
1243
1128
  const pathCollision = records.find((record) => pathsEqual(record.path, targetPath));
1244
1129
  if (pathCollision) {
@@ -1250,15 +1135,11 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
1250
1135
  const latestRecords = await listWorktrees(pi, ctx.cwd, ctx.signal);
1251
1136
  const latestOccupied = worktreeForBranch(latestRecords, branch);
1252
1137
  if (latestOccupied) {
1253
- throw new Error(
1254
- `Branch ${branch} is now checked out at ${latestOccupied.path}; select it again.`
1255
- );
1138
+ throw new Error(`Branch ${branch} is now checked out at ${latestOccupied.path}; select it again.`);
1256
1139
  }
1257
1140
  const latestPathCollision = latestRecords.find((record) => pathsEqual(record.path, targetPath));
1258
1141
  if (latestPathCollision) {
1259
- throw new Error(
1260
- `The target path is now registered as a worktree: ${latestPathCollision.path}. Select it again.`
1261
- );
1142
+ throw new Error(`The target path is now registered as a worktree: ${latestPathCollision.path}. Select it again.`);
1262
1143
  }
1263
1144
  const branchStillExists = await localBranchExists(pi, ctx.cwd, branch, ctx.signal);
1264
1145
  if (branchStillExists !== branchExists) {
@@ -1277,9 +1158,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
1277
1158
  const updated = await listWorktrees(pi, ctx.cwd, ctx.signal);
1278
1159
  const verified = updated.find((record) => pathsEqual(record.path, targetPath));
1279
1160
  if (!verified || verified.branch !== branch || verified.head !== provenance.oid) {
1280
- throw new Error(
1281
- "the expected path, branch, and approved HEAD were not present in Git porcelain output"
1282
- );
1161
+ throw new Error("the expected path, branch, and approved HEAD were not present in Git porcelain output");
1283
1162
  }
1284
1163
  created = verified;
1285
1164
  } catch (error) {
@@ -1288,10 +1167,7 @@ async function addFlow(pi, ctx, records, worktreeRoot) {
1288
1167
  );
1289
1168
  }
1290
1169
  safeNotify(ctx, `Created worktree ${targetPath} on branch ${branch}.`, "info");
1291
- if (await ctx.ui.confirm(
1292
- "Switch Pi workspace?",
1293
- stripTerminalControls(`Continue this conversation in ${targetPath}?`)
1294
- )) {
1170
+ if (await ctx.ui.confirm("Switch Pi workspace?", stripTerminalControls(`Continue this conversation in ${targetPath}?`))) {
1295
1171
  const latest = await revalidateWorktreeIdentity(pi, ctx, created);
1296
1172
  if (latest.prunableReason !== void 0 || !existsSync4(latest.path)) {
1297
1173
  throw new Error("The newly created worktree became unavailable; select it again.");
@@ -1328,9 +1204,7 @@ function assertTargetFilesystemAvailable(targetPath) {
1328
1204
  }
1329
1205
  const unsafeAncestor = unresolvableSymlinkAncestor(targetPath);
1330
1206
  if (unsafeAncestor) {
1331
- throw new Error(
1332
- `The target path has an unresolvable symbolic-link ancestor: ${unsafeAncestor}.`
1333
- );
1207
+ throw new Error(`The target path has an unresolvable symbolic-link ancestor: ${unsafeAncestor}.`);
1334
1208
  }
1335
1209
  }
1336
1210
  async function switchFlow(pi, ctx, records, currentPath, signal) {
@@ -1349,13 +1223,7 @@ async function removeFlow(pi, ctx, records, currentPath, signal) {
1349
1223
  const candidates = records.filter(
1350
1224
  (record) => !record.isMain && !record.bare && !pathsEqual(record.path, currentPath)
1351
1225
  );
1352
- const selected = await selectWorktree(
1353
- ctx,
1354
- "Remove linked worktree",
1355
- candidates,
1356
- currentPath,
1357
- signal
1358
- );
1226
+ const selected = await selectWorktree(ctx, "Remove linked worktree", candidates, currentPath, signal);
1359
1227
  if (!selected) return;
1360
1228
  if (selected.lockedReason !== void 0) {
1361
1229
  throw new Error(
@@ -1365,9 +1233,7 @@ async function removeFlow(pi, ctx, records, currentPath, signal) {
1365
1233
  if (selected.prunableReason !== void 0 || !existsSync4(selected.path)) {
1366
1234
  throw new Error("The selected worktree path is stale. Use prune instead of remove.");
1367
1235
  }
1368
- const inventory = classifyRemovalInventory(
1369
- await worktreeInventory(pi, selected.path, ctx.signal)
1370
- );
1236
+ const inventory = classifyRemovalInventory(await worktreeInventory(pi, selected.path, ctx.signal));
1371
1237
  if (inventory.protected.length > 0) {
1372
1238
  throw new Error(
1373
1239
  `Removal refused because ${selected.path} contains tracked, untracked, index-flagged, or submodule data:
@@ -1391,13 +1257,7 @@ ${recoveryWarning.trimStart()}` : `${ignoredWarning}${recoveryWarning}`;
1391
1257
  )) {
1392
1258
  return;
1393
1259
  }
1394
- await assertAdministrativeHistoryUnchanged(
1395
- pi,
1396
- ctx,
1397
- selected.path,
1398
- administrativePath,
1399
- approvedHistoryRisks
1400
- );
1260
+ await assertAdministrativeHistoryUnchanged(pi, ctx, selected.path, administrativePath, approvedHistoryRisks);
1401
1261
  const beforeRemoval = await listWorktrees(pi, ctx.cwd, ctx.signal);
1402
1262
  const latest = beforeRemoval.find((record) => pathsEqual(record.path, selected.path));
1403
1263
  if (!latest) throw new Error(`Worktree ${selected.path} is no longer registered.`);
@@ -1405,13 +1265,9 @@ ${recoveryWarning.trimStart()}` : `${ignoredWarning}${recoveryWarning}`;
1405
1265
  throw new Error(`Worktree ${selected.path} changed identity; select it again.`);
1406
1266
  }
1407
1267
  if (latest.isMain || latest.lockedReason !== void 0 || latest.prunableReason !== void 0) {
1408
- throw new Error(
1409
- `Worktree ${selected.path} changed state after confirmation; removal was refused.`
1410
- );
1268
+ throw new Error(`Worktree ${selected.path} changed state after confirmation; removal was refused.`);
1411
1269
  }
1412
- const latestInventory = classifyRemovalInventory(
1413
- await worktreeInventory(pi, latest.path, ctx.signal)
1414
- );
1270
+ const latestInventory = classifyRemovalInventory(await worktreeInventory(pi, latest.path, ctx.signal));
1415
1271
  if (latestInventory.protected.length > 0) {
1416
1272
  throw new Error(
1417
1273
  `Removal refused because new protected local data appeared after confirmation:
@@ -1425,13 +1281,7 @@ ${latestInventory.ignored.join("\n") || "(none)"}`
1425
1281
  );
1426
1282
  }
1427
1283
  await assertDetachedHeadIsDurable(pi, ctx, latest);
1428
- await assertAdministrativeHistoryUnchanged(
1429
- pi,
1430
- ctx,
1431
- latest.path,
1432
- administrativePath,
1433
- approvedHistoryRisks
1434
- );
1284
+ await assertAdministrativeHistoryUnchanged(pi, ctx, latest.path, administrativePath, approvedHistoryRisks);
1435
1285
  await removeWorktree(pi, ctx.cwd, latest.path, ctx.signal);
1436
1286
  const updated = await listWorktrees(pi, ctx.cwd, ctx.signal);
1437
1287
  if (updated.some((record) => pathsEqual(record.path, selected.path))) {
@@ -1440,9 +1290,7 @@ ${latestInventory.ignored.join("\n") || "(none)"}`
1440
1290
  safeNotify(ctx, `Removed worktree ${selected.path}. Its branch was preserved.`, "info");
1441
1291
  }
1442
1292
  async function pruneFlow(pi, ctx, records) {
1443
- for (const record of records.filter(
1444
- (candidate) => candidate.prunableReason !== void 0 && candidate.detached
1445
- )) {
1293
+ for (const record of records.filter((candidate) => candidate.prunableReason !== void 0 && candidate.detached)) {
1446
1294
  await assertDetachedHeadIsDurable(pi, ctx, record);
1447
1295
  }
1448
1296
  const preview = await prunePreview(pi, ctx.cwd, ctx.signal);
@@ -1462,9 +1310,7 @@ ${safePreview}`, "warning");
1462
1310
  return;
1463
1311
  }
1464
1312
  const latest = await listWorktrees(pi, ctx.cwd, ctx.signal);
1465
- for (const record of latest.filter(
1466
- (candidate) => candidate.prunableReason !== void 0 && candidate.detached
1467
- )) {
1313
+ for (const record of latest.filter((candidate) => candidate.prunableReason !== void 0 && candidate.detached)) {
1468
1314
  await assertDetachedHeadIsDurable(pi, ctx, record);
1469
1315
  }
1470
1316
  const beforePreviewHistoryRisks = await inspectAdministrativePruneCandidates(pi, ctx);
@@ -1477,19 +1323,11 @@ ${safePreview}`, "warning");
1477
1323
  throw new Error("Stale worktree metadata changed after confirmation; run prune again.");
1478
1324
  }
1479
1325
  const output = await pruneWorktrees(pi, ctx.cwd, ctx.signal);
1480
- safeNotify(
1481
- ctx,
1482
- output ? `Pruned stale worktree metadata:
1483
- ${output}` : "Pruned stale worktree metadata.",
1484
- "info"
1485
- );
1326
+ safeNotify(ctx, output ? `Pruned stale worktree metadata:
1327
+ ${output}` : "Pruned stale worktree metadata.", "info");
1486
1328
  }
1487
1329
  async function assertAdministrativeHistoryUnchanged(pi, ctx, selectedPath, approvedAdministrativePath, approvedHistoryRisks) {
1488
- const latestAdministrativePath = await worktreeAdministrativeDirectory(
1489
- pi,
1490
- selectedPath,
1491
- ctx.signal
1492
- );
1330
+ const latestAdministrativePath = await worktreeAdministrativeDirectory(pi, selectedPath, ctx.signal);
1493
1331
  const latestHistoryRisks = historyRisks(
1494
1332
  selectedPath,
1495
1333
  await unreachableAdministrativeHistoryOids(pi, ctx, latestAdministrativePath)
@@ -1521,10 +1359,7 @@ async function inspectAdministrativePruneCandidates(pi, ctx) {
1521
1359
  );
1522
1360
  }
1523
1361
  risks.push(
1524
- ...historyRisks(
1525
- candidate.id,
1526
- await unreachableAdministrativeHistoryOids(pi, ctx, candidate.administrativePath)
1527
- )
1362
+ ...historyRisks(candidate.id, await unreachableAdministrativeHistoryOids(pi, ctx, candidate.administrativePath))
1528
1363
  );
1529
1364
  }
1530
1365
  return normalizeAdministrativeHistoryRisks(risks);
@@ -1548,9 +1383,7 @@ function sameAdministrativeHistoryRisks(left, right) {
1548
1383
  }
1549
1384
  function formatAdministrativeRecoveryWarning(risks) {
1550
1385
  if (risks.length === 0) return "";
1551
- const entries = risks.map(
1552
- (risk) => `${stripTerminalControls(risk.label)}: ${risk.oids.map(stripTerminalControls).join(", ")}`
1553
- ).join("; ");
1386
+ const entries = risks.map((risk) => `${stripTerminalControls(risk.label)}: ${risk.oids.map(stripTerminalControls).join(", ")}`).join("; ");
1554
1387
  return ` Administrative recovery warning: these commits are not reachable from a branch, tag, or remote ref: ${entries}. Discarding their recovery pointers means they may later be garbage-collected.`;
1555
1388
  }
1556
1389
  function classifyRemovalInventory(lines) {
@@ -1577,8 +1410,7 @@ ${ignored.map(stripTerminalControls).join("\n")}`;
1577
1410
  }
1578
1411
  async function assertDetachedHeadIsDurable(pi, ctx, record) {
1579
1412
  if (!record.detached) return;
1580
- if (!record.head)
1581
- throw new Error(`Detached worktree ${record.path} has no HEAD object; refusing.`);
1413
+ if (!record.head) throw new Error(`Detached worktree ${record.path} has no HEAD object; refusing.`);
1582
1414
  const refs = await durableRefsContaining(pi, ctx.cwd, record.head, ctx.signal);
1583
1415
  if (refs.length === 0) {
1584
1416
  throw new Error(
@@ -1807,12 +1639,7 @@ function createWorktreeSettingsRuntime(options = {}) {
1807
1639
  state = { ...state, warning: latest.warning, canSave: false };
1808
1640
  throw new Error(`Fix the pi-worktree settings file at ${getPath()} before changing it.`);
1809
1641
  }
1810
- await saveWorktreeSettings(
1811
- latest.document ?? {},
1812
- configuredRoot,
1813
- getPath(),
1814
- options.operations
1815
- );
1642
+ await saveWorktreeSettings(latest.document ?? {}, configuredRoot, getPath(), options.operations);
1816
1643
  state = {
1817
1644
  effectiveRoot,
1818
1645
  source: configuredRoot === void 0 ? "default" : "user",