@cestoliv/wt 0.4.0 → 0.4.1

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.
@@ -3,8 +3,8 @@ import {
3
3
  openConfiguredIde,
4
4
  prepareWorktree,
5
5
  promptExistingWorktree
6
- } from "./chunk-ASVHQXDJ.js";
7
- import "./chunk-E2IOE23G.js";
6
+ } from "./chunk-BSMGKL27.js";
7
+ import "./chunk-XM4EABZV.js";
8
8
  import "./chunk-FNAMNRUH.js";
9
9
 
10
10
  // src/commands/agent.ts
@@ -13,7 +13,7 @@ import {
13
13
  runCommands,
14
14
  runRepoPicker,
15
15
  setUpstreamTracking
16
- } from "./chunk-E2IOE23G.js";
16
+ } from "./chunk-XM4EABZV.js";
17
17
  import {
18
18
  createStore,
19
19
  getEffectiveConfig
@@ -253,37 +253,57 @@ function shortenPath(p) {
253
253
  const home = process.env.HOME ?? "";
254
254
  return home && p.startsWith(home) ? `~${p.slice(home.length)}` : p;
255
255
  }
256
- function renderList(items, selectedIndex, query, mode) {
257
- const lines = [];
256
+ function buildListLayout(items, selectedIndex, query, mode) {
257
+ const header = [];
258
258
  if (mode === "global") {
259
- lines.push(
259
+ header.push(
260
260
  pc.dim("\u2139 Not in a git repository \u2014 showing all registered worktrees")
261
261
  );
262
- lines.push("");
262
+ header.push("");
263
263
  }
264
- lines.push(pc.cyan(`> ${query}_`));
265
- lines.push("");
264
+ header.push(pc.cyan(`> ${query}_`));
265
+ const body = [];
266
+ const itemSpans = [];
266
267
  const groups = groupByRepo(items);
267
268
  let i = 0;
268
269
  for (const [repoPath, groupItems] of groups) {
269
- lines.push(pc.bold(path2.basename(repoPath).toUpperCase()));
270
+ body.push(pc.bold(path2.basename(repoPath).toUpperCase()));
270
271
  for (const item of groupItems) {
272
+ const start = body.length;
271
273
  const cursor = i === selectedIndex ? pc.cyan("\u25B6") : " ";
272
274
  const branchLabel = item.isCurrent ? pc.dim(`${item.branch} (current)`) : pc.white(item.branch);
273
275
  const pathLabel = pc.dim(shortenPath(item.path));
274
- lines.push(` ${cursor} ${branchLabel} ${pathLabel}`);
276
+ body.push(` ${cursor} ${branchLabel} ${pathLabel}`);
275
277
  if (item.lastCommit) {
276
- lines.push(` ${pc.dim(item.lastCommit)}`);
278
+ body.push(` ${pc.dim(item.lastCommit)}`);
277
279
  }
280
+ itemSpans[i] = { start, end: body.length - 1 };
278
281
  i++;
279
282
  }
280
283
  }
281
- lines.push("");
282
284
  const createHint = mode === "repo" ? " \xB7 C create" : "";
283
- lines.push(
285
+ const footer = [
284
286
  pc.dim(`\u2195 navigate \xB7 Enter open \xB7 D delete${createHint} \xB7 Q quit`)
285
- );
286
- return lines.join("\n");
287
+ ];
288
+ return { header, body, footer, itemSpans };
289
+ }
290
+ function clampScroll(offset, span, viewportHeight, bodyLength) {
291
+ const maxOffset = Math.max(0, bodyLength - viewportHeight);
292
+ let next = offset;
293
+ if (span.start < next) next = span.start;
294
+ if (span.end >= next + viewportHeight) next = span.end - viewportHeight + 1;
295
+ return Math.max(0, Math.min(next, maxOffset));
296
+ }
297
+ function composeView(layout, offset, viewportHeight) {
298
+ const { header, body, footer } = layout;
299
+ const visible = body.slice(offset, offset + viewportHeight);
300
+ while (visible.length < viewportHeight) visible.push("");
301
+ const topSlot = offset > 0 ? pc.dim(" \u2191 more") : "";
302
+ const bottomSlot = offset + viewportHeight < body.length ? pc.dim(" \u2193 more") : "";
303
+ return [...header, topSlot, ...visible, bottomSlot, ...footer].join("\n");
304
+ }
305
+ function fixedHeight(layout) {
306
+ return layout.header.length + layout.footer.length + 2;
287
307
  }
288
308
  function setupRawMode() {
289
309
  process.stdin.setRawMode(true);
@@ -435,10 +455,21 @@ async function runBranchInput(repoRoot) {
435
455
  async function runInteractiveList(allItems, mode, handlers) {
436
456
  let query = "";
437
457
  let selectedIndex = 0;
458
+ let scrollOffset = 0;
438
459
  let filtered = allItems;
439
460
  const render = () => {
461
+ const rows = process.stdout.rows ?? 24;
462
+ const layout = buildListLayout(filtered, selectedIndex, query, mode);
463
+ const viewport = Math.max(1, rows - fixedHeight(layout));
464
+ const span = layout.itemSpans[selectedIndex] ?? { start: 0, end: 0 };
465
+ scrollOffset = clampScroll(
466
+ scrollOffset,
467
+ span,
468
+ viewport,
469
+ layout.body.length
470
+ );
440
471
  process.stdout.write("\x1B[2J\x1B[H");
441
- process.stdout.write(renderList(filtered, selectedIndex, query, mode));
472
+ process.stdout.write(composeView(layout, scrollOffset, viewport));
442
473
  };
443
474
  setupRawMode();
444
475
  render();
@@ -447,11 +478,13 @@ async function runInteractiveList(allItems, mode, handlers) {
447
478
  const attachListener = () => {
448
479
  if (!listenerActive) {
449
480
  process.stdin.on("data", onData);
481
+ process.stdout.on("resize", render);
450
482
  listenerActive = true;
451
483
  }
452
484
  };
453
485
  const detachListener = () => {
454
486
  process.stdin.removeListener("data", onData);
487
+ process.stdout.removeListener("resize", render);
455
488
  listenerActive = false;
456
489
  };
457
490
  const onData = async (key) => {
@@ -513,11 +546,13 @@ async function runInteractiveList(allItems, mode, handlers) {
513
546
  query = query.slice(0, -1);
514
547
  filtered = filterItems(allItems, query);
515
548
  selectedIndex = 0;
549
+ scrollOffset = 0;
516
550
  render();
517
551
  } else if (key.length === 1 && key >= " ") {
518
552
  query += key;
519
553
  filtered = filterItems(allItems, query);
520
554
  selectedIndex = 0;
555
+ scrollOffset = 0;
521
556
  render();
522
557
  }
523
558
  } catch (err) {
package/dist/cli.js CHANGED
@@ -3,12 +3,12 @@
3
3
  // src/cli.ts
4
4
  import { Command } from "commander";
5
5
  var program = new Command();
6
- program.name("wt").description("Git worktree manager").version("0.4.0").action(async () => {
7
- const { runList } = await import("./list-HIKXMDHJ.js");
6
+ program.name("wt").description("Git worktree manager").version("0.4.1").action(async () => {
7
+ const { runList } = await import("./list-WC5GM3PI.js");
8
8
  await runList();
9
9
  });
10
10
  program.command("create [branch]").description("Create a new worktree").action(async (branch) => {
11
- const { createWorktree } = await import("./create-YBHDJOP5.js");
11
+ const { createWorktree } = await import("./create-WRMXQIGN.js");
12
12
  await createWorktree(branch);
13
13
  });
14
14
  program.command("agent <branch> <plan_prompt>").description("Create a worktree and auto-start an AI agent in Zed (macOS)").option(
@@ -17,7 +17,7 @@ program.command("agent <branch> <plan_prompt>").description("Create a worktree a
17
17
  "plan"
18
18
  ).action(
19
19
  async (branch, planPrompt, options) => {
20
- const { createAgentWorktree } = await import("./agent-WO3XIT4H.js");
20
+ const { createAgentWorktree } = await import("./agent-CIGIZGIS.js");
21
21
  await createAgentWorktree(branch, planPrompt, { mode: options.mode });
22
22
  }
23
23
  );
@@ -4,8 +4,8 @@ import {
4
4
  openConfiguredIde,
5
5
  prepareWorktree,
6
6
  promptExistingWorktree
7
- } from "./chunk-ASVHQXDJ.js";
8
- import "./chunk-E2IOE23G.js";
7
+ } from "./chunk-BSMGKL27.js";
8
+ import "./chunk-XM4EABZV.js";
9
9
  import "./chunk-FNAMNRUH.js";
10
10
  export {
11
11
  createWorktree,
@@ -9,7 +9,7 @@ import {
9
9
  removeWorktree,
10
10
  runCommands,
11
11
  runInteractiveList
12
- } from "./chunk-E2IOE23G.js";
12
+ } from "./chunk-XM4EABZV.js";
13
13
  import {
14
14
  createStore,
15
15
  getEffectiveConfig
@@ -125,7 +125,7 @@ ${dirty.map((f) => ` ${f}`).join("\n")}`
125
125
  },
126
126
  onCreate: async () => {
127
127
  if (repoRoot) {
128
- const { createWorktree } = await import("./create-YBHDJOP5.js");
128
+ const { createWorktree } = await import("./create-WRMXQIGN.js");
129
129
  await createWorktree(void 0, { cwd: repoRoot, store });
130
130
  }
131
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cestoliv/wt",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Fast, interactive TUI to browse, create, open, and delete git worktrees across repos.",
5
5
  "repository": {
6
6
  "type": "git",