hofii 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +268 -1
  2. package/dist/main.js +40 -40
  3. package/package.json +1 -2
package/README.md CHANGED
@@ -1 +1,268 @@
1
- ## Manage dotfile declaratively in Linux
1
+ # Hofii
2
+
3
+ > An orchestration tool for managing dotfiles and packages declaratively on Linux.
4
+
5
+ ![Hofii](https://img.shields.io/badge/hofii-dotfiles-blue)
6
+ ![License](https://img.shields.io/badge/license-MIT-green)
7
+ ![Bun](https://img.shields.io/badge/runtime-bun-orange)
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ Hofii is a declarative dotfile manager for Linux that helps you:
14
+ - **Manage symlinks** for configuration files across your system
15
+ - **Install packages** from multiple package managers (pacman, AUR, Flatpak)
16
+ - **Detect your environment** automatically (distro, package manager, AUR helper)
17
+ - **Track state** with a lock file for reproducible configurations
18
+ <!--
19
+ ## Features
20
+
21
+ | Feature | Description |
22
+ |---------|-------------|
23
+ | 🔗 **Symlink Management** | Create, update, and remove symlinks with backup support |
24
+ | 📦 **Package Management** | Install packages via pacman, AUR (yay/paru), and Flatpak |
25
+ | 🔍 **Environment Detection** | Auto-detects OS, package manager, AUR helper, Flatpak |
26
+ | 📋 **Declarative Config** | TOML-based configuration with import support |
27
+ | 🔄 **Diff & Apply** | See changes before applying with interactive confirmation |
28
+ | 💾 **State Tracking** | Lock file (`~/.cache/hofii/hofii-lock.json`) tracks applied config |-->
29
+
30
+ ## Installation
31
+
32
+ ### Prerequisites
33
+ - [Bun](https://bun.sh/) (v1.0+)
34
+ - Linux (Arch-based distributions fully supported)
35
+
36
+ ```bash
37
+ bun add -g hofii
38
+ ```
39
+ Only support with bun
40
+
41
+ <!--## Quick Start
42
+
43
+ ### 1. Create a Configuration Directory
44
+
45
+ ```bash
46
+ mkdir -p ~/.config/hofii
47
+ cd ~/.config/hofii
48
+ ```
49
+
50
+ ### 2. Create `config.toml`
51
+
52
+ ```toml
53
+ # ~/.config/hofii/config.toml
54
+ [settings]
55
+ aur_helper = "yay" # or "paru"
56
+ backup = true # backup existing files before symlinking
57
+
58
+ # Symlinks: source (relative to config.toml) -> target (absolute path with ~ expansion)
59
+ [[symlinks]]
60
+ source = "./config/fastfetch"
61
+ target = "~/.config/fastfetch"
62
+
63
+ [[symlinks]]
64
+ source = "./config/nvim"
65
+ target = "~/.config/nvim"
66
+
67
+ [[symlinks]]
68
+ source = "./config/zed"
69
+ target = "~/.config/zed"
70
+
71
+ # Packages to install
72
+ [[packages]]
73
+ manager = "pacman"
74
+ items = ["git", "neovim", "zsh", "btop"]
75
+
76
+ [[packages]]
77
+ manager = "aur"
78
+ items = ["visual-studio-code-bin", "google-chrome"]
79
+
80
+ [[packages]]
81
+ manager = "flatpak"
82
+ scope = "user"
83
+ items = ["com.spotify.Client", "org.telegram.desktop"]
84
+ ```
85
+
86
+ ### 3. Add Your Dotfiles
87
+
88
+ ```bash
89
+ mkdir -p ~/.config/hofii/config
90
+ # Copy or link your config directories here
91
+ cp -r ~/.config/nvim ~/.config/hofii/config/
92
+ cp -r ~/.config/fastfetch ~/.config/hofii/config/
93
+ ```
94
+
95
+ ### 4. Scan Your System
96
+
97
+ ```bash
98
+ hofii scan
99
+ # or
100
+ hofii s
101
+ ```
102
+
103
+ This detects your OS, package manager, AUR helper, and Flatpak availability.
104
+
105
+ ### 5. Validate Configuration
106
+
107
+ ```bash
108
+ hofii validate ~/.config/hofii
109
+ # or
110
+ hofii v ~/.config/hofii
111
+ ```
112
+
113
+ Validates your TOML config without applying changes.
114
+
115
+ ### 6. Apply Configuration
116
+
117
+ ```bash
118
+ hofii switch ~/.config/hofii
119
+ # or
120
+ hofii sw ~/.config/hofii
121
+ ```
122
+
123
+ Shows a diff of what will change, asks for confirmation, then applies symlinks.-->
124
+
125
+ ## Commands
126
+
127
+ | Command | Alias | Description |
128
+ |---------|-------|-------------|
129
+ | `hofii scan` | `s` | Detect system environment (OS, package manager, AUR helper, Flatpak) |
130
+ | `hofii validate [dir]` | `v` | Validate configuration files |
131
+ | `hofii switch [dir]` | `sw` | Switch to new configuration (apply symlinks) |
132
+
133
+ ## Configuration Reference
134
+
135
+ ### Settings
136
+
137
+ ```toml
138
+ [settings]
139
+ aur_helper = "yay" # AUR helper: "yay" or "paru"
140
+ backup = true # Backup existing files before creating symlinks
141
+ flatpak = true # Enable Flatpak support (auto-detected)
142
+ ```
143
+
144
+ ### Symlinks
145
+
146
+ ```toml
147
+ [[symlinks]]
148
+ source = "./config/nvim" # Relative to config.toml directory
149
+ target = "~/.config/nvim" # Target path (~ expands to $HOME)
150
+ sudo = false # Use sudo for creation (default: false)
151
+ ```
152
+
153
+ <!--### Packages
154
+
155
+ #### Pacman (Official Repositories)
156
+ ```toml
157
+ [[packages]]
158
+ manager = "pacman"
159
+ items = ["git", "neovim", "base-devel"]
160
+ ```
161
+
162
+ #### AUR (Arch User Repository)
163
+ ```toml
164
+ [[packages]]
165
+ manager = "aur"
166
+ items = [
167
+ "visual-studio-code-bin",
168
+ { name = "google-chrome", post_hooks = ["sudo systemctl enable --now chrome-remote-desktop"] }
169
+ ]
170
+ ```
171
+
172
+ #### Flatpak
173
+ ```toml
174
+ [[packages]]
175
+ manager = "flatpak"
176
+ scope = "user" # or "system"
177
+ items = ["com.spotify.Client", "org.telegram.desktop"]
178
+ ```-->
179
+
180
+ ### Imports (Modular Config)
181
+
182
+ Split your config across multiple files:
183
+
184
+ ```toml
185
+ # config.toml
186
+ imports = ["home.toml", "work.toml"]
187
+
188
+ [[symlinks]]
189
+ source = "./config/shared"
190
+ target = "~/.config/shared"
191
+ ```
192
+
193
+ ```toml
194
+ # home.toml
195
+ [[symlinks]]
196
+ source = "./config/hyprland"
197
+ target = "~/.config/hyprland"
198
+ ```
199
+
200
+ ## Project Structure
201
+
202
+ ```
203
+ hofii/
204
+ ├── src/
205
+ │ ├── commands/ # CLI commands (scan, validate, switch)
206
+ │ ├── core/
207
+ │ │ ├── config/ # Config parsing & validation (schema, parser)
208
+ │ │ ├── detect.ts # Environment detection
209
+ │ │ ├── diff.ts # Config diffing
210
+ │ │ └── symlink.ts # Symlink operations
211
+ │ ├── data/
212
+ │ │ ├── env.ts # Environment variables
213
+ │ │ ├── metadata.ts # Lock file management (~/.cache/hofii/)
214
+ │ │ └── os.ts # OS/Package manager detection
215
+ │ ├── pm/
216
+ │ │ └── pacman.ts # Pacman package operations
217
+ │ ├── types/ # TypeScript types
218
+ │ └── utils/ # Utilities (fs, path, spawn)
219
+ ├── example/ # Example configurations
220
+ ├── dist/ # Built output
221
+ └── index.ts # Entry point
222
+ ```
223
+
224
+ ## Lock File
225
+
226
+ Hofii maintains a lock file at `~/.cache/hofii/hofii-lock.json` that tracks:
227
+ - Applied symlinks (source, target, sudo)
228
+ - Configuration state
229
+
230
+ This enables:
231
+ - Diffing between current and desired state
232
+ - Safe removal of symlinks no longer in config
233
+ - Reproducible deployments
234
+
235
+ ## Example Configuration
236
+
237
+ See the `example/` directory for a complete working configuration:
238
+
239
+ ```
240
+ example/
241
+ ├── config.toml # Main config with symlinks
242
+ ├── home.toml # Additional config (imported)
243
+ ├── config/
244
+ │ ├── fastfetch/
245
+ │ ├── btop/
246
+ │ └── ...
247
+ └── .state/ # Example lock file
248
+ ```
249
+
250
+ ## Supported Distributions
251
+
252
+ | Distribution | Package Manager | Status |
253
+ |--------------|-----------------|--------|
254
+ | Arch Linux | pacman | ✅ Full support |
255
+ | EndeavourOS | pacman | ✅ Full support |
256
+ | Manjaro | pacman | ✅ Full support |
257
+ | Garuda | pacman | ✅ Full support |
258
+ | CachyOS | pacman | ✅ Full support |
259
+ | Fedora | dnf | 🔄 Planned |
260
+ | Nobara | dnf | 🔄 Planned |
261
+
262
+ ## License
263
+
264
+ MIT License - see [LICENSE](LICENSE) for details.
265
+
266
+ ---
267
+
268
+ **Note:** Hofii is in early development. Use with caution and always review the diff before applying changes.
package/dist/main.js CHANGED
@@ -1,55 +1,55 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var vn=Object.create;var{getPrototypeOf:$n,defineProperty:st,getOwnPropertyNames:bn}=Object;var kn=Object.prototype.hasOwnProperty;function wn(e){return this[e]}var xn,_n,rt=(e,t,n)=>{var s=e!=null&&typeof e==="object";if(s){var r=t?xn??=new WeakMap:_n??=new WeakMap,u=r.get(e);if(u)return u}n=e!=null?vn($n(e)):{};let o=t||!e||!e.__esModule?st(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of bn(e))if(!kn.call(o,a))st(o,a,{get:wn.bind(e,a),enumerable:!0})}if(s)r.set(e,o);return o};var En=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qe=En(function($r,Mt){var Ge={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},ss={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},rs={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Ge.up():"");if(e)t+=Ge.left;return t}};Mt.exports={cursor:Ge,scroll:ss,erase:rs,beep:"\x07"}});function De(e){return e==null?[]:Array.isArray(e)?e:[e]}function In(e,t,n,s){var r,u=e[t],o=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((r=+n,r*0===0)?r:n),!!n):(r=+n,r*0===0)?r:n;e[t]=u==null?o:Array.isArray(u)?u.concat(o):[u,o]}function Sn(e,t){e=e||[],t=t||{};var n,s,r,u,o,a={_:[]},i=0,l=0,c=0,f=e.length;let h=t.alias!==void 0,g=t.unknown!==void 0,m=t.default!==void 0;if(t.alias=t.alias||{},t.string=De(t.string),t.boolean=De(t.boolean),h)for(n in t.alias){s=t.alias[n]=De(t.alias[n]);for(i=0;i<s.length;i++)(t.alias[s[i]]=s.concat(n)).splice(i,1)}for(i=t.boolean.length;i-- >0;){s=t.alias[t.boolean[i]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(i=t.string.length;i-- >0;){s=t.alias[t.string[i]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(m){for(n in t.default)if(u=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[u]!==void 0){t[u].push(n);for(i=0;i<s.length;i++)t[u].push(s[i])}}let y=g?Object.keys(t.alias):[];for(i=0;i<f;i++){if(r=e[i],r==="--"){a._=a._.concat(e.slice(++i));break}for(l=0;l<r.length;l++)if(r.charCodeAt(l)!==45)break;if(l===0)a._.push(r);else if(r.substring(l,l+3)==="no-"){if(u=r.substring(l+3),g&&!~y.indexOf(u))return t.unknown(r);a[u]=!1}else{for(c=l+1;c<r.length;c++)if(r.charCodeAt(c)===61)break;u=r.substring(l,c),o=r.substring(++c)||i+1===f||(""+e[i+1]).charCodeAt(0)===45||e[++i],s=l===2?[u]:u;for(c=0;c<s.length;c++){if(u=s[c],g&&!~y.indexOf(u))return t.unknown("-".repeat(l)+u);In(a,u,c+1<s.length||o,t)}}}if(m){for(n in t.default)if(a[n]===void 0)a[n]=t.default[n]}if(h)for(n in a){s=t.alias[n]||[];while(s.length>0)a[s.shift()]=a[n]}return a}function ot(e){return e.replace(/[<[].+/,"").trim()}function Cn(e){let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],r=(a)=>{let i=!1,l=a[1];if(l.startsWith("..."))l=l.slice(3),i=!0;return{required:a[0].startsWith("<"),value:l,variadic:i}},u;while(u=t.exec(e))s.push(r(u));let o;while(o=n.exec(e))s.push(r(o));return s}function An(e){let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((r,u)=>u!==n&&r.names.some((o)=>s.names.includes(o))&&typeof r.required==="boolean"))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t}function it(e){return e.sort((t,n)=>t.length>n.length?-1:1)[0]}function ut(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function On(e){return e.replaceAll(/([a-z])-([a-z])/g,(t,n,s)=>n+s.toUpperCase())}function Mn(e,t,n){let s=e;for(let r=0;r<t.length;r++){let u=t[r];if(r===t.length-1){s[u]=n;return}if(s[u]==null){let o=+t[r+1]>-1;s[u]=o?[]:{}}s=s[u]}}function Dn(e,t){for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=[e[n]].flat(),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}}function Fn(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function at(e){return e.split(".").map((t,n)=>n===0?On(t):t).join(".")}var ae=class extends Error{constructor(e){super(e);if(this.name="CACError",typeof Error.captureStackTrace!=="function")this.stack=Error(e).stack}},jn=class{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replaceAll(".*",""),this.negated=!1,this.names=ot(e).split(",").map((s)=>{let r=s.trim().replace(/^-{1,2}/,"");if(r.startsWith("no-"))this.negated=!0,r=r.replace(/^no-/,"");return at(r)}).sort((s,r)=>s.length>r.length?1:-1),this.name=this.names.at(-1),this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}},Fe,le;if(typeof process<"u"){let e;if(typeof Deno<"u"&&typeof Deno.version?.deno==="string")e="deno";else if(typeof Bun<"u"&&typeof Bun.version==="string")e="bun";else e="node";le=`${process.platform}-${process.arch} ${e}-${process.version}`,Fe=process.argv}else if(typeof navigator>"u")le="unknown";else le=`${navigator.platform} ${navigator.userAgent}`;var lt=class{rawName;description;config;cli;options;aliasNames;name;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=ot(e),this.args=Cn(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new jn(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof ct}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:r}=this.cli.globalCommand,u=[{body:`${e}${n?`/${n}`:""}`}];if(u.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let a=it(t.map((i)=>i.rawName));u.push({title:"Commands",body:t.map((i)=>` ${ut(i.rawName,a.length)} ${i.description}`).join(`
4
- `)},{title:"For more info, run any command with the `--help` flag",body:t.map((i)=>` $ ${e}${i.name===""?"":` ${i.name}`} --help`).join(`
5
- `)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=it(o.map((i)=>i.rawName));u.push({title:"Options",body:o.map((i)=>` ${ut(i.rawName,a.length)} ${i.description} ${i.config.default===void 0?"":`(default: ${i.config.default})`}`).join(`
6
- `)})}if(this.examples.length>0)u.push({title:"Examples",body:this.examples.map((a)=>{if(typeof a==="function")return a(e);return a}).join(`
7
- `)});if(r)u=r(u)||u;console.info(u.map((a)=>a.title?`${a.title}:
3
+ var bn=Object.create;var{getPrototypeOf:kn,defineProperty:it,getOwnPropertyNames:wn}=Object;var xn=Object.prototype.hasOwnProperty;function _n(e){return this[e]}var En,In,ut=(e,t,n)=>{var s=e!=null&&typeof e==="object";if(s){var r=t?En??=new WeakMap:In??=new WeakMap,i=r.get(e);if(i)return i}n=e!=null?bn(kn(e)):{};let o=t||!e||!e.__esModule?it(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of wn(e))if(!xn.call(o,a))it(o,a,{get:_n.bind(e,a),enumerable:!0})}if(s)r.set(e,o);return o};var Sn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var We=Sn(function(br,Ft){var Be={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},rs={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},is={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Be.up():"");if(e)t+=Be.left;return t}};Ft.exports={cursor:Be,scroll:rs,erase:is,beep:"\x07"}});function je(e){return e==null?[]:Array.isArray(e)?e:[e]}function Cn(e,t,n,s){var r,i=e[t],o=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((r=+n,r*0===0)?r:n),!!n):(r=+n,r*0===0)?r:n;e[t]=i==null?o:Array.isArray(i)?i.concat(o):[i,o]}function An(e,t){e=e||[],t=t||{};var n,s,r,i,o,a={_:[]},u=0,l=0,c=0,f=e.length;let h=t.alias!==void 0,v=t.unknown!==void 0,m=t.default!==void 0;if(t.alias=t.alias||{},t.string=je(t.string),t.boolean=je(t.boolean),h)for(n in t.alias){s=t.alias[n]=je(t.alias[n]);for(u=0;u<s.length;u++)(t.alias[s[u]]=s.concat(n)).splice(u,1)}for(u=t.boolean.length;u-- >0;){s=t.alias[t.boolean[u]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(u=t.string.length;u-- >0;){s=t.alias[t.string[u]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(m){for(n in t.default)if(i=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[i]!==void 0){t[i].push(n);for(u=0;u<s.length;u++)t[i].push(s[u])}}let y=v?Object.keys(t.alias):[];for(u=0;u<f;u++){if(r=e[u],r==="--"){a._=a._.concat(e.slice(++u));break}for(l=0;l<r.length;l++)if(r.charCodeAt(l)!==45)break;if(l===0)a._.push(r);else if(r.substring(l,l+3)==="no-"){if(i=r.substring(l+3),v&&!~y.indexOf(i))return t.unknown(r);a[i]=!1}else{for(c=l+1;c<r.length;c++)if(r.charCodeAt(c)===61)break;i=r.substring(l,c),o=r.substring(++c)||u+1===f||(""+e[u+1]).charCodeAt(0)===45||e[++u],s=l===2?[i]:i;for(c=0;c<s.length;c++){if(i=s[c],v&&!~y.indexOf(i))return t.unknown("-".repeat(l)+i);Cn(a,i,c+1<s.length||o,t)}}}if(m){for(n in t.default)if(a[n]===void 0)a[n]=t.default[n]}if(h)for(n in a){s=t.alias[n]||[];while(s.length>0)a[s.shift()]=a[n]}return a}function lt(e){return e.replace(/[<[].+/,"").trim()}function On(e){let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],r=(a)=>{let u=!1,l=a[1];if(l.startsWith("..."))l=l.slice(3),u=!0;return{required:a[0].startsWith("<"),value:l,variadic:u}},i;while(i=t.exec(e))s.push(r(i));let o;while(o=n.exec(e))s.push(r(o));return s}function Mn(e){let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((r,i)=>i!==n&&r.names.some((o)=>s.names.includes(o))&&typeof r.required==="boolean"))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t}function ot(e){return e.sort((t,n)=>t.length>n.length?-1:1)[0]}function at(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function Dn(e){return e.replaceAll(/([a-z])-([a-z])/g,(t,n,s)=>n+s.toUpperCase())}function Fn(e,t,n){let s=e;for(let r=0;r<t.length;r++){let i=t[r];if(r===t.length-1){s[i]=n;return}if(s[i]==null){let o=+t[r+1]>-1;s[i]=o?[]:{}}s=s[i]}}function jn(e,t){for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=[e[n]].flat(),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}}function Tn(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function ct(e){return e.split(".").map((t,n)=>n===0?Dn(t):t).join(".")}var le=class extends Error{constructor(e){super(e);if(this.name="CACError",typeof Error.captureStackTrace!=="function")this.stack=Error(e).stack}},Rn=class{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replaceAll(".*",""),this.negated=!1,this.names=lt(e).split(",").map((s)=>{let r=s.trim().replace(/^-{1,2}/,"");if(r.startsWith("no-"))this.negated=!0,r=r.replace(/^no-/,"");return ct(r)}).sort((s,r)=>s.length>r.length?1:-1),this.name=this.names.at(-1),this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}},Te,ce;if(typeof process<"u"){let e;if(typeof Deno<"u"&&typeof Deno.version?.deno==="string")e="deno";else if(typeof Bun<"u"&&typeof Bun.version==="string")e="bun";else e="node";ce=`${process.platform}-${process.arch} ${e}-${process.version}`,Te=process.argv}else if(typeof navigator>"u")ce="unknown";else ce=`${navigator.platform} ${navigator.userAgent}`;var ft=class{rawName;description;config;cli;options;aliasNames;name;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=lt(e),this.args=On(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new Rn(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof pt}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:r}=this.cli.globalCommand,i=[{body:`${e}${n?`/${n}`:""}`}];if(i.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let a=ot(t.map((u)=>u.rawName));i.push({title:"Commands",body:t.map((u)=>` ${at(u.rawName,a.length)} ${u.description}`).join(`
4
+ `)},{title:"For more info, run any command with the `--help` flag",body:t.map((u)=>` $ ${e}${u.name===""?"":` ${u.name}`} --help`).join(`
5
+ `)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=ot(o.map((u)=>u.rawName));i.push({title:"Options",body:o.map((u)=>` ${at(u.rawName,a.length)} ${u.description} ${u.config.default===void 0?"":`(default: ${u.config.default})`}`).join(`
6
+ `)})}if(this.examples.length>0)i.push({title:"Examples",body:this.examples.map((a)=>{if(typeof a==="function")return a(e);return a}).join(`
7
+ `)});if(r)i=r(i)||i;console.info(i.map((a)=>a.title?`${a.title}:
8
8
  ${a.body}`:a.body).join(`
9
9
 
10
- `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${le}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new ae(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new ae(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let u=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!u)throw new ae(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new ae(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},ct=class extends lt{constructor(e){super("@@global@@","",{},e)}},Tn=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new ct(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new lt(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!Fe)throw Error("No argv provided and runtime process argv is not available.");e=Fe}if(this.rawArgs=e,!this.name)this.name=e[1]?Fn(e[1]):"cli";let n=!0;for(let r of this.commands){let u=this.mri(e.slice(2),r),o=u.args[0];if(r.isMatched(o)){n=!1;let a={...u,args:u.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let u=this.mri(e.slice(2),r);this.setParsedInfo(u,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=An(n),r=[],u=e.indexOf("--");if(u!==-1)r=e.slice(u+1),e=e.slice(0,u);let o=Sn(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[at(h)]:o[h]}),{_:[]});let a=o._,i={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)i[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")Mn(i,f.split("."),o[f]),Dn(i,c);return{args:a,options:i}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,u)=>{if(r.variadic)s.push(e.slice(u));else s.push(e[u])}),s.push(t),n.commandAction.apply(this,s)}},ft=(e="")=>new Tn(e);import sr from"path";var ce,Rn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function mt(e){if(!e&&!ce)return Rn;return{lang:e?.lang??ce?.lang,message:e?.message,abortEarly:e?.abortEarly??ce?.abortEarly,abortPipeEarly:e?.abortPipeEarly??ce?.abortPipeEarly}}var Pn;function Nn(e){return Pn?.get(e)}var Vn;function Ln(e){return Vn?.get(e)}var Gn;function qn(e,t){return Gn?.get(e)?.get(t)}function je(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function P(e,t,n,s,r){let u=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??je(u),i={kind:e.kind,type:e.type,input:u,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??qn(e.reference,i.lang)??(l?Ln(i.lang):null)??s.message??Nn(i.lang);if(c!==void 0)i.message=typeof c==="function"?c(i):c;if(l)n.typed=!1;if(n.issues)n.issues.push(i);else n.issues=[i]}var pt=new WeakMap;function N(e){let t=pt.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},mt())}},pt.set(e,t);return t}function yt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var Te=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function Un(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function dt(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function V(e,t){return{kind:"schema",type:"array",reference:V,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let u=0;u<r.length;u++){let o=r[u],a=this.item["~run"]({value:o},s);if(a.issues){let i={type:"array",origin:"value",input:r,key:u,value:o};for(let l of a.issues){if(l.path)l.path.unshift(i);else l.path=[i];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else P(this,"type",n,s);return n}}}function Q(e){return{kind:"schema",type:"boolean",reference:Q,expects:"boolean",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else P(this,"type",t,n);return t}}}function Re(e,t){return{kind:"schema",type:"literal",reference:Re,expects:je(e),async:!1,literal:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else P(this,"type",n,s);return n}}}function W(e,t){return{kind:"schema",type:"object",reference:W,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let u in this.entries){let o=this.entries[u];if(u in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=u in r?r[u]:dt(o),i=o["~run"]({value:a},s);if(i.issues){let l={type:"object",origin:"value",input:r,key:u,value:a};for(let c of i.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=i.issues;if(s.abortEarly){n.typed=!1;break}}if(!i.typed)n.typed=!1;n.value[u]=i.value}else if(o.fallback!==void 0)n.value[u]=Un(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(P(this,"key",n,s,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:r,key:u,value:r[u]}]}),s.abortEarly)break}}}else P(this,"type",n,s);return n}}}function ee(e,t){return{kind:"schema",type:"optional",reference:ee,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=dt(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function te(e,t){return{kind:"schema",type:"picklist",reference:te,expects:yt(e.map(je),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else P(this,"type",n,s);return n}}}function D(e){return{kind:"schema",type:"string",reference:D,expects:"string",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else P(this,"type",t,n);return t}}}function ht(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function ne(e,t){return{kind:"schema",type:"union",reference:ne,expects:yt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r,u,o;for(let a of this.options){let i=a["~run"]({value:n.value},s);if(i.typed)if(i.issues)if(u)u.push(i);else u=[i];else{r=i;break}else if(o)o.push(i);else o=[i]}if(r)return r;if(u){if(u.length===1)return u[0];P(this,"type",n,s,{issues:ht(u)}),n.typed=!0}else if(o?.length===1)return o[0];else P(this,"type",n,s,{issues:ht(o)});return n}}}function fe(e,t,n){let s=e["~run"]({value:t},mt(n));if(s.issues)throw new Te(s.issues);return s.value}function Pe(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?ee(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return N(this)}}}import{stdout as Be,stdin as Ft}from"process";import*as H from"readline";import is from"readline";var gt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),vt=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,$t=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||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>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Bn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Wn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,bt=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Hn=/\t{1,1000}/y,kt=/[\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,zn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Kn=/\p{M}+/gu,Xn={limit:1/0,ellipsis:""},wt=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",u=t?.ellipsisWidth??(r?wt(r,Xn,n).width:0),o=0,a=n.controlWidth??0,i=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,g=[[zn,f],[Bn,0],[Wn,a],[Hn,i],[kt,l],[bt,h]],m=0,y=0,F=e.length,q=0,U=!1,O=F,j=Math.max(0,s-u),I=0,J=0,M=0,E=0;e:while(!0){if(J>I||y>=F&&y>m){let B=e.slice(I,J)||e.slice(m,y);q=0;for(let K of B.replaceAll(Kn,"")){let S=K.codePointAt(0)||0;if(vt(S))E=2;else if($t(S))E=h;else E=f;if(M+E>j)O=Math.min(O,Math.max(I,m)+q);if(M+E>s){U=!0;break e}q+=K.length,M+=E}I=J=0}if(y>=F)break e;for(let B=0,K=g.length;B<K;B++){let[S,ue]=g[B];if(S.lastIndex=y,S.test(e)){if(q=S===bt?gt(e.slice(y,S.lastIndex)):S===kt?1:S.lastIndex-y,E=q*ue,M+E>j)O=Math.min(O,y+Math.floor((j-M)/ue));if(M+E>s){U=!0;break e}M+=E,I=m,J=y,y=m=S.lastIndex;continue e}}y+=1}return{width:U?j:M,index:U?O:F,truncated:U,ellipsed:U&&s>=u}},xt=wt;var Jn={limit:1/0,ellipsis:"",ellipsisWidth:0},Zn=(e,t={})=>xt(e,Jn,t).width,w=Zn;var he="\x1B",Ct="\x9B",Yn=39,Ve="\x07",At="[",Qn="]",Ot="m",Le=`${Qn}8;;`,_t=new RegExp(`(?:\\${At}(?<code>\\d+)m|\\${Le}(?<uri>.*)${Ve})`,"y"),Et=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},It=(e)=>`${he}${At}${e}${Ot}`,St=(e)=>`${he}${Le}${e}${Ve}`,Ne=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,u=!1,o=e.at(-1),a=o===void 0?0:w(o),i=s.next(),l=s.next(),c=0;while(!i.done){let f=i.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===he||f===Ct)r=!0,u=t.startsWith(Le,c+1);if(r){if(u){if(f===Ve)r=!1,u=!1}else if(f===Ot)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;i=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},es=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},ts=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,u,o=e.split(" "),a=[""],i=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",y=m.trimStart();if(m.length!==y.length)a[a.length-1]=y,i=w(y)}if(f!==0){if(i>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),i=0;if(i||n.trim===!1)a[a.length-1]+=" ",i++}let g=w(h);if(n.hard&&g>t){let m=t-i,y=1+Math.floor((g-m-1)/t);if(Math.floor((g-1)/t)<y)a.push("");Ne(a,h,t),i=w(a.at(-1)??"");continue}if(i+g>t&&i&&g){if(n.wordWrap===!1&&i<t){Ne(a,h,t),i=w(a.at(-1)??"");continue}a.push(""),i=0}if(i+g>t&&n.wordWrap===!1){Ne(a,h,t),i=w(a.at(-1)??"");continue}a[a.length-1]+=h,i+=g}if(n.trim!==!1)a=a.map((f)=>es(f));let l=a.join(`
11
- `),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===he||h===Ct){_t.lastIndex=f+1;let m=_t.exec(l)?.groups;if(m?.code!==void 0){let y=Number.parseFloat(m.code);r=y===Yn?void 0:y}else if(m?.uri!==void 0)u=m.uri.length===0?void 0:m.uri}if(l[f+1]===`
12
- `){if(u)s+=St("");let g=r?Et(r):void 0;if(r&&g)s+=It(g)}else if(h===`
13
- `){if(r&&Et(r))s+=It(r);if(u)s+=St(u)}}return s},ns=/\r?\n/;function L(e,t,n){return String(e).normalize().split(ns).map((s)=>ts(s,t,n)).join(`
14
- `)}var k=rt(qe(),1);import{ReadStream as Dt}from"tty";var us=["up","down","left","right","space","enter","cancel"],os=["January","February","March","April","May","June","July","August","September","October","November","December"],_={actions:new Set(us),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...os],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:(e)=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:(e)=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function We(e,t){if(typeof e=="string")return _.aliases.get(e)===t;for(let n of e)if(n!==void 0&&We(n,t))return!0;return!1}function as(e,t){if(e===t)return;let n=e.split(`
10
+ `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${ce}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new le(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new le(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let i=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!i)throw new le(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new le(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},pt=class extends ft{constructor(e){super("@@global@@","",{},e)}},Pn=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new pt(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new ft(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!Te)throw Error("No argv provided and runtime process argv is not available.");e=Te}if(this.rawArgs=e,!this.name)this.name=e[1]?Tn(e[1]):"cli";let n=!0;for(let r of this.commands){let i=this.mri(e.slice(2),r),o=i.args[0];if(r.isMatched(o)){n=!1;let a={...i,args:i.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let i=this.mri(e.slice(2),r);this.setParsedInfo(i,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=Mn(n),r=[],i=e.indexOf("--");if(i!==-1)r=e.slice(i+1),e=e.slice(0,i);let o=An(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[ct(h)]:o[h]}),{_:[]});let a=o._,u={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)u[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")Fn(u,f.split("."),o[f]),jn(u,c);return{args:a,options:u}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,i)=>{if(r.variadic)s.push(e.slice(i));else s.push(e[i])}),s.push(t),n.commandAction.apply(this,s)}},ht=(e="")=>new Pn(e);import rr from"path";var fe,Nn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function dt(e){if(!e&&!fe)return Nn;return{lang:e?.lang??fe?.lang,message:e?.message,abortEarly:e?.abortEarly??fe?.abortEarly,abortPipeEarly:e?.abortPipeEarly??fe?.abortPipeEarly}}var Vn;function Ln(e){return Vn?.get(e)}var Gn;function qn(e){return Gn?.get(e)}var Un;function Bn(e,t){return Un?.get(e)?.get(t)}function Re(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function A(e,t,n,s,r){let i=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??Re(i),u={kind:e.kind,type:e.type,input:i,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??Bn(e.reference,u.lang)??(l?qn(u.lang):null)??s.message??Ln(u.lang);if(c!==void 0)u.message=typeof c==="function"?c(u):c;if(l)n.typed=!1;if(n.issues)n.issues.push(u);else n.issues=[u]}var mt=new WeakMap;function F(e){let t=mt.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},dt())}},mt.set(e,t);return t}function gt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var ee=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function vt(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function Pe(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function V(e,t){return{kind:"schema",type:"array",reference:V,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let i=0;i<r.length;i++){let o=r[i],a=this.item["~run"]({value:o},s);if(a.issues){let u={type:"array",origin:"value",input:r,key:i,value:o};for(let l of a.issues){if(l.path)l.path.unshift(u);else l.path=[u];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else A(this,"type",n,s);return n}}}function te(e){return{kind:"schema",type:"boolean",reference:te,expects:"boolean",async:!1,message:e,get "~standard"(){return F(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else A(this,"type",t,n);return t}}}function Ne(e,t){return{kind:"schema",type:"literal",reference:Ne,expects:Re(e),async:!1,literal:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else A(this,"type",n,s);return n}}}function K(e,t){return{kind:"schema",type:"object",reference:K,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let i in this.entries){let o=this.entries[i];if(i in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=i in r?r[i]:Pe(o),u=o["~run"]({value:a},s);if(u.issues){let l={type:"object",origin:"value",input:r,key:i,value:a};for(let c of u.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=u.issues;if(s.abortEarly){n.typed=!1;break}}if(!u.typed)n.typed=!1;n.value[i]=u.value}else if(o.fallback!==void 0)n.value[i]=vt(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(A(this,"key",n,s,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]}),s.abortEarly)break}}}else A(this,"type",n,s);return n}}}function ne(e,t){return{kind:"schema",type:"optional",reference:ne,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return F(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=Pe(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function se(e,t){return{kind:"schema",type:"picklist",reference:se,expects:gt(e.map(Re),"|"),async:!1,options:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else A(this,"type",n,s);return n}}}function Ve(e,t){return{kind:"schema",type:"strict_object",reference:Ve,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let i in this.entries){let o=this.entries[i];if(i in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=i in r?r[i]:Pe(o),u=o["~run"]({value:a},s);if(u.issues){let l={type:"object",origin:"value",input:r,key:i,value:a};for(let c of u.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=u.issues;if(s.abortEarly){n.typed=!1;break}}if(!u.typed)n.typed=!1;n.value[i]=u.value}else if(o.fallback!==void 0)n.value[i]=vt(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(A(this,"key",n,s,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]}),s.abortEarly)break}}if(!n.issues||!s.abortEarly){for(let i in r)if(!(i in this.entries)){A(this,"key",n,s,{input:i,expected:"never",path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]});break}}}else A(this,"type",n,s);return n}}}function j(e){return{kind:"schema",type:"string",reference:j,expects:"string",async:!1,message:e,get "~standard"(){return F(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else A(this,"type",t,n);return t}}}function yt(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function re(e,t){return{kind:"schema",type:"union",reference:re,expects:gt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r,i,o;for(let a of this.options){let u=a["~run"]({value:n.value},s);if(u.typed)if(u.issues)if(i)i.push(u);else i=[u];else{r=u;break}else if(o)o.push(u);else o=[u]}if(r)return r;if(i){if(i.length===1)return i[0];A(this,"type",n,s,{issues:yt(i)}),n.typed=!0}else if(o?.length===1)return o[0];else A(this,"type",n,s,{issues:yt(o)});return n}}}function pe(e,t,n){let s=e["~run"]({value:t},dt(n));if(s.issues)throw new ee(s.issues);return s.value}function Le(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?ne(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return F(this)}}}import{stdout as ze,stdin as Tt}from"process";import*as W from"readline";import us from"readline";var $t=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),bt=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,kt=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||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>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Wn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Hn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,wt=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,zn=/\t{1,1000}/y,xt=/[\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,Kn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Xn=/\p{M}+/gu,Jn={limit:1/0,ellipsis:""},_t=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",i=t?.ellipsisWidth??(r?_t(r,Jn,n).width:0),o=0,a=n.controlWidth??0,u=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,v=[[Kn,f],[Wn,0],[Hn,a],[zn,u],[xt,l],[wt,h]],m=0,y=0,T=e.length,q=0,U=!1,M=T,R=Math.max(0,s-i),I=0,J=0,D=0,E=0;e:while(!0){if(J>I||y>=T&&y>m){let B=e.slice(I,J)||e.slice(m,y);q=0;for(let z of B.replaceAll(Xn,"")){let S=z.codePointAt(0)||0;if(bt(S))E=2;else if(kt(S))E=h;else E=f;if(D+E>R)M=Math.min(M,Math.max(I,m)+q);if(D+E>s){U=!0;break e}q+=z.length,D+=E}I=J=0}if(y>=T)break e;for(let B=0,z=v.length;B<z;B++){let[S,oe]=v[B];if(S.lastIndex=y,S.test(e)){if(q=S===wt?$t(e.slice(y,S.lastIndex)):S===xt?1:S.lastIndex-y,E=q*oe,D+E>R)M=Math.min(M,y+Math.floor((R-D)/oe));if(D+E>s){U=!0;break e}D+=E,I=m,J=y,y=m=S.lastIndex;continue e}}y+=1}return{width:U?R:D,index:U?M:T,truncated:U,ellipsed:U&&s>=i}},Et=_t;var Zn={limit:1/0,ellipsis:"",ellipsisWidth:0},Yn=(e,t={})=>Et(e,Zn,t).width,w=Yn;var me="\x1B",Ot="\x9B",Qn=39,qe="\x07",Mt="[",es="]",Dt="m",Ue=`${es}8;;`,It=new RegExp(`(?:\\${Mt}(?<code>\\d+)m|\\${Ue}(?<uri>.*)${qe})`,"y"),St=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},Ct=(e)=>`${me}${Mt}${e}${Dt}`,At=(e)=>`${me}${Ue}${e}${qe}`,Ge=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,i=!1,o=e.at(-1),a=o===void 0?0:w(o),u=s.next(),l=s.next(),c=0;while(!u.done){let f=u.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===me||f===Ot)r=!0,i=t.startsWith(Ue,c+1);if(r){if(i){if(f===qe)r=!1,i=!1}else if(f===Dt)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;u=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},ts=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},ns=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,i,o=e.split(" "),a=[""],u=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",y=m.trimStart();if(m.length!==y.length)a[a.length-1]=y,u=w(y)}if(f!==0){if(u>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),u=0;if(u||n.trim===!1)a[a.length-1]+=" ",u++}let v=w(h);if(n.hard&&v>t){let m=t-u,y=1+Math.floor((v-m-1)/t);if(Math.floor((v-1)/t)<y)a.push("");Ge(a,h,t),u=w(a.at(-1)??"");continue}if(u+v>t&&u&&v){if(n.wordWrap===!1&&u<t){Ge(a,h,t),u=w(a.at(-1)??"");continue}a.push(""),u=0}if(u+v>t&&n.wordWrap===!1){Ge(a,h,t),u=w(a.at(-1)??"");continue}a[a.length-1]+=h,u+=v}if(n.trim!==!1)a=a.map((f)=>ts(f));let l=a.join(`
11
+ `),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===me||h===Ot){It.lastIndex=f+1;let m=It.exec(l)?.groups;if(m?.code!==void 0){let y=Number.parseFloat(m.code);r=y===Qn?void 0:y}else if(m?.uri!==void 0)i=m.uri.length===0?void 0:m.uri}if(l[f+1]===`
12
+ `){if(i)s+=At("");let v=r?St(r):void 0;if(r&&v)s+=Ct(v)}else if(h===`
13
+ `){if(r&&St(r))s+=Ct(r);if(i)s+=At(i)}}return s},ss=/\r?\n/;function L(e,t,n){return String(e).normalize().split(ss).map((s)=>ns(s,t,n)).join(`
14
+ `)}var k=ut(We(),1);import{ReadStream as jt}from"tty";var os=["up","down","left","right","space","enter","cancel"],as=["January","February","March","April","May","June","July","August","September","October","November","December"],_={actions:new Set(os),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...as],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:(e)=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:(e)=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function Ke(e,t){if(typeof e=="string")return _.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Ke(n,t))return!0;return!1}function ls(e,t){if(e===t)return;let n=e.split(`
15
15
  `),s=t.split(`
16
- `),r=Math.max(n.length,s.length),u=[];for(let o=0;o<r;o++)n[o]!==s[o]&&u.push(o);return{lines:u,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}var ls=globalThis.process.platform.startsWith("win"),Ue=Symbol("clack:cancel");function ye(e){return e===Ue}function me(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function jt({input:e=Ft,output:t=Be,overwrite:n=!0,hideCursor:s=!0}={}){let r=H.createInterface({input:e,output:t,prompt:"",tabSize:1});H.emitKeypressEvents(e,r),e instanceof Dt&&e.isTTY&&e.setRawMode(!0);let u=(o,{name:a,sequence:i})=>{let l=String(o);if(We([l,a,i],"cancel")){s&&t.write(k.cursor.show),process.exit(0);return}if(!n)return;H.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{H.clearLine(t,1,()=>{e.once("keypress",u)})})};return s&&t.write(k.cursor.hide),e.once("keypress",u),()=>{e.off("keypress",u),s&&t.write(k.cursor.show),e instanceof Dt&&e.isTTY&&!ls&&e.setRawMode(!1),r.terminal=!1,r.close()}}var de=(e)=>("columns"in e)&&typeof e.columns=="number"?e.columns:80,Tt=(e)=>("rows"in e)&&typeof e.rows=="number"?e.rows:20;function Rt(e,t,n,s=n,r=n,u){let o=de(e??Be);return L(t,o-n.length,{hard:!0,trim:!1}).split(`
17
- `).map((a,i,l)=>{let c=u?u(a,i):a;return i===0?`${s}${c}`:i===l.length-1?`${r}${c}`:`${n}${c}`}).join(`
18
- `)}function Pt(e,t){if("~standard"in e){let n=e["~standard"].validate(t);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return e(t)}class Nt{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,t=!0){let{input:n=Ft,output:s=Be,render:r,signal:u,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=t,this._abortSignal=u,this.input=n,this.output=s}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],s=[];for(let r of n)r.cb(...t),r.once&&s.push(()=>n.splice(n.indexOf(r),1));for(let r of s)r()}prompt(){return new Promise((e)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(Ue);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=is.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),me(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),me(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),me(this.input,!1),e(Ue)})})}_isActionKey(e,t){return e==="\t"}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,t){this.userInput=e??"",this.emit("userInput",this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(e,t){if(this._track&&t.name!=="return"&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),t?.name&&(!this._track&&_.aliases.has(t.name)&&this.emit("cursor",_.aliases.get(t.name)),_.actions.has(t.name)&&this.emit("cursor",t.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,t),t?.name==="return"&&this._shouldSubmit(e,t)){if(this.opts.validate){let n=Pt(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}We([e,t?.name,t?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
19
- `),me(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=L(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
20
- `).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=L(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(k.cursor.hide);else{let t=as(this._prevFrame,e),n=Tt(this.output);if(this.restoreCursor(),t){let s=Math.max(0,t.numLinesAfter-n),r=Math.max(0,t.numLinesBefore-n),u=t.lines.find((o)=>o>=s);if(u===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(k.cursor.move(0,u-r)),this.output.write(k.erase.lines(1));let o=e.split(`
21
- `);this.output.write(o[u]),this._prevFrame=e,this.output.write(k.cursor.move(0,o.length-u-1));return}else if(t.lines.length>1){if(s<r)u=s;else{let a=u-r;a>0&&this.output.write(k.cursor.move(0,a))}this.output.write(k.erase.down());let o=e.split(`
22
- `).slice(u);this.output.write(o.join(`
23
- `)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}class He extends Nt{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(k.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}import{styleText as p,stripVTControlCharacters as Pr}from"util";import A from"process";var se=rt(qe(),1);function cs(){if(A.platform!=="win32")return A.env.TERM!=="linux";return Boolean(A.env.CI)||Boolean(A.env.WT_SESSION)||Boolean(A.env.TERMINUS_SUBLIME)||A.env.ConEmuTask==="{cmd::Cmder}"||A.env.TERM_PROGRAM==="Terminus-Sublime"||A.env.TERM_PROGRAM==="vscode"||A.env.TERM==="xterm-256color"||A.env.TERM==="alacritty"||A.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var ze=cs(),fs=()=>process.env.CI==="true";var d=(e,t)=>ze?e:t,ps=d("\u25C6","*"),qt=d("\u25A0","x"),Ut=d("\u25B2","x"),ge=d("\u25C7","o"),hs=d("\u250C","T"),x=d("\u2502","|"),Bt=d("\u2514","\u2014"),Gr=d("\u2510","T"),qr=d("\u2518","\u2014"),Vt=d("\u25CF",">"),Lt=d("\u25CB"," "),Ur=d("\u25FB","[\u2022]"),Br=d("\u25FC","[+]"),Wr=d("\u25FB","[ ]"),Hr=d("\u25AA","\u2022"),Gt=d("\u2500","-"),ms=d("\u256E","+"),ys=d("\u251C","+"),ds=d("\u256F","+"),gs=d("\u2570","+"),zr=d("\u256D","+"),vs=d("\u25CF","\u2022"),$s=d("\u25C6","*"),bs=d("\u25B2","!"),ks=d("\u25A0","x"),ws=(e)=>{switch(e){case"initial":case"active":return p("cyan",ps);case"cancel":return p("red",qt);case"error":return p("yellow",Ut);case"submit":return p("green",ge)}};var Wt=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new He({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??_.withGuide,r=`${ws(this.state)} `,u=s?`${p("gray",x)} `:"",o=Rt(e.output,e.message,u,r),a=`${s?`${p("gray",x)}
16
+ `),r=Math.max(n.length,s.length),i=[];for(let o=0;o<r;o++)n[o]!==s[o]&&i.push(o);return{lines:i,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}var cs=globalThis.process.platform.startsWith("win"),He=Symbol("clack:cancel");function de(e){return e===He}function ye(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Rt({input:e=Tt,output:t=ze,overwrite:n=!0,hideCursor:s=!0}={}){let r=W.createInterface({input:e,output:t,prompt:"",tabSize:1});W.emitKeypressEvents(e,r),e instanceof jt&&e.isTTY&&e.setRawMode(!0);let i=(o,{name:a,sequence:u})=>{let l=String(o);if(Ke([l,a,u],"cancel")){s&&t.write(k.cursor.show),process.exit(0);return}if(!n)return;W.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{W.clearLine(t,1,()=>{e.once("keypress",i)})})};return s&&t.write(k.cursor.hide),e.once("keypress",i),()=>{e.off("keypress",i),s&&t.write(k.cursor.show),e instanceof jt&&e.isTTY&&!cs&&e.setRawMode(!1),r.terminal=!1,r.close()}}var ge=(e)=>("columns"in e)&&typeof e.columns=="number"?e.columns:80,Pt=(e)=>("rows"in e)&&typeof e.rows=="number"?e.rows:20;function Nt(e,t,n,s=n,r=n,i){let o=ge(e??ze);return L(t,o-n.length,{hard:!0,trim:!1}).split(`
17
+ `).map((a,u,l)=>{let c=i?i(a,u):a;return u===0?`${s}${c}`:u===l.length-1?`${r}${c}`:`${n}${c}`}).join(`
18
+ `)}function Vt(e,t){if("~standard"in e){let n=e["~standard"].validate(t);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return e(t)}class Lt{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,t=!0){let{input:n=Tt,output:s=ze,render:r,signal:i,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=t,this._abortSignal=i,this.input=n,this.output=s}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],s=[];for(let r of n)r.cb(...t),r.once&&s.push(()=>n.splice(n.indexOf(r),1));for(let r of s)r()}prompt(){return new Promise((e)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(He);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=us.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),ye(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),ye(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(k.cursor.show),this.output.off("resize",this.render),ye(this.input,!1),e(He)})})}_isActionKey(e,t){return e==="\t"}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,t){this.userInput=e??"",this.emit("userInput",this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(e,t){if(this._track&&t.name!=="return"&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),t?.name&&(!this._track&&_.aliases.has(t.name)&&this.emit("cursor",_.aliases.get(t.name)),_.actions.has(t.name)&&this.emit("cursor",t.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,t),t?.name==="return"&&this._shouldSubmit(e,t)){if(this.opts.validate){let n=Vt(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}Ke([e,t?.name,t?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
19
+ `),ye(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=L(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
20
+ `).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=L(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(k.cursor.hide);else{let t=ls(this._prevFrame,e),n=Pt(this.output);if(this.restoreCursor(),t){let s=Math.max(0,t.numLinesAfter-n),r=Math.max(0,t.numLinesBefore-n),i=t.lines.find((o)=>o>=s);if(i===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(k.cursor.move(0,i-r)),this.output.write(k.erase.lines(1));let o=e.split(`
21
+ `);this.output.write(o[i]),this._prevFrame=e,this.output.write(k.cursor.move(0,o.length-i-1));return}else if(t.lines.length>1){if(s<r)i=s;else{let a=i-r;a>0&&this.output.write(k.cursor.move(0,a))}this.output.write(k.erase.down());let o=e.split(`
22
+ `).slice(i);this.output.write(o.join(`
23
+ `)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}class Xe extends Lt{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(k.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}import{styleText as p,stripVTControlCharacters as Nr}from"util";import O from"process";var ie=ut(We(),1);function fs(){if(O.platform!=="win32")return O.env.TERM!=="linux";return Boolean(O.env.CI)||Boolean(O.env.WT_SESSION)||Boolean(O.env.TERMINUS_SUBLIME)||O.env.ConEmuTask==="{cmd::Cmder}"||O.env.TERM_PROGRAM==="Terminus-Sublime"||O.env.TERM_PROGRAM==="vscode"||O.env.TERM==="xterm-256color"||O.env.TERM==="alacritty"||O.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var Je=fs(),ps=()=>process.env.CI==="true";var d=(e,t)=>Je?e:t,hs=d("\u25C6","*"),Bt=d("\u25A0","x"),Wt=d("\u25B2","x"),ve=d("\u25C7","o"),ms=d("\u250C","T"),x=d("\u2502","|"),Ht=d("\u2514","\u2014"),qr=d("\u2510","T"),Ur=d("\u2518","\u2014"),Gt=d("\u25CF",">"),qt=d("\u25CB"," "),Br=d("\u25FB","[\u2022]"),Wr=d("\u25FC","[+]"),Hr=d("\u25FB","[ ]"),zr=d("\u25AA","\u2022"),Ut=d("\u2500","-"),ys=d("\u256E","+"),ds=d("\u251C","+"),gs=d("\u256F","+"),vs=d("\u2570","+"),Kr=d("\u256D","+"),$s=d("\u25CF","\u2022"),bs=d("\u25C6","*"),ks=d("\u25B2","!"),ws=d("\u25A0","x"),xs=(e)=>{switch(e){case"initial":case"active":return p("cyan",hs);case"cancel":return p("red",Bt);case"error":return p("yellow",Wt);case"submit":return p("green",ve)}};var zt=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new Xe({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??_.withGuide,r=`${xs(this.state)} `,i=s?`${p("gray",x)} `:"",o=Nt(e.output,e.message,i,r),a=`${s?`${p("gray",x)}
24
24
  `:""}${o}
25
- `,i=this.value?t:n;switch(this.state){case"submit":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p("dim",i)}`}case"cancel":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p(["strikethrough","dim"],i)}${s?`
26
- ${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",Bt):"";return`${a}${l}${this.value?`${p("green",Vt)} ${t}`:`${p("dim",Lt)} ${p("dim",t)}`}${e.vertical?s?`
25
+ `,u=this.value?t:n;switch(this.state){case"submit":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p("dim",u)}`}case"cancel":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p(["strikethrough","dim"],u)}${s?`
26
+ ${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",Ht):"";return`${a}${l}${this.value?`${p("green",Gt)} ${t}`:`${p("dim",qt)} ${p("dim",t)}`}${e.vertical?s?`
27
27
  ${p("cyan",x)} `:`
28
- `:` ${p("dim","/")} `}${this.value?`${p("dim",Lt)} ${p("dim",n)}`:`${p("green",Vt)} ${n}`}
28
+ `:` ${p("dim","/")} `}${this.value?`${p("dim",qt)} ${p("dim",n)}`:`${p("green",Gt)} ${n}`}
29
29
  ${c}
30
- `}}}}).prompt()};var Kr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Space:")} select`,`${p("dim","Enter:")} confirm`];var v={message:(e=[],{symbol:t=p("gray",x),secondarySymbol:n=p("gray",x),output:s=process.stdout,spacing:r=1,withGuide:u}={})=>{let o=[],a=u??_.withGuide,i=a?n:"",l=a?`${t} `:"",c=a?`${n} `:"";for(let h=0;h<r;h++)o.push(i);let f=Array.isArray(e)?e:e.split(`
31
- `);if(f.length>0){let[h,...g]=f;h.length>0?o.push(`${l}${h}`):o.push(a?t:"");for(let m of g)m.length>0?o.push(`${c}${m}`):o.push(a?n:"")}s.write(`${o.join(`
30
+ `}}}}).prompt()};var Xr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Space:")} select`,`${p("dim","Enter:")} confirm`];var g={message:(e=[],{symbol:t=p("gray",x),secondarySymbol:n=p("gray",x),output:s=process.stdout,spacing:r=1,withGuide:i}={})=>{let o=[],a=i??_.withGuide,u=a?n:"",l=a?`${t} `:"",c=a?`${n} `:"";for(let h=0;h<r;h++)o.push(u);let f=Array.isArray(e)?e:e.split(`
31
+ `);if(f.length>0){let[h,...v]=f;h.length>0?o.push(`${l}${h}`):o.push(a?t:"");for(let m of v)m.length>0?o.push(`${c}${m}`):o.push(a?n:"")}s.write(`${o.join(`
32
32
  `)}
33
- `)},info:(e,t)=>{v.message(e,{...t,symbol:p("blue",vs)})},success:(e,t)=>{v.message(e,{...t,symbol:p("green",$s)})},step:(e,t)=>{v.message(e,{...t,symbol:p("green",ge)})},warn:(e,t)=>{v.message(e,{...t,symbol:p("yellow",bs)})},warning:(e,t)=>{v.warn(e,t)},error:(e,t)=>{v.message(e,{...t,symbol:p("red",ks)})}};var ve=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",hs)} `:"";n.write(`${s}${e}
34
- `)},Ht=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",x)}
35
- ${p("gray",Bt)} `:"";n.write(`${s}${e}
33
+ `)},info:(e,t)=>{g.message(e,{...t,symbol:p("blue",$s)})},success:(e,t)=>{g.message(e,{...t,symbol:p("green",bs)})},step:(e,t)=>{g.message(e,{...t,symbol:p("green",ve)})},warn:(e,t)=>{g.message(e,{...t,symbol:p("yellow",ks)})},warning:(e,t)=>{g.warn(e,t)},error:(e,t)=>{g.message(e,{...t,symbol:p("red",ws)})}};var $e=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",ms)} `:"";n.write(`${s}${e}
34
+ `)},Kt=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??_.withGuide?`${p("gray",x)}
35
+ ${p("gray",Ht)} `:"";n.write(`${s}${e}
36
36
 
37
- `)};var xs=(e)=>e,_s=(e,t,n)=>{let s={hard:!0,trim:!1},r=L(e,t,s).split(`
38
- `),u=r.reduce((i,l)=>Math.max(w(l),i),0),o=r.map(n).reduce((i,l)=>Math.max(w(l),i),0),a=t-(o-u);return L(e,a,s)},$e=(e="",t="",n)=>{let s=n?.output??A.stdout,r=n?.withGuide??_.withGuide,u=n?.format??xs,o=["",..._s(e,de(s)-6,u).split(`
39
- `).map(u),""],a=w(t),i=Math.max(o.reduce((h,g)=>{let m=w(g);return m>h?m:h},0),a)+2,l=o.map((h)=>`${p("gray",x)} ${h}${" ".repeat(i-w(h))}${p("gray",x)}`).join(`
37
+ `)};var _s=(e)=>e,Es=(e,t,n)=>{let s={hard:!0,trim:!1},r=L(e,t,s).split(`
38
+ `),i=r.reduce((u,l)=>Math.max(w(l),u),0),o=r.map(n).reduce((u,l)=>Math.max(w(l),u),0),a=t-(o-i);return L(e,a,s)},be=(e="",t="",n)=>{let s=n?.output??O.stdout,r=n?.withGuide??_.withGuide,i=n?.format??_s,o=["",...Es(e,ge(s)-6,i).split(`
39
+ `).map(i),""],a=w(t),u=Math.max(o.reduce((h,v)=>{let m=w(v);return m>h?m:h},0),a)+2,l=o.map((h)=>`${p("gray",x)} ${h}${" ".repeat(u-w(h))}${p("gray",x)}`).join(`
40
40
  `),c=r?`${p("gray",x)}
41
- `:"",f=r?ys:gs;s.write(`${c}${p("green",ge)} ${p("reset",t)} ${p("gray",Gt.repeat(Math.max(i-a-1,1))+ms)}
41
+ `:"",f=r?ds:vs;s.write(`${c}${p("green",ve)} ${p("reset",t)} ${p("gray",Ut.repeat(Math.max(u-a-1,1))+ys)}
42
42
  ${l}
43
- ${p("gray",f+Gt.repeat(i+2)+ds)}
44
- `)};var Es=(e)=>p("magenta",e),be=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:u=ze?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=ze?80:120,signal:a,...i}={})=>{let l=fs(),c,f,h=!1,g=!1,m="",y,F=performance.now(),q=de(n),U=i?.styleFrame??Es,O=(b)=>{let C=b>1?r??_.messages.error:s??_.messages.cancel;g=b===1,h&&(Y(C,b),g&&typeof t=="function"&&t())},j=()=>O(2),I=()=>O(1),J=()=>{process.on("uncaughtExceptionMonitor",j),process.on("unhandledRejection",j),process.on("SIGINT",I),process.on("SIGTERM",I),process.on("exit",O),a&&a.addEventListener("abort",I)},M=()=>{process.removeListener("uncaughtExceptionMonitor",j),process.removeListener("unhandledRejection",j),process.removeListener("SIGINT",I),process.removeListener("SIGTERM",I),process.removeListener("exit",O),a&&a.removeEventListener("abort",I)},E=()=>{if(y===void 0)return;l&&n.write(`
43
+ ${p("gray",f+Ut.repeat(u+2)+gs)}
44
+ `)};var Is=(e)=>p("magenta",e),ke=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:i=Je?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=Je?80:120,signal:a,...u}={})=>{let l=ps(),c,f,h=!1,v=!1,m="",y,T=performance.now(),q=ge(n),U=u?.styleFrame??Is,M=(b)=>{let C=b>1?r??_.messages.error:s??_.messages.cancel;v=b===1,h&&(Q(C,b),v&&typeof t=="function"&&t())},R=()=>M(2),I=()=>M(1),J=()=>{process.on("uncaughtExceptionMonitor",R),process.on("unhandledRejection",R),process.on("SIGINT",I),process.on("SIGTERM",I),process.on("exit",M),a&&a.addEventListener("abort",I)},D=()=>{process.removeListener("uncaughtExceptionMonitor",R),process.removeListener("unhandledRejection",R),process.removeListener("SIGINT",I),process.removeListener("SIGTERM",I),process.removeListener("exit",M),a&&a.removeEventListener("abort",I)},E=()=>{if(y===void 0)return;l&&n.write(`
45
45
  `);let b=L(y,q,{hard:!0,trim:!1}).split(`
46
- `);b.length>1&&n.write(se.cursor.up(b.length-1)),n.write(se.cursor.to(0)),n.write(se.erase.down())},B=(b)=>b.replace(/\.+$/,""),K=(b)=>{let C=(performance.now()-b)/1000,T=Math.floor(C/60),R=Math.floor(C%60);return T>0?`[${T}m ${R}s]`:`[${R}s]`},S=i.withGuide??_.withGuide,ue=(b="")=>{h=!0,c=jt({output:n}),m=B(b),F=performance.now(),S&&n.write(`${p("gray",x)}
47
- `);let C=0,T=0;J(),f=setInterval(()=>{if(l&&m===y)return;E(),y=m;let R=U(u[C]),oe;if(l)oe=`${R} ${m}...`;else if(e==="timer")oe=`${R} ${m} ${K(F)}`;else{let gn=".".repeat(Math.floor(T)).slice(0,3);oe=`${R} ${m}${gn}`}let dn=L(oe,q,{hard:!0,trim:!1});n.write(dn),C=C+1<u.length?C+1:0,T=T<4?T+0.125:0},o)},Y=(b="",C=0,T=!1)=>{if(!h)return;h=!1,clearInterval(f),E();let R=C===0?p("green",ge):C===1?p("red",qt):p("red",Ut);m=b??m,T||(e==="timer"?n.write(`${R} ${m} ${K(F)}
48
- `):n.write(`${R} ${m}
49
- `)),M(),c()};return{start:ue,stop:(b="")=>Y(b,0),message:(b="")=>{m=B(b??m)},cancel:(b="")=>Y(b,1),error:(b="")=>Y(b,2),clear:()=>Y("",0,!0),get isCancelled(){return g}}},Xr={light:d("\u2500","-"),heavy:d("\u2501","="),block:d("\u2588","#")};var Jr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Enter:")} confirm`];var Zr=`${p("gray",x)} `;var{$:Ke}=globalThis.Bun;var Is={pacman:["arch","endeavouros","manjaro","garuda","cachyos","arcolinux","rebornos","blendos","steamos","chimeraos"],dnf:["fedora","nobara","bazzite","ultramarine"]},zt=(e)=>{for(let[t,n]of Object.entries(Is))if(n.includes(e))return t;return null};var Kt={osName:void 0,osId:void 0,platform:"linux",packageManager:void 0,helperAur:null,isFlatpak:!1,flatpak:!1};function Z(e){return Kt[e]}function G(e,t){Kt[e]=t}async function Xe(e){try{return await Ke`which ${e}`.quiet(),!0}catch{return!1}}async function Ss(){let e=[];if(await Xe("yay"))e.push("yay");if(await Xe("paru"))e.push("paru");return e}async function Cs(){if(process.platform==="linux"){let e=await Ke`cat /etc/os-release | grep ^NAME`.quiet().text()||"",t=await Ke`cat /etc/os-release | grep ^ID`.quiet().text()||"",n=e.trim().slice(5).replace(/"/g,"");return{id:t.trim().slice(3).replace(/"/g,""),name:n}}return{id:"unknown",name:"unknown"}}async function ke(){let{name:e="",id:t=""}=await Cs(),n=zt(t),s=n==="pacman"?await Ss():null,r=await Xe("flatpak");if(G("osName",e),G("osId",t),G("flatpak",r),s)G("helperAur",s[0]);if(n)G("packageManager",n);return{osName:e,osId:t,packageManager:n,aurHelper:s,flatpak:r}}async function Xt(){ve("\uD83D\uDD0D Scanning system");let e=be();e.start("Detecting environment...");let t=await ke();return e.stop("Environment detected"),$e([`OS ${t.osName} (${t.osId})`,`Package Manager ${t.packageManager}`,t.aurHelper?`AUR Helper ${t.aurHelper}`:null,`Flatpak ${t.flatpak?"Enabled":"Disabled"}`].filter(Boolean).join(`
50
- `),"System Environment",{withGuide:!0}),Ht("Scan completed"),t}import Jt from"path";import{homedir as Zt}from"os";function we(e){if(e.startsWith("~"))return Jt.join(Zt(),e.slice(1));return Jt.resolve(e)}function Je(){return Zt()}var As=Pe(W({flatpak:Q(),backup:Q(),aur_helper:te(["yay","paru"])})),Os=W({source:D(),target:D(),sudo:ee(Q())}),Ms=te(["aur","pacman"]),Ds=ne([D(),V(D()),V(V(D()))]),Fs=W({name:D(),post_hooks:ee(Ds)}),Yt=V(ne([D(),Fs])),js=W({manager:Ms,items:Yt}),Ts=W({manager:Re("flatpak"),scope:te(["system","user"]),items:Yt}),xe=Pe(W({imports:V(D()),settings:As,packages:V(ne([Ts,js])),symlinks:V(Os)}));import Ee from"path";var z={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},pi={defaultMerge:z.defaultMerge};function Rs(e,t){return t}function Ps(e,t){return e.filter((n)=>n!==void 0)}var Qt;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(Qt||(Qt={}));function en(e){if(typeof e!=="object"||e===null)return 0;if(Array.isArray(e))return 2;if(Ls(e))return 1;if(e instanceof Set)return 3;if(e instanceof Map)return 4;return 5}function Ns(e){let t=new Set;for(let n of e)for(let s of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(s);return t}function Vs(e,t){return typeof e==="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}function nn(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let s=n.next();if(s.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:s.value}}while(!0)}}}}}var tn=["[object Object]","[object Module]"];function Ls(e){if(!tn.includes(Object.prototype.toString.call(e)))return!1;let{constructor:t}=e;if(t===void 0)return!0;let n=t.prototype;if(n===null||typeof n!=="object"||!tn.includes(Object.prototype.toString.call(n)))return!1;if(!n.hasOwnProperty("isPrototypeOf"))return!1;return!0}function Gs(e,t,n){let s={};for(let r of Ns(e)){let u=[];for(let i of e)if(Vs(i,r))u.push(i[r]);if(u.length===0)continue;let o=t.metaDataUpdater(n,{key:r,parents:e}),a=sn(u,t,o);if(a===z.skip)continue;if(r==="__proto__")Object.defineProperty(s,r,{value:a,configurable:!0,enumerable:!0,writable:!0});else s[r]=a}return s}function qs(e){return e.flat()}function Us(e){return new Set(nn(e))}function Bs(e){return new Map(nn(e))}function Ws(e){return e.at(-1)}var _e={mergeRecords:Gs,mergeArrays:qs,mergeSets:Us,mergeMaps:Bs,mergeOthers:Ws};function ie(...e){return Hs({})(...e)}function Hs(e,t){let n=zs(e,s);function s(...r){return sn(r,n,t)}return s}function zs(e,t){return{defaultMergeFunctions:_e,mergeFunctions:{..._e,...Object.fromEntries(Object.entries(e).filter(([n,s])=>Object.hasOwn(_e,n)).map(([n,s])=>s===!1?[n,_e.mergeOthers]:[n,s]))},metaDataUpdater:e.metaDataUpdater??Rs,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??Ps,actions:z}}function sn(e,t,n){let s=t.filterValues?.(e,n)??e;if(s.length===0)return;if(s.length===1)return Ze(s,t,n);let r=en(s[0]);if(r!==0&&r!==5)for(let u=1;u<s.length;u++){if(en(s[u])===r)continue;return Ze(s,t,n)}switch(r){case 1:return Ks(s,t,n);case 2:return Xs(s,t,n);case 3:return Js(s,t,n);case 4:return Zs(s,t,n);default:return Ze(s,t,n)}}function Ks(e,t,n){let s=t.mergeFunctions.mergeRecords(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords)return t.defaultMergeFunctions.mergeRecords(e,t,n);return s}function Xs(e,t,n){let s=t.mergeFunctions.mergeArrays(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays)return t.defaultMergeFunctions.mergeArrays(e);return s}function Js(e,t,n){let s=t.mergeFunctions.mergeSets(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets)return t.defaultMergeFunctions.mergeSets(e);return s}function Zs(e,t,n){let s=t.mergeFunctions.mergeMaps(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps)return t.defaultMergeFunctions.mergeMaps(e);return s}function Ze(e,t,n){let s=t.mergeFunctions.mergeOthers(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers)return t.defaultMergeFunctions.mergeOthers(e);return s}async function Ye(e,t=new Set){let n=Ee.resolve(e);if(t.has(n))throw Error(`Circular dependency detected: ${n}`);t.add(n);let s=await Bun.file(n).text(),r=Bun.TOML.parse(s),u=fe(xe,r),{imports:o=[],symlinks:a=[]}=u;delete u.imports;let i=Ee.dirname(n);u.symlinks=Ys(i,a);let l={};for(let c of o){let f=Ee.resolve(i,c),h=await Ye(f,t);l=ie(l,h)}return ie(u,l)}function Ys(e,t){if(!t||t.length===0)return[];let n=[];for(let s of t){if(!s)continue;let{source:r,target:u}=s,o=Ee.resolve(e,r),a=we(u);n.push({source:o,target:a})}return n}async function Ie(e){let t=we(e);v.step("Validating Configuration");let n=be();n.start("Validating...");let s=await Ye(t),r=fe(xe,s);return n.stop("Successfully validated with no errors!"),r}import nr from"path";var{deepEquals:Qs}=globalThis.Bun;import er from"fs/promises";import Se from"path";import Qe from"fs/promises";var Ce={};function Ae(){return Ce}function rn(e,t){Ce[e]=t}async function un(){let e=Se.resolve(Je(),".cache/hofii"),t=Se.resolve(e,"hofii-lock.json");if(await Qe.exists(t)){let n=await Bun.file(t).json();Object.assign(Ce,n.config)}}async function on(){let e=Se.resolve(Je(),".cache/hofii");if(!await Qe.exists(e))await Qe.mkdir(e,{recursive:!0});let t={config:Ce};await Bun.write(Se.resolve(e,"hofii-lock.json"),JSON.stringify(t,null,2))}import Me from"fs/promises";async function Oe({cmd:e,errMsg:t,opt:n={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let s=Bun.spawn(e,{stdin:n.stdin,stdout:n.stdout,stderr:n.stderr}),r=n.stdout==="pipe"?new Response(s.stdout).text():void 0,u=n.stderr==="pipe"?new Response(s.stderr).text():void 0,o=s.exited,[a,i,l]=await Promise.all([r,u,o]);if(l!==0)throw Error(t??`Error caused with exit code ${l}`);return{stdout:a,stderr:i,exitCode:l}}async function et(e,t,n=!1){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","ln","-s",e,t],errMsg:`Failed create symlink ${e+" -> "+t}`})}else await Me.symlink(e,t)}async function tt(e,t=!1){if(t){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","rm",e],errMsg:`Failed remove symlink ${e}`})}else await Me.unlink(e)}async function nt(e){try{return await Me.lstat(e)}catch(t){return null}}async function an({oldPath:e,newPath:t,sudo:n=!1}){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","mv",e,t],errMsg:`Failed rename file ${e+" -> "+t}`})}else await Me.rename(e,t)}async function fn(e){if(!e)return;let t=Z("settings")?.backup??!0,{added:n=[],removed:s=[]}=e,r=[],u=[];try{let o=cn(await Promise.allSettled(s.map(async(i)=>{let l=await nt(i.target);if(!l){v.warn(`Target doesn't exist: ${i.target}, did you remove it manually?`),u.push(i);return}if(!l.isSymbolicLink()){v.warn(`${i.target} not a symlink, did you remove it manually?`),u.push(i);return}await tt(i.target,i.sudo),u.push(i),v.success(`Succesfully remove symlink ${i.target}`)}))),a=cn(await Promise.allSettled(n.map(async(i)=>{let l=await nt(i.target);if(l){if(l.isSymbolicLink()){let c=await er.readlink(i.target);if(c===i.source){await tt(i.target,i.sudo),await et(i.source,i.target,i.sudo),r.push(i),v.warn(`Recreate ${c} -> ${i.target}`);return}}if(t)await an({oldPath:i.target,newPath:i.target+".bak",sudo:i.sudo});else{v.error(`Target already exists, skip create: ${i.target}`);return}}await et(i.source,i.target,i.sudo),r.push(i),v.success(`Succesfully create symlink ${i.source} -> ${i.target}`)})));for(let i of a)console.error(`Failed to add symlink: ${ln(i)}`);for(let i of o)console.error(`Failed to remove symlink: ${ln(i)}`);if(a.length>0||o.length>0)v.error(" [FATAL] Error caused while applying symlinks"),process.exitCode=1}catch(o){console.error(o),v.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let i=((Ae()??{}).symlinks??[]).filter((l)=>!u.some((c)=>Qs(c,l))).concat(r);v.info(`Updated symlinks state: ${i.length}`),rn("symlinks",i)}}function ln(e){if(e instanceof Error)return`[${"code"in e?String(e.code):"ERROR"}] ${e.message}`;return`[ERROR] ${String(e)}`}function cn(e){return e.filter((t)=>t.status==="rejected")}var{deepEquals:pn}=globalThis.Bun;function tr(e,t){let n=t?.filter((r)=>!e?.some((u)=>pn(r,u,!0)))??[],s=e?.filter((r)=>!t?.some((u)=>pn(r,u,!0)))??[];return{added:n,removed:s}}function hn(e){let t=Ae();return{symlinks:tr(t.symlinks,e.symlinks)}}function mn(e){let{symlinks:t}=e;return[(()=>{let s=["SYMLINKS"],{added:r=[],removed:u=[]}=t;if(r?.length===0&&u?.length===0)return s.push(" - No changes to apply with symlinks"),s.join(`
51
- `);for(let o of r)s.push(` - [ADDED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);for(let o of u)s.push(` - [REMOVED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);return s.join(`
52
- `)})()].join("/n")}async function yn(e){let t=nr.join(e,"config.toml");G("configDir",e),await un(),ve("Switching configuration"),v.info("Scanning system environment..."),await ke();let n=await Ie(t);G("settings",ie(n.settings,{backup:!0}));let s=hn(n),r=mn(s);$e(r,"Config To Apply");let u=await Wt({message:"Apply config changes? (Please review the changes first!!)"});if(!u||ye(u))v.warn("Config changes not applied."),process.exit(0);await fn(s.symlinks)}var X=ft("hofii");X.version("0.0.3");X.command("scan","Detect system environment").alias("s").action(async()=>{await Xt(),process.exit(0)});X.command("validate [dir]","Validate configuration files").alias("v").action(async(e)=>{await Ie(e),process.exit(0)});X.command("switch [dir]","Switch to new configuration").alias("sw").action(async(e)=>{let t=sr.resolve(e);await yn(t)});try{if(process.argv.slice(2).length===0)X.outputHelp(),process.exit(0);X.help().parse(process.argv,{run:!1}),await X.runMatchedCommand()}catch(e){if(e instanceof Te){let t=e.issues.map((n)=>{let s=n.path.at(-1)?.input;return[`\u2717 ${n.message}`,` at: ${JSON.stringify(s)}`].join(`
46
+ `);b.length>1&&n.write(ie.cursor.up(b.length-1)),n.write(ie.cursor.to(0)),n.write(ie.erase.down())},B=(b)=>b.replace(/\.+$/,""),z=(b)=>{let C=(performance.now()-b)/1000,P=Math.floor(C/60),N=Math.floor(C%60);return P>0?`[${P}m ${N}s]`:`[${N}s]`},S=u.withGuide??_.withGuide,oe=(b="")=>{h=!0,c=Rt({output:n}),m=B(b),T=performance.now(),S&&n.write(`${p("gray",x)}
47
+ `);let C=0,P=0;J(),f=setInterval(()=>{if(l&&m===y)return;E(),y=m;let N=U(i[C]),ae;if(l)ae=`${N} ${m}...`;else if(e==="timer")ae=`${N} ${m} ${z(T)}`;else{let $n=".".repeat(Math.floor(P)).slice(0,3);ae=`${N} ${m}${$n}`}let vn=L(ae,q,{hard:!0,trim:!1});n.write(vn),C=C+1<i.length?C+1:0,P=P<4?P+0.125:0},o)},Q=(b="",C=0,P=!1)=>{if(!h)return;h=!1,clearInterval(f),E();let N=C===0?p("green",ve):C===1?p("red",Bt):p("red",Wt);m=b??m,P||(e==="timer"?n.write(`${N} ${m} ${z(T)}
48
+ `):n.write(`${N} ${m}
49
+ `)),D(),c()};return{start:oe,stop:(b="")=>Q(b,0),message:(b="")=>{m=B(b??m)},cancel:(b="")=>Q(b,1),error:(b="")=>Q(b,2),clear:()=>Q("",0,!0),get isCancelled(){return v}}},Jr={light:d("\u2500","-"),heavy:d("\u2501","="),block:d("\u2588","#")};var Zr=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Enter:")} confirm`];var Yr=`${p("gray",x)} `;var{$:Ze}=globalThis.Bun;var Ss={pacman:["arch","endeavouros","manjaro","garuda","cachyos","arcolinux","rebornos","blendos","steamos","chimeraos"],dnf:["fedora","nobara","bazzite","ultramarine"]},Xt=(e)=>{for(let[t,n]of Object.entries(Ss))if(n.includes(e))return t;return null};var Jt={osName:void 0,osId:void 0,platform:"linux",packageManager:void 0,helperAur:null,isFlatpak:!1,flatpak:!1};function Y(e){return Jt[e]}function G(e,t){Jt[e]=t}async function Ye(e){try{return await Ze`which ${e}`.quiet(),!0}catch{return!1}}async function Cs(){let e=[];if(await Ye("yay"))e.push("yay");if(await Ye("paru"))e.push("paru");return e}async function As(){if(process.platform==="linux"){let e=await Ze`cat /etc/os-release | grep ^NAME`.quiet().text()||"",t=await Ze`cat /etc/os-release | grep ^ID`.quiet().text()||"",n=e.trim().slice(5).replace(/"/g,"");return{id:t.trim().slice(3).replace(/"/g,""),name:n}}return{id:"unknown",name:"unknown"}}async function we(){let{name:e="",id:t=""}=await As(),n=Xt(t),s=n==="pacman"?await Cs():null,r=await Ye("flatpak");if(G("osName",e),G("osId",t),G("flatpak",r),s)G("helperAur",s[0]);if(n)G("packageManager",n);return{osName:e,osId:t,packageManager:n,aurHelper:s,flatpak:r}}async function Zt(){$e("\uD83D\uDD0D Scanning system");let e=ke();e.start("Detecting environment...");let t=await we();return e.stop("Environment detected"),be([`OS ${t.osName} (${t.osId})`,`Package Manager ${t.packageManager}`,t.aurHelper?`AUR Helper ${t.aurHelper}`:null,`Flatpak ${t.flatpak?"Enabled":"Disabled"}`].filter(Boolean).join(`
50
+ `),"System Environment",{withGuide:!0}),Kt("Scan completed"),t}import Yt from"path";import{homedir as Qt}from"os";function xe(e){if(e.startsWith("~"))return Yt.join(Qt(),e.slice(1));return Yt.resolve(e)}function Qe(){return Qt()}var Os=Le(K({flatpak:te(),backup:te(),aur_helper:se(["yay","paru"])})),Ms=K({source:j(),target:j(),sudo:ne(te())}),Ds=se(["aur","pacman"]),Fs=re([j(),V(j()),V(V(j()))]),js=K({name:j(),post_hooks:ne(Fs)}),en=V(re([j(),js])),Ts=K({manager:Ds,items:en}),Rs=K({manager:Ne("flatpak"),scope:se(["system","user"]),items:en}),_e=Le(Ve({imports:V(j()),settings:Os,packages:V(re([Rs,Ts])),symlinks:V(Ms)}));import Ie from"path";var H={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},hi={defaultMerge:H.defaultMerge};function Ps(e,t){return t}function Ns(e,t){return e.filter((n)=>n!==void 0)}var tn;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(tn||(tn={}));function nn(e){if(typeof e!=="object"||e===null)return 0;if(Array.isArray(e))return 2;if(Gs(e))return 1;if(e instanceof Set)return 3;if(e instanceof Map)return 4;return 5}function Vs(e){let t=new Set;for(let n of e)for(let s of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(s);return t}function Ls(e,t){return typeof e==="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}function rn(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let s=n.next();if(s.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:s.value}}while(!0)}}}}}var sn=["[object Object]","[object Module]"];function Gs(e){if(!sn.includes(Object.prototype.toString.call(e)))return!1;let{constructor:t}=e;if(t===void 0)return!0;let n=t.prototype;if(n===null||typeof n!=="object"||!sn.includes(Object.prototype.toString.call(n)))return!1;if(!n.hasOwnProperty("isPrototypeOf"))return!1;return!0}function qs(e,t,n){let s={};for(let r of Vs(e)){let i=[];for(let u of e)if(Ls(u,r))i.push(u[r]);if(i.length===0)continue;let o=t.metaDataUpdater(n,{key:r,parents:e}),a=un(i,t,o);if(a===H.skip)continue;if(r==="__proto__")Object.defineProperty(s,r,{value:a,configurable:!0,enumerable:!0,writable:!0});else s[r]=a}return s}function Us(e){return e.flat()}function Bs(e){return new Set(rn(e))}function Ws(e){return new Map(rn(e))}function Hs(e){return e.at(-1)}var Ee={mergeRecords:qs,mergeArrays:Us,mergeSets:Bs,mergeMaps:Ws,mergeOthers:Hs};function ue(...e){return zs({})(...e)}function zs(e,t){let n=Ks(e,s);function s(...r){return un(r,n,t)}return s}function Ks(e,t){return{defaultMergeFunctions:Ee,mergeFunctions:{...Ee,...Object.fromEntries(Object.entries(e).filter(([n,s])=>Object.hasOwn(Ee,n)).map(([n,s])=>s===!1?[n,Ee.mergeOthers]:[n,s]))},metaDataUpdater:e.metaDataUpdater??Ps,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??Ns,actions:H}}function un(e,t,n){let s=t.filterValues?.(e,n)??e;if(s.length===0)return;if(s.length===1)return et(s,t,n);let r=nn(s[0]);if(r!==0&&r!==5)for(let i=1;i<s.length;i++){if(nn(s[i])===r)continue;return et(s,t,n)}switch(r){case 1:return Xs(s,t,n);case 2:return Js(s,t,n);case 3:return Zs(s,t,n);case 4:return Ys(s,t,n);default:return et(s,t,n)}}function Xs(e,t,n){let s=t.mergeFunctions.mergeRecords(e,t,n);if(s===H.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords)return t.defaultMergeFunctions.mergeRecords(e,t,n);return s}function Js(e,t,n){let s=t.mergeFunctions.mergeArrays(e,t,n);if(s===H.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays)return t.defaultMergeFunctions.mergeArrays(e);return s}function Zs(e,t,n){let s=t.mergeFunctions.mergeSets(e,t,n);if(s===H.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets)return t.defaultMergeFunctions.mergeSets(e);return s}function Ys(e,t,n){let s=t.mergeFunctions.mergeMaps(e,t,n);if(s===H.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps)return t.defaultMergeFunctions.mergeMaps(e);return s}function et(e,t,n){let s=t.mergeFunctions.mergeOthers(e,t,n);if(s===H.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers)return t.defaultMergeFunctions.mergeOthers(e);return s}async function tt(e,t=new Set){let n=Ie.resolve(e);if(t.has(n))throw Error(`Circular dependency detected: ${n}`);t.add(n);let s=await Bun.file(n).text(),r=Bun.TOML.parse(s),i;try{i=pe(_e,r)}catch(c){if(c instanceof ee)g.error(c.issues[0].message);process.exit(1)}let{imports:o=[],symlinks:a=[]}=i;delete i.imports;let u=Ie.dirname(n);i.symlinks=Qs(u,a);let l={};for(let c of o){let f=Ie.resolve(u,c),h=await tt(f,t);l=ue(l,h)}return ue(i,l)}function Qs(e,t){if(!t||t.length===0)return[];let n=[];for(let s of t){if(!s)continue;let{source:r,target:i}=s,o=Ie.resolve(e,r),a=xe(i);n.push({source:o,target:a})}return n}async function Se(e){let t=xe(e);g.step("Validating Configuration");let n=ke();n.start("Validating...");let s=await tt(t),r=pe(_e,s);return n.stop("Successfully validated with no errors!"),r}import sr from"path";var{deepEquals:er}=globalThis.Bun;import tr from"fs/promises";import Ce from"path";import nt from"fs/promises";var Ae={};function Oe(){return Ae}function on(e,t){Ae[e]=t}async function an(){let e=Ce.resolve(Qe(),".cache/hofii"),t=Ce.resolve(e,"hofii-lock.json");if(await nt.exists(t)){let n=await Bun.file(t).json();Object.assign(Ae,n.config)}}async function ln(){let e=Ce.resolve(Qe(),".cache/hofii");if(!await nt.exists(e))await nt.mkdir(e,{recursive:!0});let t={config:Ae};await Bun.write(Ce.resolve(e,"hofii-lock.json"),JSON.stringify(t,null,2))}import De from"fs/promises";async function Me({cmd:e,errMsg:t,opt:n={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let s=Bun.spawn(e,{stdin:n.stdin,stdout:n.stdout,stderr:n.stderr}),r=n.stdout==="pipe"?new Response(s.stdout).text():void 0,i=n.stderr==="pipe"?new Response(s.stderr).text():void 0,o=s.exited,[a,u,l]=await Promise.all([r,i,o]);if(l!==0)throw Error(t??`Error caused with exit code ${l}`);return{stdout:a,stderr:u,exitCode:l}}async function st(e,t,n=!1){if(n){if(Y("platform")!=="linux"){g.warn("Sudo only support in Linux");return}await Me({cmd:["sudo","ln","-s",e,t],errMsg:`Failed create symlink ${e+" -> "+t}`})}else await De.symlink(e,t)}async function rt(e,t=!1){if(t){if(Y("platform")!=="linux"){g.warn("Sudo only support in Linux");return}await Me({cmd:["sudo","rm",e],errMsg:`Failed remove symlink ${e}`})}else await De.unlink(e)}async function Fe(e){try{return await De.lstat(e)}catch(t){return null}}async function cn({oldPath:e,newPath:t,sudo:n=!1}){if(!await Fe(t))return;if(n){if(Y("platform")!=="linux"){g.warn("Sudo only support in Linux");return}await Me({cmd:["sudo","mv",e,t],errMsg:`Failed rename file ${e+" -> "+t}`})}else await De.rename(e,t)}async function hn(e){if(!e)return;let t=Y("settings")?.backup??!0,{added:n=[],removed:s=[]}=e,r=[],i=[];try{let o=pn(await Promise.allSettled(s.map(async(u)=>{let l=await Fe(u.target);if(!l){g.warn(`Target doesn't exist: ${u.target}, did you remove it manually?`),i.push(u);return}if(!l.isSymbolicLink()){g.warn(`${u.target} not a symlink, did you remove it manually?`),i.push(u);return}await rt(u.target,u.sudo),i.push(u),g.success(`Succesfully remove symlink ${u.target}`)}))),a=pn(await Promise.allSettled(n.map(async(u)=>{let l=await Fe(u.target);if(l){if(l.isSymbolicLink()){let c=await tr.readlink(u.target);if(c===u.source){await rt(u.target,u.sudo),await st(u.source,u.target,u.sudo),r.push(u),g.warn(`Recreate ${c} -> ${u.target}`);return}}if(t)await cn({oldPath:u.target,newPath:u.target+".bak",sudo:u.sudo});else{g.error(`Target already exists, skip create: ${u.target}`);return}}await st(u.source,u.target,u.sudo),r.push(u),g.success(`Succesfully create symlink ${u.source} -> ${u.target}`)})));for(let u of a)console.error(`Failed to add symlink: ${fn(u)}`);for(let u of o)console.error(`Failed to remove symlink: ${fn(u)}`);if(a.length>0||o.length>0)g.error(" [FATAL] Error caused while applying symlinks"),process.exitCode=1}catch(o){console.error(o),g.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let u=((Oe()??{}).symlinks??[]).filter((l)=>!i.some((c)=>er(c,l))).concat(r);g.info(`Updated symlinks state: ${u.length}`),on("symlinks",u)}}function fn(e){if(e instanceof Error)return`[${"code"in e?String(e.code):"ERROR"}] ${e.message}`;return`[ERROR] ${String(e)}`}function pn(e){return e.filter((t)=>t.status==="rejected")}var{deepEquals:mn}=globalThis.Bun;function nr(e,t){let n=t?.filter((r)=>!e?.some((i)=>mn(r,i,!0)))??[],s=e?.filter((r)=>!t?.some((i)=>mn(r,i,!0)))??[];return{added:n,removed:s}}function yn(e){let t=Oe();return{symlinks:nr(t.symlinks,e.symlinks)}}function dn(e){let{symlinks:t}=e;return[(()=>{let s=["SYMLINKS"],{added:r=[],removed:i=[]}=t;if(r?.length===0&&i?.length===0)return s.push(" - No changes to apply with symlinks"),s.join(`
51
+ `);for(let o of r)s.push(` - [ADDED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);for(let o of i)s.push(` - [REMOVED] ${o.sudo?"(sudo) ":""}${o.source} -> ${o.target}`);return s.join(`
52
+ `)})()].join("/n")}async function gn(e){let t=sr.join(e,"config.toml");G("configDir",e),await an(),$e("Switching configuration"),g.info("Scanning system environment..."),await we();let n=await Se(t);G("settings",ue(n.settings,{backup:!0}));let s=yn(n),r=dn(s);be(r,"Config To Apply");let i=await zt({message:"Apply config changes? (Please review the changes first!!)"});if(!i||de(i))g.warn("Config changes not applied."),process.exit(0);await hn(s.symlinks)}var X=ht("hofii");X.version("0.0.3");X.command("scan","Detect system environment").alias("s").action(async()=>{await Zt(),process.exit(0)});X.command("validate [dir]","Validate configuration files").alias("v").action(async(e)=>{await Se(e),process.exit(0)});X.command("switch [dir]","Switch to new configuration").alias("sw").action(async(e)=>{let t=rr.resolve(e);await gn(t)});try{if(process.argv.slice(2).length===0)X.outputHelp(),process.exit(0);X.help().parse(process.argv,{run:!1}),await X.runMatchedCommand()}catch(e){if(e instanceof ee){let t=e.issues.map((n)=>{let s=n.path.at(-1)?.input;return[`\u2717 ${n.message}`,` at: ${JSON.stringify(s)}`].join(`
53
53
  `)}).join(`
54
54
 
55
- `);console.error(t)}console.error(e)}finally{await on()}
55
+ `);console.error(t)}console.error(e)}finally{await ln()}
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "hofii",
3
3
  "description": "An orchestration tools for manage dotfiles and packages",
4
- "module": "index.ts",
5
4
  "type": "module",
6
5
  "bin": {
7
6
  "hofii": "./dist/main.js"
@@ -26,5 +25,5 @@
26
25
  "deepmerge-ts": "^7.1.5",
27
26
  "valibot": "^1.4.2"
28
27
  },
29
- "version": "0.1.1"
28
+ "version": "0.1.2"
30
29
  }