webmux 0.7.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.
package/bin/webmux.js ADDED
@@ -0,0 +1,1507 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var __create = Object.create;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __toESM = (mod, isNodeMode, target) => {
9
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
10
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
+ for (let key of __getOwnPropNames(mod))
12
+ if (!__hasOwnProp.call(to, key))
13
+ __defProp(to, key, {
14
+ get: () => mod[key],
15
+ enumerable: true
16
+ });
17
+ return to;
18
+ };
19
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
+
31
+ // node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
32
+ var require_src = __commonJS((exports, module) => {
33
+ var ESC = "\x1B";
34
+ var CSI = `${ESC}[`;
35
+ var beep = "\x07";
36
+ var cursor = {
37
+ to(x, y) {
38
+ if (!y)
39
+ return `${CSI}${x + 1}G`;
40
+ return `${CSI}${y + 1};${x + 1}H`;
41
+ },
42
+ move(x, y) {
43
+ let ret = "";
44
+ if (x < 0)
45
+ ret += `${CSI}${-x}D`;
46
+ else if (x > 0)
47
+ ret += `${CSI}${x}C`;
48
+ if (y < 0)
49
+ ret += `${CSI}${-y}A`;
50
+ else if (y > 0)
51
+ ret += `${CSI}${y}B`;
52
+ return ret;
53
+ },
54
+ up: (count = 1) => `${CSI}${count}A`,
55
+ down: (count = 1) => `${CSI}${count}B`,
56
+ forward: (count = 1) => `${CSI}${count}C`,
57
+ backward: (count = 1) => `${CSI}${count}D`,
58
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
59
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
60
+ left: `${CSI}G`,
61
+ hide: `${CSI}?25l`,
62
+ show: `${CSI}?25h`,
63
+ save: `${ESC}7`,
64
+ restore: `${ESC}8`
65
+ };
66
+ var scroll = {
67
+ up: (count = 1) => `${CSI}S`.repeat(count),
68
+ down: (count = 1) => `${CSI}T`.repeat(count)
69
+ };
70
+ var erase = {
71
+ screen: `${CSI}2J`,
72
+ up: (count = 1) => `${CSI}1J`.repeat(count),
73
+ down: (count = 1) => `${CSI}J`.repeat(count),
74
+ line: `${CSI}2K`,
75
+ lineEnd: `${CSI}K`,
76
+ lineStart: `${CSI}1K`,
77
+ lines(count) {
78
+ let clear = "";
79
+ for (let i = 0;i < count; i++)
80
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
81
+ if (count)
82
+ clear += cursor.left;
83
+ return clear;
84
+ }
85
+ };
86
+ module.exports = { cursor, scroll, erase, beep };
87
+ });
88
+
89
+ // node_modules/.bun/@clack+core@1.1.0/node_modules/@clack/core/dist/index.mjs
90
+ import { styleText as D } from "util";
91
+ import { stdout as R, stdin as q } from "process";
92
+ import ot from "readline";
93
+ function x(t, e, s) {
94
+ if (!s.some((u) => !u.disabled))
95
+ return t;
96
+ const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
97
+ return s[n].disabled ? x(n, e < 0 ? -1 : 1, s) : n;
98
+ }
99
+ function K(t, e, s) {
100
+ return String(t).normalize().replaceAll(`\r
101
+ `, `
102
+ `).split(`
103
+ `).map((i) => Et(i, e, s)).join(`
104
+ `);
105
+ }
106
+ function H(t, e) {
107
+ if (typeof t == "string")
108
+ return _.aliases.get(t) === e;
109
+ for (const s of t)
110
+ if (s !== undefined && H(s, e))
111
+ return true;
112
+ return false;
113
+ }
114
+ function _t(t, e) {
115
+ if (t === e)
116
+ return;
117
+ const s = t.split(`
118
+ `), i = e.split(`
119
+ `), r = Math.max(s.length, i.length), n = [];
120
+ for (let u = 0;u < r; u++)
121
+ s[u] !== i[u] && n.push(u);
122
+ return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
123
+ }
124
+ function Ct(t) {
125
+ return t === z;
126
+ }
127
+ function W(t, e) {
128
+ const s = t;
129
+ s.isTTY && s.setRawMode(e);
130
+ }
131
+
132
+ class B {
133
+ input;
134
+ output;
135
+ _abortSignal;
136
+ rl;
137
+ opts;
138
+ _render;
139
+ _track = false;
140
+ _prevFrame = "";
141
+ _subscribers = new Map;
142
+ _cursor = 0;
143
+ state = "initial";
144
+ error = "";
145
+ value;
146
+ userInput = "";
147
+ constructor(e, s = true) {
148
+ const { input: i = q, output: r = R, render: n, signal: u, ...a } = e;
149
+ this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
150
+ }
151
+ unsubscribe() {
152
+ this._subscribers.clear();
153
+ }
154
+ setSubscriber(e, s) {
155
+ const i = this._subscribers.get(e) ?? [];
156
+ i.push(s), this._subscribers.set(e, i);
157
+ }
158
+ on(e, s) {
159
+ this.setSubscriber(e, { cb: s });
160
+ }
161
+ once(e, s) {
162
+ this.setSubscriber(e, { cb: s, once: true });
163
+ }
164
+ emit(e, ...s) {
165
+ const i = this._subscribers.get(e) ?? [], r = [];
166
+ for (const n of i)
167
+ n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
168
+ for (const n of r)
169
+ n();
170
+ }
171
+ prompt() {
172
+ return new Promise((e) => {
173
+ if (this._abortSignal) {
174
+ if (this._abortSignal.aborted)
175
+ return this.state = "cancel", this.close(), e(z);
176
+ this._abortSignal.addEventListener("abort", () => {
177
+ this.state = "cancel", this.close();
178
+ }, { once: true });
179
+ }
180
+ this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), W(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
181
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), W(this.input, false), e(this.value);
182
+ }), this.once("cancel", () => {
183
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), W(this.input, false), e(z);
184
+ });
185
+ });
186
+ }
187
+ _isActionKey(e, s) {
188
+ return e === "\t";
189
+ }
190
+ _setValue(e) {
191
+ this.value = e, this.emit("value", this.value);
192
+ }
193
+ _setUserInput(e, s) {
194
+ this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
195
+ }
196
+ _clearUserInput() {
197
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
198
+ }
199
+ onKeypress(e, s) {
200
+ if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
201
+ if (this.opts.validate) {
202
+ const i = this.opts.validate(this.value);
203
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
204
+ }
205
+ this.state !== "error" && (this.state = "submit");
206
+ }
207
+ H([e, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
208
+ }
209
+ close() {
210
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
211
+ `), W(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
212
+ }
213
+ restoreCursor() {
214
+ const e = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
215
+ `).length - 1;
216
+ this.output.write(import_sisteransi.cursor.move(-999, e * -1));
217
+ }
218
+ render() {
219
+ const e = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
220
+ if (e !== this._prevFrame) {
221
+ if (this.state === "initial")
222
+ this.output.write(import_sisteransi.cursor.hide);
223
+ else {
224
+ const s = _t(this._prevFrame, e), i = nt(this.output);
225
+ if (this.restoreCursor(), s) {
226
+ const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
227
+ let u = s.lines.find((a) => a >= r);
228
+ if (u === undefined) {
229
+ this._prevFrame = e;
230
+ return;
231
+ }
232
+ if (s.lines.length === 1) {
233
+ this.output.write(import_sisteransi.cursor.move(0, u - n)), this.output.write(import_sisteransi.erase.lines(1));
234
+ const a = e.split(`
235
+ `);
236
+ this.output.write(a[u]), this._prevFrame = e, this.output.write(import_sisteransi.cursor.move(0, a.length - u - 1));
237
+ return;
238
+ } else if (s.lines.length > 1) {
239
+ if (r < n)
240
+ u = r;
241
+ else {
242
+ const l = u - n;
243
+ l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
244
+ }
245
+ this.output.write(import_sisteransi.erase.down());
246
+ const a = e.split(`
247
+ `).slice(u);
248
+ this.output.write(a.join(`
249
+ `)), this._prevFrame = e;
250
+ return;
251
+ }
252
+ }
253
+ this.output.write(import_sisteransi.erase.down());
254
+ }
255
+ this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
256
+ }
257
+ }
258
+ }
259
+ function wt(t, e) {
260
+ if (t === undefined || e.length === 0)
261
+ return 0;
262
+ const s = e.findIndex((i) => i.value === t);
263
+ return s !== -1 ? s : 0;
264
+ }
265
+ function Dt(t, e) {
266
+ return (e.label ?? String(e.value)).toLowerCase().includes(t.toLowerCase());
267
+ }
268
+ function St(t, e) {
269
+ if (e)
270
+ return t ? e : e[0];
271
+ }
272
+ var import_sisteransi, at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109, lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510, ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141, O, y, L, P, M, ct, ft, X = (t, e = {}, s = {}) => {
273
+ const i = e.limit ?? 1 / 0, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X(r, ft, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
274
+ let h = 0, o = 0, p = t.length, v = 0, F = false, d = p, b = Math.max(0, i - n), C = 0, w = 0, c = 0, f = 0;
275
+ t:
276
+ for (;; ) {
277
+ if (w > C || o >= p && o > h) {
278
+ const ut = t.slice(C, w) || t.slice(h, o);
279
+ v = 0;
280
+ for (const Y of ut.replaceAll(ct, "")) {
281
+ const $ = Y.codePointAt(0) || 0;
282
+ if (lt($) ? f = m : ht($) ? f = V : E !== A && at($) ? f = E : f = A, c + f > b && (d = Math.min(d, Math.max(C, h) + v)), c + f > i) {
283
+ F = true;
284
+ break t;
285
+ }
286
+ v += Y.length, c += f;
287
+ }
288
+ C = w = 0;
289
+ }
290
+ if (o >= p)
291
+ break;
292
+ if (M.lastIndex = o, M.test(t)) {
293
+ if (v = M.lastIndex - o, f = v * A, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / A))), c + f > i) {
294
+ F = true;
295
+ break;
296
+ }
297
+ c += f, C = h, w = o, o = h = M.lastIndex;
298
+ continue;
299
+ }
300
+ if (O.lastIndex = o, O.test(t)) {
301
+ if (c + u > b && (d = Math.min(d, o)), c + u > i) {
302
+ F = true;
303
+ break;
304
+ }
305
+ c += u, C = h, w = o, o = h = O.lastIndex;
306
+ continue;
307
+ }
308
+ if (y.lastIndex = o, y.test(t)) {
309
+ if (v = y.lastIndex - o, f = v * a, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / a))), c + f > i) {
310
+ F = true;
311
+ break;
312
+ }
313
+ c += f, C = h, w = o, o = h = y.lastIndex;
314
+ continue;
315
+ }
316
+ if (L.lastIndex = o, L.test(t)) {
317
+ if (v = L.lastIndex - o, f = v * l, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / l))), c + f > i) {
318
+ F = true;
319
+ break;
320
+ }
321
+ c += f, C = h, w = o, o = h = L.lastIndex;
322
+ continue;
323
+ }
324
+ if (P.lastIndex = o, P.test(t)) {
325
+ if (c + g > b && (d = Math.min(d, o)), c + g > i) {
326
+ F = true;
327
+ break;
328
+ }
329
+ c += g, C = h, w = o, o = h = P.lastIndex;
330
+ continue;
331
+ }
332
+ o += 1;
333
+ }
334
+ return { width: F ? b : c, index: F ? d : p, truncated: F, ellipsed: F && i >= n };
335
+ }, pt, S = (t, e = {}) => X(t, pt, e).width, T = "\x1B", Z = "\x9B", Ft = 39, j = "\x07", Q = "[", dt = "]", tt = "m", U, et, mt = (t) => {
336
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97)
337
+ return 39;
338
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107)
339
+ return 49;
340
+ if (t === 1 || t === 2)
341
+ return 22;
342
+ if (t === 3)
343
+ return 23;
344
+ if (t === 4)
345
+ return 24;
346
+ if (t === 7)
347
+ return 27;
348
+ if (t === 8)
349
+ return 28;
350
+ if (t === 9)
351
+ return 29;
352
+ if (t === 0)
353
+ return 0;
354
+ }, st = (t) => `${T}${Q}${t}${tt}`, it = (t) => `${T}${U}${t}${j}`, gt = (t) => t.map((e) => S(e)), G = (t, e, s) => {
355
+ const i = e[Symbol.iterator]();
356
+ let r = false, n = false, u = t.at(-1), a = u === undefined ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
357
+ for (;!l.done; ) {
358
+ const m = l.value, A = S(m);
359
+ a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === T || m === Z) && (r = true, n = e.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
360
+ }
361
+ u = t.at(-1), !a && u !== undefined && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
362
+ }, vt = (t) => {
363
+ const e = t.split(" ");
364
+ let s = e.length;
365
+ for (;s > 0 && !(S(e[s - 1]) > 0); )
366
+ s--;
367
+ return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
368
+ }, Et = (t, e, s = {}) => {
369
+ if (s.trim !== false && t.trim() === "")
370
+ return "";
371
+ let i = "", r, n;
372
+ const u = t.split(" "), a = gt(u);
373
+ let l = [""];
374
+ for (const [h, o] of u.entries()) {
375
+ s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
376
+ let p = S(l.at(-1) ?? "");
377
+ if (h !== 0 && (p >= e && (s.wordWrap === false || s.trim === false) && (l.push(""), p = 0), (p > 0 || s.trim === false) && (l[l.length - 1] += " ", p++)), s.hard && a[h] > e) {
378
+ const v = e - p, F = 1 + Math.floor((a[h] - v - 1) / e);
379
+ Math.floor((a[h] - 1) / e) < F && l.push(""), G(l, o, e);
380
+ continue;
381
+ }
382
+ if (p + a[h] > e && p > 0 && a[h] > 0) {
383
+ if (s.wordWrap === false && p < e) {
384
+ G(l, o, e);
385
+ continue;
386
+ }
387
+ l.push("");
388
+ }
389
+ if (p + a[h] > e && s.wordWrap === false) {
390
+ G(l, o, e);
391
+ continue;
392
+ }
393
+ l[l.length - 1] += o;
394
+ }
395
+ s.trim !== false && (l = l.map((h) => vt(h)));
396
+ const E = l.join(`
397
+ `), g = E[Symbol.iterator]();
398
+ let m = g.next(), A = g.next(), V = 0;
399
+ for (;!m.done; ) {
400
+ const h = m.value, o = A.value;
401
+ if (i += h, h === T || h === Z) {
402
+ et.lastIndex = V + 1;
403
+ const F = et.exec(E)?.groups;
404
+ if (F?.code !== undefined) {
405
+ const d = Number.parseFloat(F.code);
406
+ r = d === Ft ? undefined : d;
407
+ } else
408
+ F?.uri !== undefined && (n = F.uri.length === 0 ? undefined : F.uri);
409
+ }
410
+ const p = r ? mt(r) : undefined;
411
+ o === `
412
+ ` ? (n && (i += it("")), r && p && (i += st(p))) : h === `
413
+ ` && (r && p && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
414
+ }
415
+ return i;
416
+ }, At, _, bt, z, rt = (t) => ("columns" in t) && typeof t.columns == "number" ? t.columns : 80, nt = (t) => ("rows" in t) && typeof t.rows == "number" ? t.rows : 20, Vt, kt, yt;
417
+ var init_dist = __esm(() => {
418
+ import_sisteransi = __toESM(require_src(), 1);
419
+ O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
420
+ y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
421
+ L = /\t{1,1000}/y;
422
+ P = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
423
+ M = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
424
+ ct = /\p{M}+/gu;
425
+ ft = { limit: 1 / 0, ellipsis: "" };
426
+ pt = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
427
+ U = `${dt}8;;`;
428
+ et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
429
+ At = ["up", "down", "left", "right", "space", "enter", "cancel"];
430
+ _ = { actions: new Set(At), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
431
+ bt = globalThis.process.platform.startsWith("win");
432
+ z = Symbol("clack:cancel");
433
+ Vt = class Vt extends B {
434
+ filteredOptions;
435
+ multiple;
436
+ isNavigating = false;
437
+ selectedValues = [];
438
+ focusedValue;
439
+ #t = 0;
440
+ #s = "";
441
+ #i;
442
+ #e;
443
+ get cursor() {
444
+ return this.#t;
445
+ }
446
+ get userInputWithCursor() {
447
+ if (!this.userInput)
448
+ return D(["inverse", "hidden"], "_");
449
+ if (this._cursor >= this.userInput.length)
450
+ return `${this.userInput}\u2588`;
451
+ const e = this.userInput.slice(0, this._cursor), [s, ...i] = this.userInput.slice(this._cursor);
452
+ return `${e}${D("inverse", s)}${i.join("")}`;
453
+ }
454
+ get options() {
455
+ return typeof this.#e == "function" ? this.#e() : this.#e;
456
+ }
457
+ constructor(e) {
458
+ super(e), this.#e = e.options;
459
+ const s = this.options;
460
+ this.filteredOptions = [...s], this.multiple = e.multiple === true, this.#i = e.filter ?? Dt;
461
+ let i;
462
+ if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
463
+ for (const r of i) {
464
+ const n = s.findIndex((u) => u.value === r);
465
+ n !== -1 && (this.toggleSelected(r), this.#t = n);
466
+ }
467
+ this.focusedValue = this.options[this.#t]?.value, this.on("key", (r, n) => this.#r(r, n)), this.on("userInput", (r) => this.#n(r));
468
+ }
469
+ _isActionKey(e, s) {
470
+ return e === "\t" || this.multiple && this.isNavigating && s.name === "space" && e !== undefined && e !== "";
471
+ }
472
+ #r(e, s) {
473
+ const i = s.name === "up", r = s.name === "down", n = s.name === "return";
474
+ i || r ? (this.#t = x(this.#t, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = St(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
475
+ }
476
+ deselectAll() {
477
+ this.selectedValues = [];
478
+ }
479
+ toggleSelected(e) {
480
+ this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((s) => s !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
481
+ }
482
+ #n(e) {
483
+ if (e !== this.#s) {
484
+ this.#s = e;
485
+ const s = this.options;
486
+ e ? this.filteredOptions = s.filter((n) => this.#i(e, n)) : this.filteredOptions = [...s];
487
+ const i = wt(this.focusedValue, this.filteredOptions);
488
+ this.#t = x(i, 0, this.filteredOptions);
489
+ const r = this.filteredOptions[this.#t];
490
+ r && !r.disabled ? this.focusedValue = r.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
491
+ }
492
+ }
493
+ };
494
+ kt = class kt extends B {
495
+ get cursor() {
496
+ return this.value ? 0 : 1;
497
+ }
498
+ get _value() {
499
+ return this.cursor === 0;
500
+ }
501
+ constructor(e) {
502
+ super(e, false), this.value = !!e.initialValue, this.on("userInput", () => {
503
+ this.value = this._value;
504
+ }), this.on("confirm", (s) => {
505
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
506
+ }), this.on("cursor", () => {
507
+ this.value = !this.value;
508
+ });
509
+ }
510
+ };
511
+ yt = class yt extends B {
512
+ options;
513
+ cursor = 0;
514
+ #t;
515
+ getGroupItems(e) {
516
+ return this.options.filter((s) => s.group === e);
517
+ }
518
+ isGroupSelected(e) {
519
+ const s = this.getGroupItems(e), i = this.value;
520
+ return i === undefined ? false : s.every((r) => i.includes(r.value));
521
+ }
522
+ toggleValue() {
523
+ const e = this.options[this.cursor];
524
+ if (this.value === undefined && (this.value = []), e.group === true) {
525
+ const s = e.value, i = this.getGroupItems(s);
526
+ this.isGroupSelected(s) ? this.value = this.value.filter((r) => i.findIndex((n) => n.value === r) === -1) : this.value = [...this.value, ...i.map((r) => r.value)], this.value = Array.from(new Set(this.value));
527
+ } else {
528
+ const s = this.value.includes(e.value);
529
+ this.value = s ? this.value.filter((i) => i !== e.value) : [...this.value, e.value];
530
+ }
531
+ }
532
+ constructor(e) {
533
+ super(e, false);
534
+ const { options: s } = e;
535
+ this.#t = e.selectableGroups !== false, this.options = Object.entries(s).flatMap(([i, r]) => [{ value: i, group: true, label: i }, ...r.map((n) => ({ ...n, group: i }))]), this.value = [...e.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), this.#t ? 0 : 1), this.on("cursor", (i) => {
536
+ switch (i) {
537
+ case "left":
538
+ case "up": {
539
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
540
+ const r = this.options[this.cursor]?.group === true;
541
+ !this.#t && r && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
542
+ break;
543
+ }
544
+ case "down":
545
+ case "right": {
546
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
547
+ const r = this.options[this.cursor]?.group === true;
548
+ !this.#t && r && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
549
+ break;
550
+ }
551
+ case "space":
552
+ this.toggleValue();
553
+ break;
554
+ }
555
+ });
556
+ }
557
+ };
558
+ });
559
+
560
+ // node_modules/.bun/@clack+prompts@1.1.0/node_modules/@clack/prompts/dist/index.mjs
561
+ import { styleText as t, stripVTControlCharacters as ue } from "util";
562
+ import N2 from "process";
563
+ function pt2() {
564
+ return N2.platform !== "win32" ? N2.env.TERM !== "linux" : !!N2.env.CI || !!N2.env.WT_SESSION || !!N2.env.TERMINUS_SUBLIME || N2.env.ConEmuTask === "{cmd::Cmder}" || N2.env.TERM_PROGRAM === "Terminus-Sublime" || N2.env.TERM_PROGRAM === "vscode" || N2.env.TERM === "xterm-256color" || N2.env.TERM === "alacritty" || N2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
565
+ }
566
+ function J(e, r, s) {
567
+ return String(e).normalize().replaceAll(`\r
568
+ `, `
569
+ `).split(`
570
+ `).map((i) => It2(i, r, s)).join(`
571
+ `);
572
+ }
573
+ var import_sisteransi2, ee, I2 = (e, r) => ee ? e : r, Re, $e, de, V, he, h, x2, Oe, Pe, z2, H2, te, U2, q2, Ne, se, pe, We, me, ge, Ge, fe, Fe, ye, Ee, W2 = (e) => {
574
+ switch (e) {
575
+ case "initial":
576
+ case "active":
577
+ return t("cyan", Re);
578
+ case "cancel":
579
+ return t("red", $e);
580
+ case "error":
581
+ return t("yellow", de);
582
+ case "submit":
583
+ return t("green", V);
584
+ }
585
+ }, mt2 = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109, gt2 = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510, ft2 = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141, we, re, ie, Ae, ne, Ft2, yt2, Le = (e, r = {}, s = {}) => {
586
+ const i = r.limit ?? 1 / 0, a = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (a ? Le(a, yt2, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, n = s.tabWidth ?? 8, c = s.ambiguousWidth ?? 1, p = s.emojiWidth ?? 2, f = s.fullWidthWidth ?? 2, g = s.regularWidth ?? 1, E = s.wideWidth ?? 2;
587
+ let $ = 0, m = 0, d = e.length, F = 0, y2 = false, v = d, C = Math.max(0, i - o), A = 0, b = 0, w = 0, S2 = 0;
588
+ e:
589
+ for (;; ) {
590
+ if (b > A || m >= d && m > $) {
591
+ const T2 = e.slice(A, b) || e.slice($, m);
592
+ F = 0;
593
+ for (const M2 of T2.replaceAll(Ft2, "")) {
594
+ const O2 = M2.codePointAt(0) || 0;
595
+ if (gt2(O2) ? S2 = f : ft2(O2) ? S2 = E : c !== g && mt2(O2) ? S2 = c : S2 = g, w + S2 > C && (v = Math.min(v, Math.max(A, $) + F)), w + S2 > i) {
596
+ y2 = true;
597
+ break e;
598
+ }
599
+ F += M2.length, w += S2;
600
+ }
601
+ A = b = 0;
602
+ }
603
+ if (m >= d)
604
+ break;
605
+ if (ne.lastIndex = m, ne.test(e)) {
606
+ if (F = ne.lastIndex - m, S2 = F * g, w + S2 > C && (v = Math.min(v, m + Math.floor((C - w) / g))), w + S2 > i) {
607
+ y2 = true;
608
+ break;
609
+ }
610
+ w += S2, A = $, b = m, m = $ = ne.lastIndex;
611
+ continue;
612
+ }
613
+ if (we.lastIndex = m, we.test(e)) {
614
+ if (w + u > C && (v = Math.min(v, m)), w + u > i) {
615
+ y2 = true;
616
+ break;
617
+ }
618
+ w += u, A = $, b = m, m = $ = we.lastIndex;
619
+ continue;
620
+ }
621
+ if (re.lastIndex = m, re.test(e)) {
622
+ if (F = re.lastIndex - m, S2 = F * l, w + S2 > C && (v = Math.min(v, m + Math.floor((C - w) / l))), w + S2 > i) {
623
+ y2 = true;
624
+ break;
625
+ }
626
+ w += S2, A = $, b = m, m = $ = re.lastIndex;
627
+ continue;
628
+ }
629
+ if (ie.lastIndex = m, ie.test(e)) {
630
+ if (F = ie.lastIndex - m, S2 = F * n, w + S2 > C && (v = Math.min(v, m + Math.floor((C - w) / n))), w + S2 > i) {
631
+ y2 = true;
632
+ break;
633
+ }
634
+ w += S2, A = $, b = m, m = $ = ie.lastIndex;
635
+ continue;
636
+ }
637
+ if (Ae.lastIndex = m, Ae.test(e)) {
638
+ if (w + p > C && (v = Math.min(v, m)), w + p > i) {
639
+ y2 = true;
640
+ break;
641
+ }
642
+ w += p, A = $, b = m, m = $ = Ae.lastIndex;
643
+ continue;
644
+ }
645
+ m += 1;
646
+ }
647
+ return { width: y2 ? C : w, index: y2 ? v : d, truncated: y2, ellipsed: y2 && i >= o };
648
+ }, Et2, D2 = (e, r = {}) => Le(e, Et2, r).width, ae = "\x1B", je = "\x9B", vt2 = 39, Ce = "\x07", ke = "[", wt2 = "]", Ve = "m", Se, He, At2 = (e) => {
649
+ if (e >= 30 && e <= 37 || e >= 90 && e <= 97)
650
+ return 39;
651
+ if (e >= 40 && e <= 47 || e >= 100 && e <= 107)
652
+ return 49;
653
+ if (e === 1 || e === 2)
654
+ return 22;
655
+ if (e === 3)
656
+ return 23;
657
+ if (e === 4)
658
+ return 24;
659
+ if (e === 7)
660
+ return 27;
661
+ if (e === 8)
662
+ return 28;
663
+ if (e === 9)
664
+ return 29;
665
+ if (e === 0)
666
+ return 0;
667
+ }, Ue = (e) => `${ae}${ke}${e}${Ve}`, Ke = (e) => `${ae}${Se}${e}${Ce}`, Ct2 = (e) => e.map((r) => D2(r)), Ie = (e, r, s) => {
668
+ const i = r[Symbol.iterator]();
669
+ let a = false, o = false, u = e.at(-1), l = u === undefined ? 0 : D2(u), n = i.next(), c = i.next(), p = 0;
670
+ for (;!n.done; ) {
671
+ const f = n.value, g = D2(f);
672
+ l + g <= s ? e[e.length - 1] += f : (e.push(f), l = 0), (f === ae || f === je) && (a = true, o = r.startsWith(Se, p + 1)), a ? o ? f === Ce && (a = false, o = false) : f === Ve && (a = false) : (l += g, l === s && !c.done && (e.push(""), l = 0)), n = c, c = i.next(), p += f.length;
673
+ }
674
+ u = e.at(-1), !l && u !== undefined && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
675
+ }, St2 = (e) => {
676
+ const r = e.split(" ");
677
+ let s = r.length;
678
+ for (;s > 0 && !(D2(r[s - 1]) > 0); )
679
+ s--;
680
+ return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
681
+ }, It2 = (e, r, s = {}) => {
682
+ if (s.trim !== false && e.trim() === "")
683
+ return "";
684
+ let i = "", a, o;
685
+ const u = e.split(" "), l = Ct2(u);
686
+ let n = [""];
687
+ for (const [$, m] of u.entries()) {
688
+ s.trim !== false && (n[n.length - 1] = (n.at(-1) ?? "").trimStart());
689
+ let d = D2(n.at(-1) ?? "");
690
+ if ($ !== 0 && (d >= r && (s.wordWrap === false || s.trim === false) && (n.push(""), d = 0), (d > 0 || s.trim === false) && (n[n.length - 1] += " ", d++)), s.hard && l[$] > r) {
691
+ const F = r - d, y2 = 1 + Math.floor((l[$] - F - 1) / r);
692
+ Math.floor((l[$] - 1) / r) < y2 && n.push(""), Ie(n, m, r);
693
+ continue;
694
+ }
695
+ if (d + l[$] > r && d > 0 && l[$] > 0) {
696
+ if (s.wordWrap === false && d < r) {
697
+ Ie(n, m, r);
698
+ continue;
699
+ }
700
+ n.push("");
701
+ }
702
+ if (d + l[$] > r && s.wordWrap === false) {
703
+ Ie(n, m, r);
704
+ continue;
705
+ }
706
+ n[n.length - 1] += m;
707
+ }
708
+ s.trim !== false && (n = n.map(($) => St2($)));
709
+ const c = n.join(`
710
+ `), p = c[Symbol.iterator]();
711
+ let f = p.next(), g = p.next(), E = 0;
712
+ for (;!f.done; ) {
713
+ const $ = f.value, m = g.value;
714
+ if (i += $, $ === ae || $ === je) {
715
+ He.lastIndex = E + 1;
716
+ const y2 = He.exec(c)?.groups;
717
+ if (y2?.code !== undefined) {
718
+ const v = Number.parseFloat(y2.code);
719
+ a = v === vt2 ? undefined : v;
720
+ } else
721
+ y2?.uri !== undefined && (o = y2.uri.length === 0 ? undefined : y2.uri);
722
+ }
723
+ const d = a ? At2(a) : undefined;
724
+ m === `
725
+ ` ? (o && (i += Ke("")), a && d && (i += Ue(d))) : $ === `
726
+ ` && (a && d && (i += Ue(a)), o && (i += Ke(o))), E += $.length, f = g, g = p.next();
727
+ }
728
+ return i;
729
+ }, Rt = (e) => {
730
+ const r = e.active ?? "Yes", s = e.inactive ?? "No";
731
+ return new kt({ active: r, inactive: s, signal: e.signal, input: e.input, output: e.output, initialValue: e.initialValue ?? true, render() {
732
+ const i = e.withGuide ?? _.withGuide, a = `${i ? `${t("gray", h)}
733
+ ` : ""}${W2(this.state)} ${e.message}
734
+ `, o = this.value ? r : s;
735
+ switch (this.state) {
736
+ case "submit": {
737
+ const u = i ? `${t("gray", h)} ` : "";
738
+ return `${a}${u}${t("dim", o)}`;
739
+ }
740
+ case "cancel": {
741
+ const u = i ? `${t("gray", h)} ` : "";
742
+ return `${a}${u}${t(["strikethrough", "dim"], o)}${i ? `
743
+ ${t("gray", h)}` : ""}`;
744
+ }
745
+ default: {
746
+ const u = i ? `${t("cyan", h)} ` : "", l = i ? t("cyan", x2) : "";
747
+ return `${a}${u}${this.value ? `${t("green", z2)} ${r}` : `${t("dim", H2)} ${t("dim", r)}`}${e.vertical ? i ? `
748
+ ${t("cyan", h)} ` : `
749
+ ` : ` ${t("dim", "/")} `}${this.value ? `${t("dim", H2)} ${t("dim", s)}` : `${t("green", z2)} ${s}`}
750
+ ${l}
751
+ `;
752
+ }
753
+ }
754
+ } }).prompt();
755
+ }, R2, Wt2 = (e = "", r) => {
756
+ const s = r?.output ?? process.stdout, i = r?.withGuide ?? _.withGuide ? `${t("gray", he)} ` : "";
757
+ s.write(`${i}${e}
758
+ `);
759
+ }, Gt = (e = "", r) => {
760
+ const s = r?.output ?? process.stdout, i = r?.withGuide ?? _.withGuide ? `${t("gray", h)}
761
+ ${t("gray", x2)} ` : "";
762
+ s.write(`${i}${e}
763
+
764
+ `);
765
+ }, jt = (e) => t("dim", e), kt2 = (e, r, s) => {
766
+ const i = { hard: true, trim: false }, a = J(e, r, i).split(`
767
+ `), o = a.reduce((n, c) => Math.max(D2(c), n), 0), u = a.map(s).reduce((n, c) => Math.max(D2(c), n), 0), l = r - (u - o);
768
+ return J(e, l, i);
769
+ }, Vt2 = (e = "", r = "", s) => {
770
+ const i = s?.output ?? N2.stdout, a = s?.withGuide ?? _.withGuide, o = s?.format ?? jt, u = ["", ...kt2(e, rt(i) - 6, o).split(`
771
+ `).map(o), ""], l = D2(r), n = Math.max(u.reduce((g, E) => {
772
+ const $ = D2(E);
773
+ return $ > g ? $ : g;
774
+ }, 0), l) + 2, c = u.map((g) => `${t("gray", h)} ${g}${" ".repeat(n - D2(g))}${t("gray", h)}`).join(`
775
+ `), p = a ? `${t("gray", h)}
776
+ ` : "", f = a ? We : ge;
777
+ i.write(`${p}${t("green", V)} ${t("reset", r)} ${t("gray", se.repeat(Math.max(n - l - 1, 1)) + pe)}
778
+ ${c}
779
+ ${t("gray", f + se.repeat(n + 2) + me)}
780
+ `);
781
+ }, ze, Qe;
782
+ var init_dist2 = __esm(() => {
783
+ init_dist();
784
+ init_dist();
785
+ import_sisteransi2 = __toESM(require_src(), 1);
786
+ ee = pt2();
787
+ Re = I2("\u25C6", "*");
788
+ $e = I2("\u25A0", "x");
789
+ de = I2("\u25B2", "x");
790
+ V = I2("\u25C7", "o");
791
+ he = I2("\u250C", "T");
792
+ h = I2("\u2502", "|");
793
+ x2 = I2("\u2514", "\u2014");
794
+ Oe = I2("\u2510", "T");
795
+ Pe = I2("\u2518", "\u2014");
796
+ z2 = I2("\u25CF", ">");
797
+ H2 = I2("\u25CB", " ");
798
+ te = I2("\u25FB", "[\u2022]");
799
+ U2 = I2("\u25FC", "[+]");
800
+ q2 = I2("\u25FB", "[ ]");
801
+ Ne = I2("\u25AA", "\u2022");
802
+ se = I2("\u2500", "-");
803
+ pe = I2("\u256E", "+");
804
+ We = I2("\u251C", "+");
805
+ me = I2("\u256F", "+");
806
+ ge = I2("\u2570", "+");
807
+ Ge = I2("\u256D", "+");
808
+ fe = I2("\u25CF", "\u2022");
809
+ Fe = I2("\u25C6", "*");
810
+ ye = I2("\u25B2", "!");
811
+ Ee = I2("\u25A0", "x");
812
+ we = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
813
+ re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
814
+ ie = /\t{1,1000}/y;
815
+ Ae = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
816
+ ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
817
+ Ft2 = /\p{M}+/gu;
818
+ yt2 = { limit: 1 / 0, ellipsis: "" };
819
+ Et2 = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
820
+ Se = `${wt2}8;;`;
821
+ He = new RegExp(`(?:\\${ke}(?<code>\\d+)m|\\${Se}(?<uri>.*)${Ce})`, "y");
822
+ R2 = { message: (e = [], { symbol: r = t("gray", h), secondarySymbol: s = t("gray", h), output: i = process.stdout, spacing: a = 1, withGuide: o } = {}) => {
823
+ const u = [], l = o ?? _.withGuide, n = l ? s : "", c = l ? `${r} ` : "", p = l ? `${s} ` : "";
824
+ for (let g = 0;g < a; g++)
825
+ u.push(n);
826
+ const f = Array.isArray(e) ? e : e.split(`
827
+ `);
828
+ if (f.length > 0) {
829
+ const [g, ...E] = f;
830
+ g.length > 0 ? u.push(`${c}${g}`) : u.push(l ? r : "");
831
+ for (const $ of E)
832
+ $.length > 0 ? u.push(`${p}${$}`) : u.push(l ? s : "");
833
+ }
834
+ i.write(`${u.join(`
835
+ `)}
836
+ `);
837
+ }, info: (e, r) => {
838
+ R2.message(e, { ...r, symbol: t("blue", fe) });
839
+ }, success: (e, r) => {
840
+ R2.message(e, { ...r, symbol: t("green", Fe) });
841
+ }, step: (e, r) => {
842
+ R2.message(e, { ...r, symbol: t("green", V) });
843
+ }, warn: (e, r) => {
844
+ R2.message(e, { ...r, symbol: t("yellow", ye) });
845
+ }, warning: (e, r) => {
846
+ R2.warn(e, r);
847
+ }, error: (e, r) => {
848
+ R2.message(e, { ...r, symbol: t("red", Ee) });
849
+ } };
850
+ ze = { light: I2("\u2500", "-"), heavy: I2("\u2501", "="), block: I2("\u2588", "#") };
851
+ Qe = `${t("gray", h)} `;
852
+ });
853
+
854
+ // bin/src/shared.ts
855
+ import { existsSync, readFileSync } from "fs";
856
+ import { basename, join } from "path";
857
+ function run(cmd, args, opts) {
858
+ const result = Bun.spawnSync([cmd, ...args], { stdout: "pipe", stderr: "pipe", ...opts });
859
+ return {
860
+ success: result.success,
861
+ stdout: result.stdout,
862
+ stderr: result.stderr
863
+ };
864
+ }
865
+ function which(tool) {
866
+ return run("which", [tool]).success;
867
+ }
868
+ function getGitRoot() {
869
+ const result = run("git", ["rev-parse", "--show-toplevel"]);
870
+ if (!result.success)
871
+ return null;
872
+ return result.stdout.toString().trim();
873
+ }
874
+ function detectProjectName(gitRoot) {
875
+ const pkgPath = join(gitRoot, "package.json");
876
+ if (existsSync(pkgPath)) {
877
+ try {
878
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
879
+ if (pkg.name)
880
+ return pkg.name;
881
+ } catch {}
882
+ }
883
+ return basename(gitRoot);
884
+ }
885
+ var init_shared = () => {};
886
+
887
+ // bin/src/init.ts
888
+ var exports_init = {};
889
+ import { existsSync as existsSync2 } from "fs";
890
+ import { join as join2 } from "path";
891
+ function checkDeps() {
892
+ const missing = [];
893
+ for (const dep of deps) {
894
+ const found = which(dep.tool);
895
+ if (found) {
896
+ console.log(` \u2713 ${dep.tool}`);
897
+ } else if (dep.required) {
898
+ console.log(` \u2717 ${dep.tool} \u2014 not found (required)`);
899
+ missing.push(dep);
900
+ } else {
901
+ console.log(` \u25CB ${dep.tool} \u2014 not found (optional)`);
902
+ }
903
+ }
904
+ return missing;
905
+ }
906
+ function webmuxTemplate(name) {
907
+ return `# Project display name in the dashboard
908
+ name: ${name}
909
+
910
+ # Each service defines a port env var that webmux injects into .env.local
911
+ # when creating a worktree. Ports are auto-assigned: base + (slot \xD7 step).
912
+ # Use \`source .env.local\` in your .workmux.yaml pane commands to pick them up.
913
+ services:
914
+ - name: app
915
+ portEnv: PORT
916
+ portStart: 3000 # Port for the main branch (slot 0)
917
+ portStep: 10 # Increment per worktree (3010, 3020, ...)
918
+
919
+ # Agent profiles determine how AI agents run in worktrees
920
+ profiles:
921
+ default:
922
+ name: default
923
+
924
+ # --- Sandbox profile (uncomment to enable) ---
925
+ # Runs agents in Docker containers for full isolation.
926
+ # Requires: docker + a built image.
927
+ # sandbox:
928
+ # name: sandbox
929
+ # image: my-project-sandbox
930
+ # envPassthrough: # Env vars forwarded into the container
931
+ # - DATABASE_URL
932
+ # systemPrompt: >
933
+ # You are running inside a sandboxed container.
934
+ # Start the dev server with: npm run dev
935
+
936
+ # --- Linked repos (uncomment to enable) ---
937
+ # Monitor PRs from related repos in the dashboard.
938
+ # linkedRepos:
939
+ # - repo: org/other-repo
940
+ # alias: other
941
+
942
+ # --- Startup environment variables ---
943
+ # These will appear as configurable fields in the UI when creating a worktree.
944
+ # startupEnvs:
945
+ # NODE_ENV: development
946
+ `;
947
+ }
948
+ function workmuxTemplate() {
949
+ return `main_branch: main
950
+
951
+ panes:
952
+ # Agent pane \u2014 runs the AI coding assistant
953
+ - command: >-
954
+ claude --append-system-prompt
955
+ "You are running inside a git worktree managed by workmux.\\n
956
+ Pane layout (current window):\\n
957
+ - Pane 0: this pane (claude agent)\\n
958
+ - Pane 1: dev server\\n\\n
959
+ To check dev server logs: tmux capture-pane -t .1 -p -S -50\\n
960
+ To restart dev server: tmux send-keys -t .1 C-c 'source .env.local && PORT=\\$PORT npm run dev' Enter"
961
+ focus: true
962
+
963
+ # Dev server \u2014 waits for .env.local (written by webmux) then starts
964
+ - command: >-
965
+ npm install &&
966
+ until [ -f .env.local ]; do sleep 0.2; done;
967
+ source .env.local;
968
+ PORT=$PORT npm run dev
969
+ split: horizontal
970
+ `;
971
+ }
972
+ var deps, gitRoot, missing, workmuxYaml, webmuxYaml;
973
+ var init_init = __esm(async () => {
974
+ init_dist2();
975
+ init_shared();
976
+ deps = [
977
+ { tool: "git", required: true, hint: "https://git-scm.com/downloads" },
978
+ { tool: "bun", required: true, hint: "https://bun.sh" },
979
+ { tool: "tmux", required: true, hint: "brew install tmux / sudo apt install tmux" },
980
+ { tool: "workmux", required: true, hint: "cargo install workmux or https://workmux.raine.dev" },
981
+ { tool: "gh", required: false, hint: "brew install gh then gh auth login" },
982
+ { tool: "docker", required: false, hint: "https://docs.docker.com/get-started/get-docker/" }
983
+ ];
984
+ Wt2("webmux init");
985
+ gitRoot = getGitRoot();
986
+ if (!gitRoot) {
987
+ R2.error("Not inside a git repository. Run this from within a project.");
988
+ Gt("Aborted.");
989
+ process.exit(1);
990
+ }
991
+ R2.success(`Git root: ${gitRoot}`);
992
+ R2.step("Checking dependencies...");
993
+ missing = checkDeps();
994
+ if (missing.length > 0) {
995
+ const lines = missing.map((d) => ` ${d.tool}: ${d.hint}`).join(`
996
+ `);
997
+ Vt2(lines, "Install these required dependencies, then re-run webmux init");
998
+ Gt("Setup incomplete.");
999
+ process.exit(1);
1000
+ }
1001
+ if (which("gh")) {
1002
+ const ghAuth = run("gh", ["auth", "status"]);
1003
+ if (!ghAuth.success) {
1004
+ R2.warning("gh is installed but not authenticated. Run: gh auth login");
1005
+ } else {
1006
+ R2.success("gh \u2014 authenticated");
1007
+ }
1008
+ }
1009
+ R2.step("Checking config files...");
1010
+ workmuxYaml = join2(gitRoot, ".workmux.yaml");
1011
+ if (existsSync2(workmuxYaml)) {
1012
+ R2.info(".workmux.yaml already exists, skipping");
1013
+ } else {
1014
+ await Bun.write(workmuxYaml, workmuxTemplate());
1015
+ R2.success(".workmux.yaml created");
1016
+ }
1017
+ webmuxYaml = join2(gitRoot, ".webmux.yaml");
1018
+ if (existsSync2(webmuxYaml)) {
1019
+ R2.info(".webmux.yaml already exists, skipping");
1020
+ } else {
1021
+ const name = detectProjectName(gitRoot);
1022
+ await Bun.write(webmuxYaml, webmuxTemplate(name));
1023
+ R2.success(".webmux.yaml created");
1024
+ }
1025
+ Gt("You're all set! Next steps:");
1026
+ console.log();
1027
+ console.log(" 1. Edit .workmux.yaml to configure pane layout for your project");
1028
+ console.log(" 2. Edit .webmux.yaml to set up service ports and profiles");
1029
+ console.log(" 3. Run: webmux");
1030
+ console.log();
1031
+ });
1032
+
1033
+ // bin/src/service.ts
1034
+ var exports_service = {};
1035
+ __export(exports_service, {
1036
+ default: () => service
1037
+ });
1038
+ import { existsSync as existsSync3, mkdirSync, unlinkSync } from "fs";
1039
+ import { join as join3 } from "path";
1040
+ import { homedir } from "os";
1041
+ function getPlatform() {
1042
+ const plat = process.platform;
1043
+ if (plat === "linux" || plat === "darwin")
1044
+ return plat;
1045
+ return null;
1046
+ }
1047
+ function resolveWebmuxPath() {
1048
+ const result = run("which", ["webmux"]);
1049
+ if (!result.success)
1050
+ return null;
1051
+ return result.stdout.toString().trim();
1052
+ }
1053
+ function sanitizeName(name) {
1054
+ return name.replace(/[^a-zA-Z0-9_-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
1055
+ }
1056
+ function formatCommand([bin, args]) {
1057
+ return [bin, ...args].join(" ");
1058
+ }
1059
+ function runCommand(cmd) {
1060
+ return run(cmd[0], cmd[1]);
1061
+ }
1062
+ function printRunResult(result) {
1063
+ console.log(result.stdout.toString());
1064
+ const err = result.stderr.toString().trim();
1065
+ if (err)
1066
+ console.error(err);
1067
+ }
1068
+ function systemdUnitPath(serviceName) {
1069
+ return join3(homedir(), ".config", "systemd", "user", `${serviceName}.service`);
1070
+ }
1071
+ function launchdPlistPath(serviceName) {
1072
+ return join3(homedir(), "Library", "LaunchAgents", `com.webmux.${serviceName}.plist`);
1073
+ }
1074
+ function serviceFilePath(config) {
1075
+ if (config.platform === "linux")
1076
+ return systemdUnitPath(config.serviceName);
1077
+ return launchdPlistPath(config.serviceName);
1078
+ }
1079
+ function generateSystemdUnit(config) {
1080
+ return `[Unit]
1081
+ Description=webmux dashboard \u2014 ${config.projectName}
1082
+
1083
+ [Service]
1084
+ Type=simple
1085
+ ExecStart=${config.webmuxPath} --port ${config.port}
1086
+ WorkingDirectory=${config.projectDir}
1087
+ Restart=on-failure
1088
+ RestartSec=5
1089
+ Environment=BACKEND_PORT=${config.port}
1090
+ Environment=WEBMUX_PROJECT_DIR=${config.projectDir}
1091
+ Environment=PATH=${process.env.PATH}
1092
+
1093
+ [Install]
1094
+ WantedBy=default.target
1095
+ `;
1096
+ }
1097
+ function generateLaunchdPlist(config) {
1098
+ const logPath = join3(homedir(), "Library", "Logs", `webmux-${config.serviceName}.log`);
1099
+ return `<?xml version="1.0" encoding="UTF-8"?>
1100
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1101
+ <plist version="1.0">
1102
+ <dict>
1103
+ <key>Label</key>
1104
+ <string>com.webmux.${config.serviceName}</string>
1105
+ <key>ProgramArguments</key>
1106
+ <array>
1107
+ <string>${config.webmuxPath}</string>
1108
+ <string>--port</string>
1109
+ <string>${config.port}</string>
1110
+ </array>
1111
+ <key>WorkingDirectory</key>
1112
+ <string>${config.projectDir}</string>
1113
+ <key>RunAtLoad</key>
1114
+ <true/>
1115
+ <key>KeepAlive</key>
1116
+ <dict>
1117
+ <key>SuccessfulExit</key>
1118
+ <false/>
1119
+ </dict>
1120
+ <key>StandardOutPath</key>
1121
+ <string>${logPath}</string>
1122
+ <key>StandardErrorPath</key>
1123
+ <string>${logPath}</string>
1124
+ <key>EnvironmentVariables</key>
1125
+ <dict>
1126
+ <key>BACKEND_PORT</key>
1127
+ <string>${config.port}</string>
1128
+ <key>WEBMUX_PROJECT_DIR</key>
1129
+ <string>${config.projectDir}</string>
1130
+ <key>PATH</key>
1131
+ <string>${process.env.PATH}</string>
1132
+ </dict>
1133
+ </dict>
1134
+ </plist>
1135
+ `;
1136
+ }
1137
+ function generateServiceFile(config) {
1138
+ if (config.platform === "linux")
1139
+ return generateSystemdUnit(config);
1140
+ return generateLaunchdPlist(config);
1141
+ }
1142
+ function installCommands(config) {
1143
+ if (config.platform === "linux") {
1144
+ return [
1145
+ ["systemctl", ["--user", "daemon-reload"]],
1146
+ ["systemctl", ["--user", "enable", "--now", config.serviceName]]
1147
+ ];
1148
+ }
1149
+ return [
1150
+ ["launchctl", ["load", "-w", launchdPlistPath(config.serviceName)]]
1151
+ ];
1152
+ }
1153
+ function uninstallCommands(config) {
1154
+ if (config.platform === "linux") {
1155
+ return [
1156
+ ["systemctl", ["--user", "stop", config.serviceName]],
1157
+ ["systemctl", ["--user", "disable", config.serviceName]]
1158
+ ];
1159
+ }
1160
+ return [
1161
+ ["launchctl", ["unload", "-w", launchdPlistPath(config.serviceName)]]
1162
+ ];
1163
+ }
1164
+ function isInstalled(config) {
1165
+ return existsSync3(serviceFilePath(config));
1166
+ }
1167
+ async function install(config) {
1168
+ const filePath = serviceFilePath(config);
1169
+ if (isInstalled(config)) {
1170
+ const reinstall = await Rt({ message: "Service is already installed. Reinstall?" });
1171
+ if (Ct(reinstall) || !reinstall) {
1172
+ R2.info("Aborted.");
1173
+ return;
1174
+ }
1175
+ for (const cmd of uninstallCommands(config)) {
1176
+ runCommand(cmd);
1177
+ }
1178
+ }
1179
+ const content = generateServiceFile(config);
1180
+ const commands = installCommands(config);
1181
+ Vt2([
1182
+ `File: ${filePath}`,
1183
+ "",
1184
+ "Contents:",
1185
+ content,
1186
+ "Commands to run:",
1187
+ ...commands.map((c) => ` $ ${formatCommand(c)}`)
1188
+ ].join(`
1189
+ `), "Install service");
1190
+ const ok = await Rt({ message: "Proceed?" });
1191
+ if (Ct(ok) || !ok) {
1192
+ R2.info("Aborted.");
1193
+ return;
1194
+ }
1195
+ mkdirSync(filePath.substring(0, filePath.lastIndexOf("/")), { recursive: true });
1196
+ await Bun.write(filePath, content);
1197
+ R2.success(`Wrote ${filePath}`);
1198
+ for (const cmd of commands) {
1199
+ const result = runCommand(cmd);
1200
+ if (!result.success) {
1201
+ R2.error(`Command failed: ${formatCommand(cmd)}
1202
+ ${result.stderr.toString()}`);
1203
+ return;
1204
+ }
1205
+ R2.success(`$ ${formatCommand(cmd)}`);
1206
+ }
1207
+ R2.success("Service installed and started!");
1208
+ if (config.platform === "linux") {
1209
+ Vt2(`To keep the service running after logout, run:
1210
+ loginctl enable-linger $USER
1211
+
1212
+ (May require admin privileges on some systems.)`, "Tip");
1213
+ }
1214
+ R2.info(`Check status: webmux service status`);
1215
+ R2.info(`View logs: webmux service logs`);
1216
+ }
1217
+ async function uninstall(config) {
1218
+ const filePath = serviceFilePath(config);
1219
+ if (!isInstalled(config)) {
1220
+ R2.error("Service is not installed.");
1221
+ return;
1222
+ }
1223
+ const commands = uninstallCommands(config);
1224
+ Vt2([
1225
+ `File to remove: ${filePath}`,
1226
+ "",
1227
+ "Commands to run:",
1228
+ ...commands.map((c) => ` $ ${formatCommand(c)}`)
1229
+ ].join(`
1230
+ `), "Uninstall service");
1231
+ const ok = await Rt({ message: "Proceed?" });
1232
+ if (Ct(ok) || !ok) {
1233
+ R2.info("Aborted.");
1234
+ return;
1235
+ }
1236
+ for (const cmd of commands) {
1237
+ const result = runCommand(cmd);
1238
+ if (!result.success) {
1239
+ R2.warning(`Command failed: ${formatCommand(cmd)}
1240
+ ${result.stderr.toString()}`);
1241
+ } else {
1242
+ R2.success(`$ ${formatCommand(cmd)}`);
1243
+ }
1244
+ }
1245
+ unlinkSync(filePath);
1246
+ R2.success(`Removed ${filePath}`);
1247
+ R2.success("Service uninstalled.");
1248
+ }
1249
+ function status(config) {
1250
+ if (!isInstalled(config)) {
1251
+ R2.error("Service is not installed.");
1252
+ return;
1253
+ }
1254
+ if (config.platform === "linux") {
1255
+ printRunResult(run("systemctl", ["--user", "status", config.serviceName]));
1256
+ } else {
1257
+ printRunResult(run("launchctl", ["list", `com.webmux.${config.serviceName}`]));
1258
+ }
1259
+ }
1260
+ function logs(config) {
1261
+ if (!isInstalled(config)) {
1262
+ R2.error("Service is not installed.");
1263
+ return;
1264
+ }
1265
+ let proc;
1266
+ if (config.platform === "linux") {
1267
+ proc = Bun.spawn(["journalctl", "--user", "-u", config.serviceName, "-f", "--no-pager"], { stdout: "inherit", stderr: "inherit" });
1268
+ } else {
1269
+ const logPath = join3(homedir(), "Library", "Logs", `webmux-${config.serviceName}.log`);
1270
+ if (!existsSync3(logPath)) {
1271
+ R2.error(`Log file not found: ${logPath}`);
1272
+ return;
1273
+ }
1274
+ proc = Bun.spawn(["tail", "-f", logPath], {
1275
+ stdout: "inherit",
1276
+ stderr: "inherit"
1277
+ });
1278
+ }
1279
+ process.on("SIGINT", () => proc.kill());
1280
+ proc.exited.then((code) => process.exit(code));
1281
+ }
1282
+ function usage() {
1283
+ console.log(`
1284
+ webmux service \u2014 Manage webmux as a system service
1285
+
1286
+ Usage:
1287
+ webmux service install Install, enable, and start the service
1288
+ webmux service uninstall Stop, disable, and remove the service
1289
+ webmux service status Show service status
1290
+ webmux service logs Tail service logs
1291
+ `);
1292
+ }
1293
+ async function service(args) {
1294
+ const action = args[0];
1295
+ if (!action || action === "--help" || action === "-h") {
1296
+ usage();
1297
+ return;
1298
+ }
1299
+ if (!["install", "uninstall", "status", "logs"].includes(action)) {
1300
+ R2.error(`Unknown action: ${action}`);
1301
+ usage();
1302
+ return;
1303
+ }
1304
+ const platform = getPlatform();
1305
+ if (!platform) {
1306
+ R2.error(`Unsupported platform: ${process.platform}. Only linux and macOS are supported.`);
1307
+ return;
1308
+ }
1309
+ const gitRoot2 = getGitRoot();
1310
+ if (!gitRoot2) {
1311
+ R2.error("Not inside a git repository.");
1312
+ return;
1313
+ }
1314
+ const serviceManager = platform === "linux" ? "systemctl" : "launchctl";
1315
+ const smResult = run("which", [serviceManager]);
1316
+ if (!smResult.success) {
1317
+ R2.error(`${serviceManager} not found. Cannot manage services on this system.`);
1318
+ return;
1319
+ }
1320
+ const webmuxPath = resolveWebmuxPath();
1321
+ if (!webmuxPath) {
1322
+ R2.error("Could not find webmux in PATH.");
1323
+ return;
1324
+ }
1325
+ let port = parseInt(process.env.BACKEND_PORT || "5111");
1326
+ for (let i = 1;i < args.length; i++) {
1327
+ if (args[i] === "--port" && args[i + 1]) {
1328
+ const parsed = parseInt(args[++i]);
1329
+ if (Number.isNaN(parsed)) {
1330
+ R2.error("--port requires a numeric value");
1331
+ return;
1332
+ }
1333
+ port = parsed;
1334
+ }
1335
+ }
1336
+ const projectName = detectProjectName(gitRoot2);
1337
+ const serviceName = `webmux-${sanitizeName(projectName)}`;
1338
+ const config = {
1339
+ platform,
1340
+ projectName,
1341
+ serviceName,
1342
+ webmuxPath,
1343
+ projectDir: gitRoot2,
1344
+ port
1345
+ };
1346
+ switch (action) {
1347
+ case "install":
1348
+ await install(config);
1349
+ break;
1350
+ case "uninstall":
1351
+ await uninstall(config);
1352
+ break;
1353
+ case "status":
1354
+ status(config);
1355
+ break;
1356
+ case "logs":
1357
+ logs(config);
1358
+ break;
1359
+ }
1360
+ }
1361
+ var init_service = __esm(() => {
1362
+ init_dist2();
1363
+ init_shared();
1364
+ });
1365
+
1366
+ // bin/src/webmux.ts
1367
+ import { resolve, dirname, join as join4 } from "path";
1368
+ import { existsSync as existsSync4 } from "fs";
1369
+ import { fileURLToPath } from "url";
1370
+ var PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
1371
+ function usage2() {
1372
+ console.log(`
1373
+ webmux \u2014 Dev dashboard for managing Git worktrees
1374
+
1375
+ Usage:
1376
+ webmux Start the dashboard
1377
+ webmux init Interactive project setup
1378
+ webmux service Manage webmux as a system service
1379
+ webmux --port N Set port (default: 5111)
1380
+ webmux --debug Show debug-level logs
1381
+ webmux --help Show this help message
1382
+
1383
+ Environment:
1384
+ BACKEND_PORT Same as --port (flag takes precedence)
1385
+ `);
1386
+ }
1387
+ var args = process.argv.slice(2);
1388
+ if (args[0] === "init") {
1389
+ await init_init().then(() => exports_init);
1390
+ process.exit(0);
1391
+ }
1392
+ if (args[0] === "service") {
1393
+ const { default: service2 } = await Promise.resolve().then(() => (init_service(), exports_service));
1394
+ await service2(args.slice(1));
1395
+ process.exit(0);
1396
+ }
1397
+ var port = parseInt(process.env.BACKEND_PORT || "5111");
1398
+ var debug = false;
1399
+ for (let i = 0;i < args.length; i++) {
1400
+ switch (args[i]) {
1401
+ case "--port":
1402
+ port = parseInt(args[++i]);
1403
+ if (Number.isNaN(port)) {
1404
+ console.error("Error: --port requires a numeric value");
1405
+ process.exit(1);
1406
+ }
1407
+ break;
1408
+ case "--debug":
1409
+ debug = true;
1410
+ break;
1411
+ case "--help":
1412
+ case "-h":
1413
+ usage2();
1414
+ process.exit(0);
1415
+ break;
1416
+ default:
1417
+ console.error(`Unknown option: ${args[i]}
1418
+ Run webmux --help for usage.`);
1419
+ process.exit(1);
1420
+ }
1421
+ }
1422
+ if (!existsSync4(resolve(process.cwd(), ".webmux.yaml"))) {
1423
+ console.error("No .webmux.yaml found in this directory.\nRun `webmux init` to set up your project.");
1424
+ process.exit(1);
1425
+ }
1426
+ async function loadEnvFile(path) {
1427
+ if (!existsSync4(path))
1428
+ return;
1429
+ const lines = (await Bun.file(path).text()).split(`
1430
+ `);
1431
+ for (const line of lines) {
1432
+ const trimmed = line.trim();
1433
+ if (!trimmed || trimmed.startsWith("#"))
1434
+ continue;
1435
+ const eq = trimmed.indexOf("=");
1436
+ if (eq === -1)
1437
+ continue;
1438
+ const key = trimmed.slice(0, eq).trim();
1439
+ const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
1440
+ if (!(key in process.env)) {
1441
+ process.env[key] = val;
1442
+ }
1443
+ }
1444
+ }
1445
+ await loadEnvFile(resolve(process.cwd(), ".env.local"));
1446
+ await loadEnvFile(resolve(process.cwd(), ".env"));
1447
+ var baseEnv = { ...process.env, BACKEND_PORT: String(port), WEBMUX_PROJECT_DIR: process.cwd(), ...debug ? { WEBMUX_DEBUG: "1" } : {} };
1448
+ function pipeWithPrefix(stream, prefix) {
1449
+ const reader = stream.getReader();
1450
+ const decoder = new TextDecoder;
1451
+ let buffer = "";
1452
+ (async () => {
1453
+ while (true) {
1454
+ const { done, value } = await reader.read();
1455
+ if (done)
1456
+ break;
1457
+ buffer += decoder.decode(value, { stream: true });
1458
+ const lines = buffer.split(`
1459
+ `);
1460
+ buffer = lines.pop();
1461
+ for (const line of lines) {
1462
+ console.log(`${prefix} ${line}`);
1463
+ }
1464
+ }
1465
+ if (buffer) {
1466
+ console.log(`${prefix} ${buffer}`);
1467
+ }
1468
+ })();
1469
+ }
1470
+ var children = [];
1471
+ var exiting = false;
1472
+ function cleanup() {
1473
+ if (exiting)
1474
+ return;
1475
+ exiting = true;
1476
+ for (const child of children) {
1477
+ try {
1478
+ child.kill("SIGTERM");
1479
+ } catch {}
1480
+ }
1481
+ setTimeout(() => {
1482
+ for (const child of children) {
1483
+ try {
1484
+ child.kill("SIGKILL");
1485
+ } catch {}
1486
+ }
1487
+ process.exit(0);
1488
+ }, 1000).unref();
1489
+ }
1490
+ process.on("SIGINT", cleanup);
1491
+ process.on("SIGTERM", cleanup);
1492
+ var backendEntry = join4(PKG_ROOT, "backend", "dist", "server.js");
1493
+ var staticDir = join4(PKG_ROOT, "frontend", "dist");
1494
+ if (!existsSync4(staticDir)) {
1495
+ console.error(`Error: frontend/dist/ not found. Run 'bun run build' first.`);
1496
+ process.exit(1);
1497
+ }
1498
+ console.log(`Starting webmux on port ${port}...`);
1499
+ var be = Bun.spawn(["bun", backendEntry], {
1500
+ env: { ...baseEnv, WEBMUX_STATIC_DIR: staticDir },
1501
+ stdout: "pipe",
1502
+ stderr: "pipe"
1503
+ });
1504
+ children.push(be);
1505
+ pipeWithPrefix(be.stdout, "[BE]");
1506
+ pipeWithPrefix(be.stderr, "[BE]");
1507
+ await be.exited;