git-worktree-pool 0.0.0-stage → 0.1.3

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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -2
  3. package/dist/bin/wtp.js +5 -0
  4. package/dist/bin/wtp.js.map +1 -0
  5. package/dist/cli/args.js +11 -0
  6. package/dist/cli/args.js.map +1 -0
  7. package/dist/cli/commands/assign.js +41 -0
  8. package/dist/cli/commands/assign.js.map +1 -0
  9. package/dist/cli/commands/delete.js +55 -0
  10. package/dist/cli/commands/delete.js.map +1 -0
  11. package/dist/cli/commands/doctor.js +62 -0
  12. package/dist/cli/commands/doctor.js.map +1 -0
  13. package/dist/cli/commands/free.js +31 -0
  14. package/dist/cli/commands/free.js.map +1 -0
  15. package/dist/cli/commands/help.js +25 -0
  16. package/dist/cli/commands/help.js.map +1 -0
  17. package/dist/cli/commands/init.js +8 -0
  18. package/dist/cli/commands/init.js.map +1 -0
  19. package/dist/cli/commands/list.js +27 -0
  20. package/dist/cli/commands/list.js.map +1 -0
  21. package/dist/cli/commands/path.js +22 -0
  22. package/dist/cli/commands/path.js.map +1 -0
  23. package/dist/cli/commands/setup.js +166 -0
  24. package/dist/cli/commands/setup.js.map +1 -0
  25. package/dist/cli/commands/switch.js +32 -0
  26. package/dist/cli/commands/switch.js.map +1 -0
  27. package/dist/cli/commands/tui.js +19 -0
  28. package/dist/cli/commands/tui.js.map +1 -0
  29. package/dist/cli/explain.js +10 -0
  30. package/dist/cli/explain.js.map +1 -0
  31. package/dist/cli/io.js +56 -0
  32. package/dist/cli/io.js.map +1 -0
  33. package/dist/cli/main.js +82 -0
  34. package/dist/cli/main.js.map +1 -0
  35. package/dist/cli/move.js +42 -0
  36. package/dist/cli/move.js.map +1 -0
  37. package/dist/core/assign.js +52 -0
  38. package/dist/core/assign.js.map +1 -0
  39. package/dist/core/branch.js +78 -0
  40. package/dist/core/branch.js.map +1 -0
  41. package/dist/core/config.js +14 -0
  42. package/dist/core/config.js.map +1 -0
  43. package/dist/core/context.js +38 -0
  44. package/dist/core/context.js.map +1 -0
  45. package/dist/core/delete.js +85 -0
  46. package/dist/core/delete.js.map +1 -0
  47. package/dist/core/doctor.js +32 -0
  48. package/dist/core/doctor.js.map +1 -0
  49. package/dist/core/errors.js +43 -0
  50. package/dist/core/errors.js.map +1 -0
  51. package/dist/core/free.js +51 -0
  52. package/dist/core/free.js.map +1 -0
  53. package/dist/core/git.js +29 -0
  54. package/dist/core/git.js.map +1 -0
  55. package/dist/core/lock.js +70 -0
  56. package/dist/core/lock.js.map +1 -0
  57. package/dist/core/naming.js +47 -0
  58. package/dist/core/naming.js.map +1 -0
  59. package/dist/core/parse.js +69 -0
  60. package/dist/core/parse.js.map +1 -0
  61. package/dist/core/pool.js +141 -0
  62. package/dist/core/pool.js.map +1 -0
  63. package/dist/platform/clipboard.js +39 -0
  64. package/dist/platform/clipboard.js.map +1 -0
  65. package/dist/platform/cwd.js +9 -0
  66. package/dist/platform/cwd.js.map +1 -0
  67. package/dist/platform/launchers.js +154 -0
  68. package/dist/platform/launchers.js.map +1 -0
  69. package/dist/platform/path-search.js +60 -0
  70. package/dist/platform/path-search.js.map +1 -0
  71. package/dist/platform/powershell.js +32 -0
  72. package/dist/platform/powershell.js.map +1 -0
  73. package/dist/platform/process-tree.js +43 -0
  74. package/dist/platform/process-tree.js.map +1 -0
  75. package/dist/platform/run.js +12 -0
  76. package/dist/platform/run.js.map +1 -0
  77. package/dist/platform/shell-init.js +117 -0
  78. package/dist/platform/shell-init.js.map +1 -0
  79. package/dist/tui/App.js +304 -0
  80. package/dist/tui/App.js.map +1 -0
  81. package/dist/tui/AssignPopup.js +12 -0
  82. package/dist/tui/AssignPopup.js.map +1 -0
  83. package/dist/tui/Footer.js +13 -0
  84. package/dist/tui/Footer.js.map +1 -0
  85. package/dist/tui/Help.js +18 -0
  86. package/dist/tui/Help.js.map +1 -0
  87. package/dist/tui/KeyHints.js +7 -0
  88. package/dist/tui/KeyHints.js.map +1 -0
  89. package/dist/tui/PoolTable.js +30 -0
  90. package/dist/tui/PoolTable.js.map +1 -0
  91. package/dist/tui/Popup.js +8 -0
  92. package/dist/tui/Popup.js.map +1 -0
  93. package/dist/tui/fuzzy.js +42 -0
  94. package/dist/tui/fuzzy.js.map +1 -0
  95. package/dist/tui/run.js +40 -0
  96. package/dist/tui/run.js.map +1 -0
  97. package/dist/tui/state.js +30 -0
  98. package/dist/tui/state.js.map +1 -0
  99. package/dist/ui/ansi.js +18 -0
  100. package/dist/ui/ansi.js.map +1 -0
  101. package/dist/ui/glyphs.js +3 -0
  102. package/dist/ui/glyphs.js.map +1 -0
  103. package/dist/ui/labels.js +28 -0
  104. package/dist/ui/labels.js.map +1 -0
  105. package/dist/ui/table.js +116 -0
  106. package/dist/ui/table.js.map +1 -0
  107. package/launchers/wtp +6 -0
  108. package/launchers/wtp.cmd +28 -0
  109. package/launchers/wtp.ps1 +26 -0
  110. package/package.json +70 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yoav Vainrich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # git-worktree-pool
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Work on several branches at once, without a fresh `npm install` for each one.
4
+
5
+ ## Why
6
+
7
+ `git worktree add` gives you a second checkout of a branch in seconds. In a large monorepo, though, the checkout is not where the time goes. A new worktree has no `node_modules`, so you run `npm install` there, and that can take a long time.
8
+
9
+ It is worst on Windows. Antivirus and other IT security tools there often check each file as it is written and hold the write until the check ends, so writing the many files of `node_modules` is slow. On macOS, some of these tools check files after they are written, so the same install finishes sooner.
10
+
11
+ `wtp` keeps a pool of worktrees next to your clone and reuses them, so you pay for that install once per slot, not once per branch. When you finish a branch, wtp frees its slot: it discards the branch's changes but keeps the ignored files, such as `node_modules` and build output. The next branch gets that slot with its dependencies already in place, and a later `npm install` there only has to apply the difference. wtp also moves your shell into the slot, so you can start work at once.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install -g git-worktree-pool
17
+ worktree-pool setup
18
+ ```
19
+
20
+ Requirements: Node 22.12 or later, git 2.31 or later.
21
+
22
+ `worktree-pool setup` gives you the `wtp` command, which moves the shell you type it in. Setup asks before each change. `worktree-pool setup --remove` undoes them.
23
+
24
+ * **cmd and PowerShell:** `wtp` works right after setup. Windows PowerShell 5.1 also needs scripts allowed: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
25
+ * **bash, zsh, fish, Git Bash:** setup adds a `wtp` function to your shell profile. Open a new shell to use it.
26
+
27
+ Without setup, wtp still copies the slot path to the clipboard, and you paste it.
28
+
29
+ ## Quick start
30
+
31
+ ```bash
32
+ cd my-repo
33
+ wtp assign my-feature # gives the branch a slot and moves you there
34
+ wtp switch 0 # back to your clone
35
+ wtp free 1 # done with slot 1: it is free for the next branch
36
+ wtp # or do all of this from the TUI
37
+ ```
38
+
39
+ The pool sits next to your clone:
40
+
41
+ ```
42
+ my-repo/ slot 0, your clone
43
+ my-repo-wt-pool/
44
+ my-repo-wt-1/ slot 1
45
+ my-repo-wt-2/ slot 2
46
+ ```
47
+
48
+ wtp works from the clone, from the pool folder, and from any slot.
49
+
50
+ ## Commands
51
+
52
+ | Command | What it does |
53
+ |---|---|
54
+ | `wtp` | Opens the TUI. |
55
+ | `wtp list`, `wtp ls` | Prints the slot table. `--json` prints the data. `--no-changes` skips the change counts. |
56
+ | `wtp assign <branch>` | Gives the branch a slot, copies the path, and moves the shell there. `--no-cd` only copies. When the branch is already in a slot, wtp offers to switch there. |
57
+ | `wtp switch <index\|branch>` | Copies the slot path and moves the shell there. A branch name must match exactly. It also reaches a worktree outside the pool. |
58
+ | `wtp free <index>` | Asks, then discards uncommitted changes, releases the branch, and marks the slot free. `--yes` skips the question. `--force` frees a locked slot. |
59
+ | `wtp delete <index>` | Asks, then discards uncommitted changes and removes the slot folder. `--yes` skips the question. `--branch` also deletes the local branch. `--force` allows unmerged branches and locked slots. |
60
+ | `wtp path <index\|branch>` | Prints the slot path. |
61
+ | `wtp doctor` | Reports pool problems and repairs the safe ones. |
62
+
63
+ `assign` takes the lowest free slot, or makes a new one. For the branch, it uses the local branch, else the branch on `origin`, else a new branch from your local `main`. wtp does not fetch `main` first.
64
+
65
+ ## TUI keys
66
+
67
+ | Key | Action |
68
+ |---|---|
69
+ | `↑` `↓`, `k` `j` | Move the selection |
70
+ | `0`-`9` | Jump to a slot index |
71
+ | `Enter` | Move the shell to the slot and exit |
72
+ | `a` | Assign a branch. The suggestions leave out branches that a worktree already has. The TUI stays open with the new slot selected; Enter goes there. |
73
+ | `f` | Free the slot |
74
+ | `d` | Delete the slot |
75
+ | `c` | Copy the path |
76
+ | `/` | Filter by branch |
77
+ | `?` | Help |
78
+ | `q`, `Esc` | Quit. If you freed or deleted the slot you are in, quit moves you to the clone. |
79
+
80
+ ## Settings
81
+
82
+ Per-repo settings live in git config:
83
+
84
+ | Key | Default | Meaning |
85
+ |---|---|---|
86
+ | `wtp.base` | `main` | The branch that new branches start from |
87
+ | `wtp.remote` | `origin` | The remote that assign looks at |
88
+
89
+ For example: `git config wtp.base develop`.
90
+
91
+ ## Notes
92
+
93
+ * Slot 0 is your clone. wtp never frees or deletes it.
94
+ * Free and delete always say what they discard before they ask.
95
+ * On Windows, wtp can't delete the slot your shell is in. Run `wtp switch 0` first.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { defaultIo } from "../cli/io.js";
3
+ import { main } from "../cli/main.js";
4
+ process.exitCode = await main(process.argv.slice(2), defaultIo());
5
+ //# sourceMappingURL=wtp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wtp.js","sourceRoot":"","sources":["../../src/bin/wtp.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { UserError } from "../core/errors.js";
2
+ // For "<index|branch>": all digits is a slot index, anything else a branch name.
3
+ export function isIndex(value) {
4
+ return /^\d+$/.test(value);
5
+ }
6
+ export function parseIndex(value, usage) {
7
+ if (value === undefined || !/^\d+$/.test(value))
8
+ throw new UserError(`Usage: ${usage}`);
9
+ return Number(value);
10
+ }
11
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,iFAAiF;AACjF,MAAM,UAAU,OAAO,CAAC,KAAa;IACjC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAyB,EAAE,KAAa;IAC/D,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;IACxF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { assign } from "../../core/assign.js";
2
+ import { resolveContext } from "../../core/context.js";
3
+ import { BranchInUseError, UserError } from "../../core/errors.js";
4
+ import { loadPool } from "../../core/pool.js";
5
+ import { assignSummary } from "../../ui/labels.js";
6
+ import { moveShellTo } from "../move.js";
7
+ import { renderPlainTable } from "./list.js";
8
+ import { canRunTui, tuiCommand } from "./tui.js";
9
+ export async function assignCommand(args, io) {
10
+ const name = args.positionals[0];
11
+ if (!name) {
12
+ if (canRunTui(io))
13
+ return tuiCommand(io, "assign");
14
+ throw new UserError("Usage: wtp assign <branch>");
15
+ }
16
+ const ctx = await resolveContext(io.cwd, io.platform);
17
+ let r;
18
+ try {
19
+ r = await assign(ctx, name);
20
+ }
21
+ catch (e) {
22
+ if (!(e instanceof BranchInUseError) || e.index === null)
23
+ throw e;
24
+ if (!io.stdinIsTTY)
25
+ throw new UserError(`${name} is already in slot ${e.index}. Run: wtp switch ${e.index}`);
26
+ if (!(await io.confirm(`${name} is already in slot ${e.index}. Switch there?`, { defaultYes: true })))
27
+ return 1;
28
+ await moveShellTo(e.path, io, { copy: true, cd: true });
29
+ return 0;
30
+ }
31
+ if (r.createdPoolRoot)
32
+ io.stderr.write(`created the pool folder ${ctx.poolRoot}\n`);
33
+ for (const w of r.warnings)
34
+ io.stderr.write(`! ${w}\n`);
35
+ io.stderr.write(`${assignSummary(name, r)}\n`);
36
+ const cd = !args.values["no-cd"];
37
+ await moveShellTo(r.path, io, { copy: true, cd });
38
+ io.stdout.write(renderPlainTable(await loadPool({ ...ctx, cwd: cd ? r.path : ctx.cwd }, { changes: true }), io));
39
+ return 0;
40
+ }
41
+ //# sourceMappingURL=assign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assign.js","sourceRoot":"","sources":["../../../src/cli/commands/assign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAU,EAAE,EAAM;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACjC,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,IAAI,SAAS,CAAC,EAAE,CAAC;YAAE,OAAO,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QACnD,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEtD,IAAI,CAAC,CAAC;IACN,IAAI,CAAC;QACD,CAAC,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,CAAC,EAAE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AG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACjH,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,55 @@
1
+ import path from "node:path";
2
+ import { resolveContext } from "../../core/context.js";
3
+ import { deleteSlot } from "../../core/delete.js";
4
+ import { UserError } from "../../core/errors.js";
5
+ import { describeLoss, inspectSlot } from "../../core/free.js";
6
+ import { isInside } from "../../core/naming.js";
7
+ import { loadPool, requireSlot } from "../../core/pool.js";
8
+ import { deletedText } from "../../ui/labels.js";
9
+ import { parseIndex } from "../args.js";
10
+ import { showPoolAfter } from "../move.js";
11
+ export async function deleteCommand(args, io) {
12
+ const index = parseIndex(args.positionals[0], "wtp delete <index>");
13
+ const ctx = await resolveContext(io.cwd, io.platform);
14
+ const slot = requireSlot(await loadPool(ctx), index, "delete");
15
+ const inside = isInside(ctx.cwd, slot.path, ctx.platform);
16
+ if (inside && io.platform === "win32") {
17
+ throw new UserError(`You are in slot ${index}. Windows can't delete a folder that a shell is in. Run wtp switch 0 first, then wtp delete ${index}.`);
18
+ }
19
+ const force = Boolean(args.values.force);
20
+ // --yes answers the question below, and that question is "discard and delete?", as in free --yes.
21
+ if (!args.values.yes) {
22
+ io.stderr.write(`Delete slot ${index} (${path.basename(slot.path)}, ${slot.branch ?? slot.state})?\n`);
23
+ if (slot.state === "active") {
24
+ const info = await inspectSlot(slot.path);
25
+ // With --branch --force the branch goes too (git branch -D), so "the branch keeps them" would be false.
26
+ const losesCommits = Boolean(args.values.branch && force && info.unpushed);
27
+ for (const line of describeLoss({ ...info, unpushed: losesCommits ? 0 : info.unpushed }).slice(0, -1)) {
28
+ io.stderr.write(` ${line}\n`);
29
+ }
30
+ if (losesCommits) {
31
+ io.stderr.write(info.unpushed === 1
32
+ ? " 1 commit is not on any remote and is lost with the branch.\n"
33
+ : ` ${info.unpushed} commits are not on any remote and are lost with the branch.\n`);
34
+ }
35
+ }
36
+ io.stderr.write(" The folder is removed from disk.\n");
37
+ if (args.values.branch && slot.branch)
38
+ io.stderr.write(` The local branch ${slot.branch} is deleted too.\n`);
39
+ if (!(await io.confirm("Delete?"))) {
40
+ io.stderr.write("Aborted. Nothing changed.\n");
41
+ return 1;
42
+ }
43
+ }
44
+ const r = await deleteSlot(ctx, index, {
45
+ discard: true,
46
+ unlock: force,
47
+ deleteBranch: args.values.branch ? (force ? "force" : "safe") : false
48
+ });
49
+ for (const w of r.warnings)
50
+ io.stderr.write(`! ${w}\n`);
51
+ io.stderr.write(`${deletedText(index, r.branchDeleted ? r.branch : null)}\n`);
52
+ await showPoolAfter(ctx, slot.path, io);
53
+ return 0;
54
+ }
55
+ //# sourceMappingURL=delete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/cli/commands/delete.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAU,EAAE,EAAM;IAClD,MAAM,KAAK,GAAG,UA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AAI,CAAC,CAAC;IACxD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { resolveContext } from "../../core/context.js";
2
+ import { diagnose, MIN_GIT } from "../../core/doctor.js";
3
+ import { repairPool } from "../../core/pool.js";
4
+ import { LAUNCHER_VERSION, launcherVersion, realFs } from "../../platform/launchers.js";
5
+ import { findOnPath } from "../../platform/path-search.js";
6
+ import { PS51_NOTE, readPs51Policy } from "../../platform/powershell.js";
7
+ import { hasIntegration, profilePath, sessionShell } from "../../platform/shell-init.js";
8
+ import { FUNCTION_HINT } from "../move.js";
9
+ // Says which wtp this shell runs. In bash, zsh, and fish the profile function wins over any file on PATH.
10
+ async function checkWtp(io, deps) {
11
+ const shell = sessionShell(io.platform, io.env, io.home);
12
+ if (shell && (await hasIntegration(shell, io))) {
13
+ io.stdout.write(`wtp -> the wtp function in ${profilePath(shell, io)}\n`);
14
+ return;
15
+ }
16
+ const wins = findOnPath("wtp", { platform: io.platform, env: io.env, isFile: deps.fs.isFile });
17
+ if (!wins) {
18
+ io.stderr.write("! wtp is not set up. Run \"worktree-pool setup\" once.\n");
19
+ return;
20
+ }
21
+ io.stdout.write(`wtp -> ${wins}\n`);
22
+ const version = launcherVersion(wins, deps.fs);
23
+ if (version === null)
24
+ io.stderr.write(`! ${wins} runs as wtp, but it is not a wtp launcher. Run "worktree-pool setup" to see why.\n`);
25
+ else if (version < LAUNCHER_VERSION)
26
+ io.stderr.write(`! The wtp launcher ${wins} is old. Run "worktree-pool setup" to replace it.\n`);
27
+ else if (io.platform !== "win32")
28
+ io.stderr.write(FUNCTION_HINT);
29
+ else if ((await deps.ps51Policy()) === "Restricted")
30
+ io.stderr.write(PS51_NOTE);
31
+ }
32
+ export async function doctorCommand(args, io, deps = { fs: realFs, ps51Policy: () => readPs51Policy() }) {
33
+ await checkWtp(io, deps);
34
+ const ctx = await resolveContext(io.cwd, io.platform);
35
+ const d = await diagnose(ctx);
36
+ if (d.gitTooOld)
37
+ io.stderr.write(`! git ${d.gitVersion} is older than ${MIN_GIT.join(".")}. Update git.\n`);
38
+ if (d.problems.length === 0) {
39
+ io.stdout.write("No problems found.\n");
40
+ return d.gitTooOld ? 1 : 0;
41
+ }
42
+ for (const p of d.problems)
43
+ io.stdout.write(`slot ${p.index}: ${p.problem} (${p.path})\n`);
44
+ let failed = false;
45
+ if (d.problems.some((p) => p.autoFix)) {
46
+ const ok = args.values.yes || (await io.confirm("Repair the problems that wtp can fix?"));
47
+ if (ok) {
48
+ for (const fixed of await repairPool(ctx))
49
+ io.stdout.write(`fixed ${fixed}\n`);
50
+ }
51
+ else {
52
+ io.stdout.write("Nothing changed.\n");
53
+ failed = true;
54
+ }
55
+ }
56
+ for (const p of d.problems.filter((x) => !x.autoFix)) {
57
+ io.stdout.write(`slot ${p.index}: wtp does not touch this folder. Check what it holds, then delete it by hand.\n`);
58
+ failed = true;
59
+ }
60
+ return failed ? 1 : 0;
61
+ }
62
+ //# sourceMappingURL=doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../../src/cli/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAe,MAAM,6BAA6B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE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AC,CAAC;IAC3F,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC,CAAC;QAC1F,IAAI,EAAE,EAAE,CAAC;YACL,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,CAAC,GAAG,CAAC;gBAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;QACnF,CAAC;aACI,CAAC;YACF,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACtC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;IACL,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,kFAAkF,CAAC,CAAC;QACnH,MAAM,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import path from "node:path";
2
+ import { resolveContext } from "../../core/context.js";
3
+ import { describeLoss, free, inspectSlot } from "../../core/free.js";
4
+ import { loadPool, requireSlot } from "../../core/pool.js";
5
+ import { freedText } from "../../ui/labels.js";
6
+ import { parseIndex } from "../args.js";
7
+ import { showPoolAfter } from "../move.js";
8
+ export async function freeCommand(args, io) {
9
+ const index = parseIndex(args.positionals[0], "wtp free <index>");
10
+ const ctx = await resolveContext(io.cwd, io.platform);
11
+ const slot = requireSlot(await loadPool(ctx), index, "free");
12
+ if (slot.state === "free") {
13
+ io.stderr.write(`Slot ${index} is already free.\n`);
14
+ return 0;
15
+ }
16
+ if (slot.state === "active" && !args.values.yes) {
17
+ const info = await inspectSlot(slot.path);
18
+ io.stderr.write(`Free slot ${index} (${path.basename(slot.path)}, ${slot.branch ?? "detached"})?\n`);
19
+ for (const line of describeLoss(info))
20
+ io.stderr.write(` ${line}\n`);
21
+ if (!(await io.confirm("Discard and free?"))) {
22
+ io.stderr.write("Aborted. Nothing changed.\n");
23
+ return 1;
24
+ }
25
+ }
26
+ await free(ctx, index, { force: Boolean(args.values.force) });
27
+ io.stderr.write(`${freedText(index)}\n`);
28
+ await showPoolAfter(ctx, slot.path, io);
29
+ return 0;
30
+ }
31
+ //# sourceMappingURL=free.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"free.js","sourceRoot":"","sources":["../../../src/cli/commands/free.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAU,EAAE,EAAM;IAChD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAClE,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QA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,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ const HELP = `wtp - a pool of reusable git worktrees
2
+
3
+ Usage:
4
+ wtp open the TUI (plain list when not in a terminal)
5
+ wtp list | ls print the slot table [--json] [--no-changes]
6
+ wtp assign <branch> give a branch a slot, copy its path, cd to it [--no-cd]
7
+ wtp switch <index|branch> copy the slot path and cd to it
8
+ wtp free <index> reset a slot and mark it free [--yes] [--force]
9
+ wtp delete <index> remove a slot [--yes] [--branch] [--force]
10
+ wtp path <index|branch> print a slot path
11
+ wtp setup set up the wtp command for your shells, once [--yes] [--remove]
12
+ wtp doctor report and repair pool problems
13
+ wtp help | --help show this help
14
+ wtp --version print the version
15
+
16
+ A branch name must match exactly. Digits always mean a slot index.
17
+
18
+ worktree-pool is the same program, but only wtp can change the shell's folder.
19
+ First time: run "worktree-pool setup" once to get the wtp command.
20
+ `;
21
+ export async function helpCommand(_args, io) {
22
+ io.stdout.write(HELP);
23
+ return 0;
24
+ }
25
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../../../src/cli/commands/help.ts"],"names":[],"mappings":"AAGA,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;CAmBZ,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAW,EAAE,EAAM;IACjD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { initScript, parseShell } from "../../platform/shell-init.js";
2
+ // Plumbing for the profile line that "worktree-pool setup" writes. Shells run it at every start,
3
+ // so this path must not import Ink.
4
+ export async function initCommand(args, io) {
5
+ io.stdout.write(initScript(parseShell(args.positionals[0])));
6
+ return 0;
7
+ }
8
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAItE,iGAAiG;AACjG,oCAAoC;AACpC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAU,EAAE,EAAM;IAChD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { resolveContext } from "../../core/context.js";
2
+ import { chooseSlot, loadPool } from "../../core/pool.js";
3
+ import { colors } from "../../ui/ansi.js";
4
+ import { buildRows, formatTable, nextAssignHint } from "../../ui/table.js";
5
+ export function renderPlainTable(pool, io) {
6
+ const tty = Boolean(io.stdout.isTTY);
7
+ const color = tty && !io.env.NO_COLOR;
8
+ const table = formatTable(buildRows(pool, { showCurrent: tty }), { color, width: tty ? io.stdout.columns : undefined });
9
+ return `${table}\n\n${colors(color).dim(nextAssignHint(pool))}\n`;
10
+ }
11
+ export function poolToJson(pool) {
12
+ return {
13
+ root: pool.ctx.root,
14
+ poolRoot: pool.ctx.poolRoot,
15
+ repoName: pool.ctx.repoName,
16
+ slots: pool.slots,
17
+ external: pool.external,
18
+ nextAssign: chooseSlot(pool)
19
+ };
20
+ }
21
+ export async function listCommand(args, io) {
22
+ const ctx = await resolveContext(io.cwd, io.platform);
23
+ const pool = await loadPool(ctx, { changes: !args.values["no-changes"] });
24
+ io.stdout.write(args.values.json ? JSON.stringify(poolToJson(pool), null, 2) + "\n" : renderPlainTable(pool, io));
25
+ return 0;
26
+ }
27
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/cli/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,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,EAAE,CAAC,QAAQ,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC1E,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAClH,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { requireCheckout } from "../../core/branch.js";
2
+ import { resolveContext } from "../../core/context.js";
3
+ import { UserError } from "../../core/errors.js";
4
+ import { findSlot, loadPool } from "../../core/pool.js";
5
+ import { isIndex, parseIndex } from "../args.js";
6
+ export async function pathCommand(args, io) {
7
+ const target = args.positionals[0];
8
+ if (target === undefined)
9
+ throw new UserError("Usage: wtp path <index|branch>");
10
+ const pool = await loadPool(await resolveContext(io.cwd, io.platform));
11
+ if (!isIndex(target)) {
12
+ io.stdout.write(requireCheckout(pool, target).path + "\n");
13
+ return 0;
14
+ }
15
+ const index = parseIndex(target, "wtp path <index|branch>");
16
+ const slot = findSlot(pool, index);
17
+ if (!slot || slot.state === "broken")
18
+ throw new UserError(`There is no slot ${index}.`);
19
+ io.stdout.write(slot.path + "\n");
20
+ return 0;
21
+ }
22
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/cli/commands/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAU,EAAE,EAAM;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;IAChF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAC3D,OAAO,CAAC,CAAC;IACb,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,oBAAoB,KAAK,GAAG,CAAC,CAAC;IACxF,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,166 @@
1
+ import { rm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { chooseFolder, isCurrentLauncher, isMarked, launcherNames, launcherSourceDir, listMarkedLaunchers, realFs, scanWtp, writeLaunchers } from "../../platform/launchers.js";
4
+ import { findOnPath } from "../../platform/path-search.js";
5
+ import { adminCopy, PS51_NOTE, readPs51Policy } from "../../platform/powershell.js";
6
+ import { parentChain } from "../../platform/process-tree.js";
7
+ import { hasIntegration, installIntegration, profilePath, removeIntegration, SHELLS, shellForSetup } from "../../platform/shell-init.js";
8
+ export function defaultSetupDeps() {
9
+ return {
10
+ fs: realFs,
11
+ srcDir: launcherSourceDir(),
12
+ parents: () => parentChain(process.ppid, { platform: process.platform }),
13
+ ps51Policy: () => readPs51Policy(),
14
+ adminCopy: (files, dir) => adminCopy(files, dir)
15
+ };
16
+ }
17
+ function conflictText(c) {
18
+ switch (c.where) {
19
+ case "before":
20
+ return `! ${c.file} runs as wtp before the launcher would. If it is an old wtp install, uninstall it. Otherwise remove or rename it.\n`;
21
+ case "after":
22
+ return `! The wtp launcher would hide ${c.file}. If it is an old wtp install, uninstall it. Otherwise remove or rename it.\n`;
23
+ case "target":
24
+ return `! ${c.file} is not a wtp launcher, and setup does not overwrite it.\n`;
25
+ }
26
+ }
27
+ function manualText(names, srcDir, dir) {
28
+ const to = dir ?? "<a folder on PATH>";
29
+ const lines = names.map((n) => ` copy "${path.join(srcDir, n)}" "${to}"`);
30
+ return `Copy the wtp launchers by hand into a folder on PATH:\n${lines.join("\n")}\n`;
31
+ }
32
+ async function setupLaunchers(io, deps, ask) {
33
+ const search = { platform: io.platform, env: io.env };
34
+ const names = launcherNames(io.platform);
35
+ const choice = chooseFolder({ ...search, parents: await deps.parents(), fs: deps.fs });
36
+ if (choice.kind === "none") {
37
+ if (io.platform === "win32") {
38
+ io.stderr.write(manualText(names, deps.srcDir, choice.dir));
39
+ return "failed";
40
+ }
41
+ const why = choice.dir ? `${choice.dir} is not writable` : "no folder on PATH holds worktree-pool";
42
+ io.stderr.write(`Skipped the wtp launcher: ${why}. The wtp function in your profile still gives you wtp.\n`);
43
+ return "ok";
44
+ }
45
+ const scan = scanWtp(choice.dir, { ...search, fs: deps.fs });
46
+ if (scan.conflicts.length > 0) {
47
+ for (const c of scan.conflicts)
48
+ io.stderr.write(conflictText(c));
49
+ io.stderr.write("Nothing changed. Remove or rename that file, then run \"worktree-pool setup\" again.\n");
50
+ return "conflict";
51
+ }
52
+ for (const old of scan.stale) {
53
+ if (!(await ask(`Remove the old wtp launcher ${old}?`)))
54
+ continue;
55
+ await rm(old, { force: true });
56
+ io.stderr.write(`removed ${old}\n`);
57
+ }
58
+ const pending = names.filter((n) => !isCurrentLauncher(path.join(choice.dir, n), deps.fs));
59
+ if (pending.length === 0) {
60
+ io.stderr.write(`The wtp launchers in ${choice.dir} are up to date.\n`);
61
+ return "ok";
62
+ }
63
+ if (choice.kind === "admin") {
64
+ io.stderr.write(`${choice.dir} is locked for your account.\n`);
65
+ const asked = await ask(`Copy ${pending.join(", ")} there as administrator? Windows asks for permission.`);
66
+ if (asked)
67
+ await deps.adminCopy(pending.map((n) => path.join(deps.srcDir, n)), choice.dir);
68
+ // Trust the files, not the exit code: a declined UAC prompt can still exit 0.
69
+ if (asked && pending.every((n) => isCurrentLauncher(path.join(choice.dir, n), deps.fs))) {
70
+ for (const n of pending)
71
+ io.stderr.write(`wrote ${path.join(choice.dir, n)}\n`);
72
+ return "ok";
73
+ }
74
+ if (asked)
75
+ io.stderr.write("The administrator copy did not finish.\n");
76
+ io.stderr.write(manualText(pending, deps.srcDir, choice.dir));
77
+ return "failed";
78
+ }
79
+ if (!(await ask(`Write ${pending.join(", ")} to ${choice.dir}?`))) {
80
+ io.stderr.write("Skipped the wtp launchers.\n");
81
+ return "failed";
82
+ }
83
+ for (const r of await writeLaunchers(choice.dir, pending, { platform: io.platform, srcDir: deps.srcDir })) {
84
+ io.stderr.write(`${r.action} ${r.file}\n`);
85
+ }
86
+ return "ok";
87
+ }
88
+ async function install(io, deps, ask) {
89
+ const launchers = await setupLaunchers(io, deps, ask);
90
+ if (launchers === "conflict")
91
+ return 1;
92
+ let ok = launchers === "ok";
93
+ const shell = shellForSetup(io.platform, io.env, io.home);
94
+ let profileChanged = false;
95
+ if (shell) {
96
+ const file = profilePath(shell, io);
97
+ const r = await installIntegration(shell, { home: io.home, env: io.env, confirm: ask, log: (s) => {
98
+ io.stderr.write(s);
99
+ } });
100
+ if (r === "already")
101
+ io.stderr.write(`${file} already has the wtp function.\n`);
102
+ else if (r === "installed") {
103
+ io.stderr.write(`added the wtp function to ${file}\n`);
104
+ profileChanged = true;
105
+ }
106
+ else {
107
+ io.stderr.write(`Skipped ${file}.\n`);
108
+ ok = false;
109
+ }
110
+ }
111
+ const wins = findOnPath("wtp", { platform: io.platform, env: io.env, isFile: deps.fs.isFile });
112
+ if (wins) {
113
+ if (isMarked(wins, deps.fs))
114
+ io.stderr.write(`wtp runs ${wins}\n`);
115
+ else {
116
+ io.stderr.write(`! wtp runs ${wins}, which is not a wtp launcher. Check your PATH.\n`);
117
+ ok = false;
118
+ }
119
+ }
120
+ if (profileChanged)
121
+ io.stderr.write("Open a new terminal, or reload your profile, to use the wtp function.\n");
122
+ if (io.platform === "win32" && (await deps.ps51Policy()) === "Restricted")
123
+ io.stderr.write(PS51_NOTE);
124
+ return ok ? 0 : 1;
125
+ }
126
+ async function removeAll(io, deps, ask) {
127
+ const files = listMarkedLaunchers({ platform: io.platform, env: io.env, fs: deps.fs });
128
+ const shells = [];
129
+ for (const s of SHELLS)
130
+ if (await hasIntegration(s, io))
131
+ shells.push(s);
132
+ if (files.length === 0 && shells.length === 0) {
133
+ io.stderr.write("Nothing to remove.\n");
134
+ return 0;
135
+ }
136
+ const list = [...files, ...shells.map((s) => `the wtp function in ${profilePath(s, io)}`)];
137
+ io.stderr.write(`wtp setup removes:\n${list.map((x) => ` ${x}`).join("\n")}\n`);
138
+ if (!(await ask("Remove them?"))) {
139
+ io.stderr.write("Nothing changed.\n");
140
+ return 1;
141
+ }
142
+ let ok = true;
143
+ for (const f of files) {
144
+ try {
145
+ await rm(f);
146
+ io.stderr.write(`removed ${f}\n`);
147
+ }
148
+ catch {
149
+ io.stderr.write(`! Could not remove ${f}. It may need administrator rights.\n`);
150
+ ok = false;
151
+ }
152
+ }
153
+ for (const s of shells) {
154
+ const f = await removeIntegration(s, io);
155
+ if (f)
156
+ io.stderr.write(`removed the wtp function from ${f}\n`);
157
+ }
158
+ return ok ? 0 : 1;
159
+ }
160
+ export async function setupCommand(args, io, deps = defaultSetupDeps()) {
161
+ // The user ran setup to get these files, so Enter means yes. Removal keeps the safe default, no.
162
+ const defaultYes = !args.values.remove;
163
+ const ask = (q) => (args.values.yes ? Promise.resolve(true) : io.confirm(q, { defaultYes }));
164
+ return args.values.remove ? removeAll(io, deps, ask) : install(io, deps, ask);
165
+ }
166
+ //# sourceMappingURL=setup.js.map