@narumitw/pi-worktree 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/command.ts +43 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-worktree",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "Pi extension for safe interactive Git worktree management and workspace switching.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,9 +32,9 @@
32
32
  "@earendil-works/pi-coding-agent": "*"
33
33
  },
34
34
  "devDependencies": {
35
- "@biomejs/biome": "2.5.5",
36
- "@earendil-works/pi-coding-agent": "0.82.1",
37
- "@types/node": "26.1.1",
35
+ "@biomejs/biome": "2.5.6",
36
+ "@earendil-works/pi-coding-agent": "0.83.0",
37
+ "@types/node": "26.1.2",
38
38
  "typescript": "7.0.2"
39
39
  },
40
40
  "repository": {
package/src/command.ts CHANGED
@@ -115,8 +115,10 @@ export function registerWorktreeCommand(
115
115
  },
116
116
  actions: {
117
117
  add: async () => runFlow(() => addFlow(pi, ctx, records, root.effectiveRoot)),
118
- switch: async () => runFlow(() => switchFlow(pi, ctx, records, currentPath)),
119
- remove: async () => runFlow(() => removeFlow(pi, ctx, records, currentPath)),
118
+ switch: async ({ signal }) =>
119
+ runFlow(() => switchFlow(pi, ctx, records, currentPath, signal)),
120
+ remove: async ({ signal }) =>
121
+ runFlow(() => removeFlow(pi, ctx, records, currentPath, signal)),
120
122
  prune: async () => runFlow(() => pruneFlow(pi, ctx, records)),
121
123
  configure: async () => runFlow(() => configureRootFlow(ctx, settings)),
122
124
  },
@@ -273,6 +275,7 @@ async function switchFlow(
273
275
  ctx: ExtensionCommandContext,
274
276
  records: readonly WorktreeRecord[],
275
277
  currentPath: string,
278
+ signal?: AbortSignal,
276
279
  ): Promise<void> {
277
280
  const candidates = records.filter(
278
281
  (record) =>
@@ -281,7 +284,7 @@ async function switchFlow(
281
284
  existsSync(record.path) &&
282
285
  !pathsEqual(record.path, currentPath),
283
286
  );
284
- const selected = await selectWorktree(ctx, "Switch to worktree", candidates, currentPath);
287
+ const selected = await selectWorktree(ctx, "Switch to worktree", candidates, currentPath, signal);
285
288
  if (!selected) return;
286
289
  const latest = await revalidateWorktreeIdentity(pi, ctx, selected);
287
290
  if (
@@ -300,11 +303,18 @@ async function removeFlow(
300
303
  ctx: ExtensionCommandContext,
301
304
  records: readonly WorktreeRecord[],
302
305
  currentPath: string,
306
+ signal?: AbortSignal,
303
307
  ): Promise<void> {
304
308
  const candidates = records.filter(
305
309
  (record) => !record.isMain && !record.bare && !pathsEqual(record.path, currentPath),
306
310
  );
307
- const selected = await selectWorktree(ctx, "Remove linked worktree", candidates, currentPath);
311
+ const selected = await selectWorktree(
312
+ ctx,
313
+ "Remove linked worktree",
314
+ candidates,
315
+ currentPath,
316
+ signal,
317
+ );
308
318
  if (!selected) return;
309
319
  if (selected.lockedReason !== undefined) {
310
320
  throw new Error(
@@ -630,17 +640,40 @@ async function selectWorktree(
630
640
  title: string,
631
641
  records: readonly WorktreeRecord[],
632
642
  currentPath: string,
643
+ signal?: AbortSignal,
633
644
  ): Promise<WorktreeRecord | undefined> {
634
645
  if (records.length === 0) {
635
646
  ctx.ui.notify("No eligible worktrees are available for this action.", "info");
636
647
  return undefined;
637
648
  }
638
- const labels = records.map(
639
- (record, index) => `${index + 1}. ${formatWorktree(record, currentPath)}`,
640
- );
641
- const selected = await ctx.ui.select(title, labels);
642
- const index = selected === undefined ? -1 : labels.indexOf(selected);
643
- return index < 0 ? undefined : records[index];
649
+ let selected: WorktreeRecord | undefined;
650
+ const menu = defineMenu<undefined, "worktrees", "choose", ExtensionCommandContext>({
651
+ start: "worktrees",
652
+ screens: {
653
+ worktrees: () => ({
654
+ kind: "choice",
655
+ title,
656
+ items: records.map((record, index) => ({
657
+ id: record.path,
658
+ label: `${index + 1}. ${formatWorktree(record, currentPath)}`,
659
+ })),
660
+ action: "choose",
661
+ hint: "close",
662
+ }),
663
+ },
664
+ actions: {
665
+ choose: async ({ itemId }) => {
666
+ selected = records.find((record) => record.path === itemId);
667
+ return selected ? { kind: "close" } : { kind: "rejected" };
668
+ },
669
+ },
670
+ });
671
+ await runMenu(ctx, menu, {
672
+ getState: () => undefined,
673
+ signal,
674
+ isCurrent: () => !signal?.aborted,
675
+ });
676
+ return selected;
644
677
  }
645
678
 
646
679
  function safeNotify(