@n-seiji/hop 0.0.0-stage → 0.2.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.
package/README.ja.md ADDED
@@ -0,0 +1,90 @@
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
3
+ <img src="docs/assets/logo-light.svg" alt="hop" width="210">
4
+ </picture>
5
+
6
+ [English](README.md) · **日本語**
7
+
8
+ **git worktree を、作る・移る・消す。ぜんぶ `hop` ひとつで。**
9
+
10
+ `hop` は、人間と AI coding agent のための zero-setup な git worktree manager。設定も状態ファイルもいらない。[Web サイト](https://www.sijis.me/work/hop)
11
+
12
+ <table>
13
+ <tr>
14
+ <td align="center" valign="top" width="33%">
15
+ <img src="docs/assets/tile-create.svg" width="200" alt="worktree を作る"><br>
16
+ <b>作る</b><br>
17
+ <sub>branch も worktree も、その場で。</sub>
18
+ </td>
19
+ <td align="center" valign="top" width="33%">
20
+ <img src="docs/assets/tile-jump.svg" width="200" alt="worktree へ移る"><br>
21
+ <b>移る</b><br>
22
+ <sub><code>hop</code> で選び、<code>hop -</code> で戻る。</sub>
23
+ </td>
24
+ <td align="center" valign="top" width="33%">
25
+ <img src="docs/assets/tile-remove.svg" width="200" alt="worktree を消す"><br>
26
+ <b>消す</b><br>
27
+ <sub>1 つずつ、または merge 済みをまとめて。</sub>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ curl -fsSL https://raw.githubusercontent.com/n-seiji/hop/main/install.sh | sh
36
+ ```
37
+
38
+ 続けて `~/.zshrc` に次を足すと、`hop` が `cd` までしてくれる。
39
+
40
+ ```sh
41
+ eval "$(hop init zsh)"
42
+ ```
43
+
44
+ npm、mise、Linux arm64、バイナリの検証、更新については [ガイド](docs/guide.ja.md#install) を参照。
45
+
46
+ ## 使い方
47
+
48
+ | コマンド | 動作 |
49
+ |---|---|
50
+ | `hop` | worktree/branch を対話的に選んで `cd` |
51
+ | `hop <branch>` | その branch の worktree へ `cd` |
52
+ | `hop <branch> --create` | 未作成ならその場で worktree を作成 |
53
+ | `hop -` | 直前の worktree へ戻る |
54
+ | `hop root` | root clone へ `cd` |
55
+ | `hop ls [--json]` | worktree 一覧 (dirty, ahead/behind, kind) |
56
+ | `hop rm <branch>` | worktree を削除 (branch は残す) |
57
+ | `hop clean` | ゴミ worktree を自動判定して削除 (既定では managed のみ) |
58
+ | `hop --update` | standalone バイナリを最新リリースへ置換 |
59
+
60
+ picker とそのキー、`hop root <branch>` などは [ガイド](docs/guide.ja.md#使い方) にある。
61
+
62
+ ## 安全がデフォルト
63
+
64
+ - `hop rm` は、`--force` を付けない限り dirty な worktree を拒否する。`hop clean` と `hop root` は dirty な worktree に触れない。
65
+ - git が locked と報告する worktree は、`--force` でも削除しない。
66
+ - `_worktree/<repo>/` の外にある (external) worktree を picker から削除するときは y/N を確認する。Ctrl+X は常に確認する。
67
+ - `hop clean` が既定で対象にするのは、hop が管理する worktree だけ。external は `--ext` を付けたときだけ対象になる。
68
+ - `hop rm` は branch を残す。
69
+
70
+ ## AI coding agent 向け
71
+
72
+ 全コマンドが非対話で完結する。`--json` はどこでも使え、path は stdout、ログは stderr に出る。このリポジトリは [`using-hop`](plugins/hop/skills/using-hop/SKILL.md) skill を plugin として配布している。agent が `hop` を安全に使うための skill。
73
+
74
+ ```sh
75
+ # Claude Code
76
+ /plugin marketplace add n-seiji/hop
77
+ /plugin install hop@hop
78
+
79
+ # Codex
80
+ codex plugin marketplace add n-seiji/hop
81
+ codex plugin install hop
82
+ ```
83
+
84
+ ## その他
85
+
86
+ - [Web サイト](https://www.sijis.me/work/hop)
87
+ - [ガイド](docs/guide.ja.md): 使い方、picker、インストール、更新、トラブルシューティング
88
+ - [docs/design.md](docs/design.md): 設計書
89
+ - [AGENTS.md](AGENTS.md): このリポジトリで作業する coding agent 向けガイド
90
+ - [LICENSE](LICENSE): GPL-3.0
package/README.md CHANGED
@@ -1,3 +1,90 @@
1
- # Temporary Holding Version
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
3
+ <img src="docs/assets/logo-light.svg" alt="hop" width="210">
4
+ </picture>
2
5
 
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.
6
+ **English** · [日本語](README.ja.md)
7
+
8
+ **Create, jump between, and remove git worktrees. All with `hop`.**
9
+
10
+ `hop` is a zero-setup git worktree manager for humans and AI coding agents. It needs no config and no state files. [Website](https://www.sijis.me/en/work/hop)
11
+
12
+ <table>
13
+ <tr>
14
+ <td align="center" valign="top" width="33%">
15
+ <img src="docs/assets/tile-create.svg" width="200" alt="Create a worktree"><br>
16
+ <b>Create</b><br>
17
+ <sub>The branch and its worktree, on the spot.</sub>
18
+ </td>
19
+ <td align="center" valign="top" width="33%">
20
+ <img src="docs/assets/tile-jump.svg" width="200" alt="Jump between worktrees"><br>
21
+ <b>Jump</b><br>
22
+ <sub><code>hop</code> to pick, <code>hop -</code> to go back.</sub>
23
+ </td>
24
+ <td align="center" valign="top" width="33%">
25
+ <img src="docs/assets/tile-remove.svg" width="200" alt="Remove a worktree"><br>
26
+ <b>Remove</b><br>
27
+ <sub>One at a time, or clean up what's merged.</sub>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ curl -fsSL https://raw.githubusercontent.com/n-seiji/hop/main/install.sh | sh
36
+ ```
37
+
38
+ Then add this to `~/.zshrc` so `hop` can `cd` for you:
39
+
40
+ ```sh
41
+ eval "$(hop init zsh)"
42
+ ```
43
+
44
+ For npm, mise, Linux arm64, verifying binaries, and updating, see the [guide](docs/guide.md#install).
45
+
46
+ ## Usage
47
+
48
+ | Command | What it does |
49
+ |---|---|
50
+ | `hop` | Pick a worktree or branch interactively and `cd` into it |
51
+ | `hop <branch>` | `cd` into the branch's worktree |
52
+ | `hop <branch> --create` | Create the worktree if it is missing |
53
+ | `hop -` | `cd` back to the previous worktree |
54
+ | `hop root` | `cd` into the root clone |
55
+ | `hop ls [--json]` | List worktrees (dirty, ahead/behind, kind) |
56
+ | `hop rm <branch>` | Remove a worktree. The branch is kept |
57
+ | `hop clean` | Find and remove garbage worktrees (managed only by default) |
58
+ | `hop --update` | Replace a standalone binary with the latest release |
59
+
60
+ The [guide](docs/guide.md#usage) covers the picker and its keys, `hop root <branch>`, and the rest.
61
+
62
+ ## Safe by default
63
+
64
+ - `hop rm` refuses a dirty worktree unless you pass `--force`. `hop clean` and `hop root` never touch one.
65
+ - A worktree that git reports as locked is never removed, even with `--force`.
66
+ - Deleting an external worktree (one not under `_worktree/<repo>/`) from the picker asks y/N. Ctrl+X always asks.
67
+ - By default, `hop clean` only picks worktrees that hop manages. External ones need `--ext`.
68
+ - `hop rm` keeps the branch.
69
+
70
+ ## For AI coding agents
71
+
72
+ Every command can complete non-interactively. `--json` works everywhere, paths go to stdout, and logs go to stderr. The repo ships the [`using-hop`](plugins/hop/skills/using-hop/SKILL.md) skill as a plugin. It teaches agents to drive `hop` safely.
73
+
74
+ ```sh
75
+ # Claude Code
76
+ /plugin marketplace add n-seiji/hop
77
+ /plugin install hop@hop
78
+
79
+ # Codex
80
+ codex plugin marketplace add n-seiji/hop
81
+ codex plugin install hop
82
+ ```
83
+
84
+ ## More
85
+
86
+ - [Website](https://www.sijis.me/en/work/hop)
87
+ - [Guide](docs/guide.md): usage, picker, install, updating, troubleshooting
88
+ - [docs/design.md](docs/design.md): the design document
89
+ - [AGENTS.md](AGENTS.md): guide for coding agents working on this repo
90
+ - [LICENSE](LICENSE): GPL-3.0
@@ -0,0 +1,262 @@
1
+ import {
2
+ messageOf,
3
+ describeFatalError
4
+ } from "./cli-n74f2vav.js";
5
+ import {
6
+ upstreamStateOf
7
+ } from "./cli-btqjpf1q.js";
8
+ import {
9
+ withRepoLock
10
+ } from "./cli-h17ydkz8.js";
11
+ import {
12
+ isOptionLikeRef,
13
+ loadRepoContext,
14
+ nestedWorktrees,
15
+ worktreeDirtyState
16
+ } from "./cli-4f1vz23g.js";
17
+ import {
18
+ EXIT_USAGE_ERROR,
19
+ ok,
20
+ fail
21
+ } from "./cli-77yanq37.js";
22
+
23
+ // src/domain/garbage.ts
24
+ var classifyGarbage = (input) => {
25
+ if (input.prunable) {
26
+ return "prunable";
27
+ }
28
+ if (!input.clean) {
29
+ return null;
30
+ }
31
+ if (input.mergedIntoDefault === true) {
32
+ return "merged";
33
+ }
34
+ if (input.upstreamGone && input.allCommitsReachableFromDefault === true) {
35
+ return "gone";
36
+ }
37
+ return null;
38
+ };
39
+
40
+ // src/commands/clean-candidates.ts
41
+ var buildCleanCandidates = async (git, fs, context, ext) => {
42
+ const [defaultRef, upstreams] = await Promise.all([
43
+ git.resolveDefaultBranchRef(context.rootPath),
44
+ git.upstreamStates(context.rootPath)
45
+ ]);
46
+ const targets = context.worktrees.filter((wt) => (wt.kind === "managed" || ext && wt.kind === "external") && !(wt.branch !== null && isOptionLikeRef(wt.branch)));
47
+ const results = await Promise.all(targets.map(async (wt) => {
48
+ const reason = await classifyWorktree(wt, {
49
+ git,
50
+ fs,
51
+ defaultRef,
52
+ upstreams,
53
+ context
54
+ });
55
+ if (reason === null) {
56
+ return null;
57
+ }
58
+ return { branch: wt.branch ?? "", path: wt.path, reason };
59
+ }));
60
+ return results.filter((candidate) => candidate !== null);
61
+ };
62
+ var branchMergeFacts = async (git, rootPath, branch, { defaultRef, upstreams }) => {
63
+ const upstreamGone = upstreamStateOf(upstreams, branch).kind === "gone";
64
+ const mergedIntoDefault = defaultRef === null ? "unknown" : await git.isAncestor(rootPath, branch, defaultRef);
65
+ const allCommitsReachableFromDefault = defaultRef === null || mergedIntoDefault === true || !upstreamGone ? "unknown" : await git.hasEquivalentCommits(rootPath, branch, defaultRef);
66
+ return {
67
+ prunable: false,
68
+ upstreamGone,
69
+ mergedIntoDefault,
70
+ allCommitsReachableFromDefault
71
+ };
72
+ };
73
+ var classifyWorktree = async (wt, { git, fs, defaultRef, upstreams, context }) => {
74
+ if (wt.prunable) {
75
+ return classifyGarbage({
76
+ prunable: true,
77
+ clean: false,
78
+ mergedIntoDefault: "unknown",
79
+ upstreamGone: false,
80
+ allCommitsReachableFromDefault: "unknown"
81
+ });
82
+ }
83
+ if (wt.branch === null) {
84
+ return null;
85
+ }
86
+ const { rootPath, worktrees } = context;
87
+ const facts = await branchMergeFacts(git, rootPath, wt.branch, {
88
+ defaultRef,
89
+ upstreams
90
+ });
91
+ if (classifyGarbage({ ...facts, clean: true }) === null) {
92
+ return null;
93
+ }
94
+ const dirtyState = await worktreeDirtyState(git, fs, worktrees, wt);
95
+ const input = { ...facts, clean: dirtyState === false };
96
+ return classifyGarbage(input);
97
+ };
98
+
99
+ // src/commands/clean.ts
100
+ var clean = async (git, fs, term, options) => {
101
+ const context = await loadRepoContext(git, fs, options.cwd);
102
+ const { removable: candidates, lockedWarnings } = withoutLocked(await buildCleanCandidates(git, fs, context, options.ext), context.worktrees);
103
+ const warningsField = lockedWarnings.length === 0 ? {} : { warnings: lockedWarnings };
104
+ if (options.dryRun) {
105
+ return ok({ data: { candidates }, ...warningsField });
106
+ }
107
+ if (candidates.length === 0) {
108
+ return ok({ data: { candidates, removed: [] }, ...warningsField });
109
+ }
110
+ if (!options.yes) {
111
+ if (!term.isTTY()) {
112
+ return fail(EXIT_USAGE_ERROR, "hop clean would remove worktrees; re-run with --yes (non-interactive) or --dry-run to only list candidates.");
113
+ }
114
+ for (const candidate of candidates) {
115
+ term.logStderr(`${candidate.reason} ${candidate.branch} ${candidate.path}`);
116
+ }
117
+ const confirmed = await term.confirm(`Remove ${candidates.length} worktree(s) above?`);
118
+ if (!confirmed) {
119
+ return ok({ data: { candidates, removed: [] }, ...warningsField });
120
+ }
121
+ }
122
+ return executeClean({
123
+ git,
124
+ fs,
125
+ term,
126
+ context,
127
+ candidates,
128
+ cleanOptions: options,
129
+ initialWarnings: lockedWarnings
130
+ });
131
+ };
132
+ var lockedWarning = (wt) => `Skipped ${wt.path}: locked by git${wt.lockReason === null ? "" : ` (${wt.lockReason})`}. hop never unlocks worktrees automatically — run "git worktree unlock" yourself first if you're sure.`;
133
+ var withoutLocked = (candidates, worktrees) => {
134
+ const byPath = new Map(worktrees.map((wt) => [wt.path, wt]));
135
+ const removable = [];
136
+ const lockedWarnings = [];
137
+ for (const candidate of candidates) {
138
+ const wt = byPath.get(candidate.path);
139
+ if (wt?.locked === true) {
140
+ lockedWarnings.push(lockedWarning(wt));
141
+ } else {
142
+ removable.push(candidate);
143
+ }
144
+ }
145
+ return { removable, lockedWarnings };
146
+ };
147
+ var removeCandidate = async ({
148
+ git,
149
+ rootPath,
150
+ candidate,
151
+ deleteBranch,
152
+ worktrees
153
+ }) => {
154
+ if (nestedWorktrees(worktrees, candidate.path).length > 0) {
155
+ return {
156
+ kind: "skipped",
157
+ warning: `Skipped ${candidate.path}: still contains a registered worktree.`
158
+ };
159
+ }
160
+ const wt = worktrees.find((entry) => entry.path === candidate.path);
161
+ if (wt?.locked === true) {
162
+ return { kind: "skipped", warning: lockedWarning(wt) };
163
+ }
164
+ try {
165
+ await git.removeWorktree(rootPath, candidate.path, false);
166
+ } catch (error) {
167
+ return {
168
+ kind: "skipped",
169
+ warning: `Failed to remove ${candidate.path}: ${describeFatalError(error).message}`
170
+ };
171
+ }
172
+ if (deleteBranch && candidate.branch.length > 0) {
173
+ try {
174
+ await git.deleteBranch(rootPath, candidate.branch);
175
+ } catch (error) {
176
+ return {
177
+ kind: "removed",
178
+ warning: `Removed ${candidate.path} but kept branch "${candidate.branch}": ${describeFatalError(error).message}`
179
+ };
180
+ }
181
+ }
182
+ return { kind: "removed" };
183
+ };
184
+ var canDeletePrunableBranch = async (git, rootPath, candidate, facts) => {
185
+ if (candidate.reason !== "prunable") {
186
+ return true;
187
+ }
188
+ if (candidate.branch.length === 0) {
189
+ return false;
190
+ }
191
+ try {
192
+ const branchFacts = await branchMergeFacts(git, rootPath, candidate.branch, facts);
193
+ return classifyGarbage({ ...branchFacts, clean: true }) !== null;
194
+ } catch {
195
+ return false;
196
+ }
197
+ };
198
+ var executeClean = ({
199
+ git,
200
+ fs,
201
+ term,
202
+ context,
203
+ candidates,
204
+ cleanOptions,
205
+ initialWarnings
206
+ }) => withRepoLock(context.commonDir, async () => {
207
+ try {
208
+ const fresh = await loadRepoContext(git, fs, context.rootPath);
209
+ const freshCandidates = await buildCleanCandidates(git, fs, fresh, cleanOptions.ext);
210
+ const freshByPath = new Map(freshCandidates.map((candidate) => [candidate.path, candidate]));
211
+ const warnings = [...initialWarnings];
212
+ const stillValid = candidates.flatMap((candidate) => {
213
+ const freshCandidate = freshByPath.get(candidate.path);
214
+ if (freshCandidate === undefined) {
215
+ warnings.push(`Skipped ${candidate.path}: no longer a clean-up candidate.`);
216
+ return [];
217
+ }
218
+ return [freshCandidate];
219
+ });
220
+ const [defaultRef, upstreams] = await Promise.all([
221
+ git.resolveDefaultBranchRef(fresh.rootPath),
222
+ git.upstreamStates(fresh.rootPath)
223
+ ]);
224
+ const removed = [];
225
+ for (const [index, candidate] of stillValid.entries()) {
226
+ const branchSafe = await canDeletePrunableBranch(git, fresh.rootPath, candidate, {
227
+ defaultRef,
228
+ upstreams
229
+ });
230
+ const deleteBranch = cleanOptions.withBranch && branchSafe;
231
+ if (cleanOptions.withBranch && candidate.reason === "prunable" && candidate.branch.length > 0 && !branchSafe) {
232
+ warnings.push(`Keeping branch "${candidate.branch}": prunable worktree is not confirmed merged or gone.`);
233
+ }
234
+ const label = candidate.branch.length > 0 ? candidate.branch : candidate.path;
235
+ term.logStderr(`[${index + 1}/${stillValid.length}] removing ${label}`);
236
+ const outcome = await removeCandidate({
237
+ git,
238
+ rootPath: fresh.rootPath,
239
+ candidate,
240
+ deleteBranch,
241
+ worktrees: fresh.worktrees
242
+ });
243
+ if (outcome.kind === "removed") {
244
+ removed.push(candidate.branch);
245
+ }
246
+ if (outcome.warning !== undefined) {
247
+ warnings.push(outcome.warning);
248
+ }
249
+ }
250
+ return ok({
251
+ data: { candidates: [...candidates], removed },
252
+ ...warnings.length === 0 ? {} : { warnings }
253
+ });
254
+ } catch (error) {
255
+ throw new Error(`Failed to clean worktrees: ${messageOf(error)}`, {
256
+ cause: error
257
+ });
258
+ }
259
+ });
260
+ export {
261
+ clean
262
+ };
@@ -0,0 +1,143 @@
1
+ // src/domain/display-width.ts
2
+ var WIDTH_ZERO = 0;
3
+ var WIDTH_NARROW = 1;
4
+ var WIDTH_WIDE = 2;
5
+ var segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
6
+ var ZERO_WIDTH_JOINER = 8205;
7
+ var VARIATION_SELECTOR_TEXT = 65038;
8
+ var VARIATION_SELECTOR_EMOJI = 65039;
9
+ var ZERO_WIDTH_CODE_POINTS = new Set([
10
+ ZERO_WIDTH_JOINER,
11
+ VARIATION_SELECTOR_TEXT,
12
+ VARIATION_SELECTOR_EMOJI
13
+ ]);
14
+ var isCombiningMark = (codePoint) => /\p{M}/u.test(String.fromCodePoint(codePoint));
15
+ var HANGUL_JAMO_START = 4352;
16
+ var HANGUL_JAMO_END = 4447;
17
+ var CJK_RADICALS_START = 11904;
18
+ var CJK_SYMBOLS_END = 12350;
19
+ var HIRAGANA_START = 12353;
20
+ var CJK_COMPATIBILITY_END = 13311;
21
+ var CJK_EXT_A_START = 13312;
22
+ var CJK_EXT_A_END = 19903;
23
+ var CJK_UNIFIED_START = 19968;
24
+ var CJK_UNIFIED_END = 40959;
25
+ var YI_SYLLABLES_START = 40960;
26
+ var YI_SYLLABLES_END = 42191;
27
+ var HANGUL_SYLLABLES_START = 44032;
28
+ var HANGUL_SYLLABLES_END = 55203;
29
+ var CJK_COMPAT_IDEOGRAPHS_START = 63744;
30
+ var CJK_COMPAT_IDEOGRAPHS_END = 64255;
31
+ var CJK_COMPAT_FORMS_START = 65072;
32
+ var CJK_COMPAT_FORMS_END = 65103;
33
+ var FULLWIDTH_FORMS_START = 65280;
34
+ var FULLWIDTH_FORMS_END = 65376;
35
+ var FULLWIDTH_SIGNS_START = 65504;
36
+ var FULLWIDTH_SIGNS_END = 65510;
37
+ var EMOJI_MISC_START = 127744;
38
+ var EMOJI_MISC_END = 128591;
39
+ var EMOJI_TRANSPORT_START = 128640;
40
+ var EMOJI_TRANSPORT_END = 129535;
41
+ var CJK_EXT_B_START = 131072;
42
+ var CJK_EXT_B_END = 262141;
43
+ var WIDE_RANGES = [
44
+ [HANGUL_JAMO_START, HANGUL_JAMO_END],
45
+ [CJK_RADICALS_START, CJK_SYMBOLS_END],
46
+ [HIRAGANA_START, CJK_COMPATIBILITY_END],
47
+ [CJK_EXT_A_START, CJK_EXT_A_END],
48
+ [CJK_UNIFIED_START, CJK_UNIFIED_END],
49
+ [YI_SYLLABLES_START, YI_SYLLABLES_END],
50
+ [HANGUL_SYLLABLES_START, HANGUL_SYLLABLES_END],
51
+ [CJK_COMPAT_IDEOGRAPHS_START, CJK_COMPAT_IDEOGRAPHS_END],
52
+ [CJK_COMPAT_FORMS_START, CJK_COMPAT_FORMS_END],
53
+ [FULLWIDTH_FORMS_START, FULLWIDTH_FORMS_END],
54
+ [FULLWIDTH_SIGNS_START, FULLWIDTH_SIGNS_END],
55
+ [EMOJI_MISC_START, EMOJI_MISC_END],
56
+ [EMOJI_TRANSPORT_START, EMOJI_TRANSPORT_END],
57
+ [CJK_EXT_B_START, CJK_EXT_B_END]
58
+ ];
59
+ var isWide = (codePoint) => WIDE_RANGES.some(([start, end]) => codePoint >= start && codePoint <= end);
60
+ var codePointWidth = (codePoint) => {
61
+ if (ZERO_WIDTH_CODE_POINTS.has(codePoint) || isCombiningMark(codePoint)) {
62
+ return WIDTH_ZERO;
63
+ }
64
+ return isWide(codePoint) ? WIDTH_WIDE : WIDTH_NARROW;
65
+ };
66
+ var graphemeWidth = (grapheme) => {
67
+ const codePoints = Array.from(grapheme, (char) => char.codePointAt(0)).filter((codePoint) => codePoint !== undefined);
68
+ return codePoints.reduce((max, codePoint) => Math.max(max, codePointWidth(codePoint)), WIDTH_ZERO);
69
+ };
70
+ var graphemes = (value) => Array.from(segmenter.segment(value), (entry) => entry.segment);
71
+ var displayWidth = (value) => graphemes(value).reduce((total, grapheme) => total + graphemeWidth(grapheme), WIDTH_ZERO);
72
+ var padToWidth = (value, width) => {
73
+ const current = displayWidth(value);
74
+ return current >= width ? value : value + " ".repeat(width - current);
75
+ };
76
+ var DEFAULT_ELLIPSIS = "…";
77
+ var takeWithinWidth = (clusters, budget) => {
78
+ const taken = [];
79
+ let usedWidth = WIDTH_ZERO;
80
+ for (const grapheme of clusters) {
81
+ const nextWidth = usedWidth + graphemeWidth(grapheme);
82
+ if (nextWidth > budget) {
83
+ break;
84
+ }
85
+ taken.push(grapheme);
86
+ usedWidth = nextWidth;
87
+ }
88
+ return taken;
89
+ };
90
+ var truncateToWidth = (value, width, ellipsis = DEFAULT_ELLIPSIS) => {
91
+ if (displayWidth(value) <= width) {
92
+ return value;
93
+ }
94
+ const budget = width - displayWidth(ellipsis);
95
+ if (budget < WIDTH_ZERO) {
96
+ return "";
97
+ }
98
+ return takeWithinWidth(graphemes(value), budget).join("") + ellipsis;
99
+ };
100
+ var truncateToWidthKeepingTail = (value, width, ellipsis = DEFAULT_ELLIPSIS) => {
101
+ if (displayWidth(value) <= width) {
102
+ return value;
103
+ }
104
+ const budget = width - displayWidth(ellipsis);
105
+ if (budget < WIDTH_ZERO) {
106
+ return "";
107
+ }
108
+ const keptFromEnd = takeWithinWidth(graphemes(value).toReversed(), budget);
109
+ return ellipsis + keptFromEnd.toReversed().join("");
110
+ };
111
+
112
+ // src/domain/ansi.ts
113
+ var ESC = "\x1B";
114
+ var SGR = {
115
+ bold: `${ESC}[1m`,
116
+ dim: `${ESC}[2m`,
117
+ inverse: `${ESC}[7m`,
118
+ red: `${ESC}[31m`,
119
+ green: `${ESC}[32m`,
120
+ yellow: `${ESC}[33m`,
121
+ magenta: `${ESC}[35m`,
122
+ cyan: `${ESC}[36m`
123
+ };
124
+ var SGR_RESET = `${ESC}[0m`;
125
+
126
+ // src/domain/worktree-state.ts
127
+ var worktreeState = (worktree, dirty) => {
128
+ if (worktree.prunable) {
129
+ return { text: "✗ missing", tone: "red" };
130
+ }
131
+ if (worktree.locked) {
132
+ return { text: "⊘ locked", tone: "red" };
133
+ }
134
+ if (worktree.bare) {
135
+ return { text: "- bare", tone: "dim" };
136
+ }
137
+ if (dirty === null) {
138
+ return { text: "✗ missing", tone: "red" };
139
+ }
140
+ return dirty ? { text: "● changes", tone: "yellow" } : { text: "✓ clean", tone: "green" };
141
+ };
142
+
143
+ export { graphemes, displayWidth, padToWidth, truncateToWidth, truncateToWidthKeepingTail, ESC, SGR, SGR_RESET, worktreeState };