|
| 1 | +# Luca Scripts |
| 2 | + |
| 3 | +This document provides visual documentation for the scripts supporting Luca. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. System Overview |
| 8 | + |
| 9 | +This diagram shows how all the scripts relate to each other and their role in the Luca ecosystem. |
| 10 | + |
| 11 | +```mermaid |
| 12 | +flowchart TB |
| 13 | + subgraph User["👤 User Actions"] |
| 14 | + U1[Run install.sh] |
| 15 | + U2[Change directory in terminal] |
| 16 | + U3[Git checkout/switch branch] |
| 17 | + U4[Run uninstall.sh] |
| 18 | + end |
| 19 | +
|
| 20 | + subgraph Scripts["📜 LucaScripts"] |
| 21 | + IS[install.sh] |
| 22 | + SH[shell_hook.sh] |
| 23 | + PC[post-checkout] |
| 24 | + UN[uninstall.sh] |
| 25 | + end |
| 26 | +
|
| 27 | + subgraph Artifacts["📦 Installed Artifacts"] |
| 28 | + EXE["/usr/local/bin/luca"] |
| 29 | + HOOK["~/.luca/shell_hook.sh"] |
| 30 | + GITHOOK[".git/hooks/post-checkout"] |
| 31 | + RCFILE["~/.bashrc or ~/.zshrc"] |
| 32 | + end |
| 33 | +
|
| 34 | + subgraph Runtime["⚡ Runtime Behavior"] |
| 35 | + PATH["PATH management"] |
| 36 | + SYNC["Tool synchronization"] |
| 37 | + end |
| 38 | +
|
| 39 | + U1 --> IS |
| 40 | + IS -->|downloads & installs| EXE |
| 41 | + IS -->|downloads| HOOK |
| 42 | + IS -->|modifies| RCFILE |
| 43 | + IS -->|optionally installs| GITHOOK |
| 44 | +
|
| 45 | + U2 --> SH |
| 46 | + SH --> PATH |
| 47 | + PATH -->|adds/removes| .luca/active |
| 48 | +
|
| 49 | + U3 --> PC |
| 50 | + PC -->|may call| IS |
| 51 | + PC -->|runs| SYNC |
| 52 | + SYNC -->|"luca install"| EXE |
| 53 | +
|
| 54 | + U4 --> UN |
| 55 | + UN -->|removes| EXE |
| 56 | + UN -->|removes| HOOK |
| 57 | + UN -->|cleans| RCFILE |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 2. Installation Flow (`install.sh`) |
| 63 | + |
| 64 | +Detailed flowchart of what happens when you run the installation script. |
| 65 | + |
| 66 | +```mermaid |
| 67 | +flowchart TD |
| 68 | + Start([Start install.sh]) --> CheckVersion{".luca-version<br/>exists?"} |
| 69 | + |
| 70 | + CheckVersion -->|Yes| ReadVersion[Read version from file] |
| 71 | + CheckVersion -->|No| FetchLatest[Fetch latest from<br/>GitHub API] |
| 72 | + |
| 73 | + ReadVersion --> ValidateSemVer{Valid SemVer?} |
| 74 | + FetchLatest --> ValidateSemVer |
| 75 | + |
| 76 | + ValidateSemVer -->|No| ErrorExit1([❌ Exit: Invalid version]) |
| 77 | + ValidateSemVer -->|Yes| DetectOS{Detect OS} |
| 78 | + |
| 79 | + DetectOS -->|macOS| SetMacZip[Set: Luca-macOS.zip] |
| 80 | + DetectOS -->|Linux| SetLinuxZip[Set: Luca-Linux.zip] |
| 81 | + DetectOS -->|Other| ErrorExit2([❌ Exit: Unsupported OS]) |
| 82 | + |
| 83 | + SetMacZip --> CheckExisting |
| 84 | + SetLinuxZip --> CheckCurl{curl installed?} |
| 85 | + |
| 86 | + CheckCurl -->|No| InstallCurl[Install curl via<br/>apt-get/yum] |
| 87 | + CheckCurl -->|Yes| CheckExisting |
| 88 | + InstallCurl --> CheckExisting |
| 89 | + |
| 90 | + CheckExisting{Luca already<br/>installed?} |
| 91 | + CheckExisting -->|Yes| CompareVersion{Same version?} |
| 92 | + CheckExisting -->|No| Download |
| 93 | + |
| 94 | + CompareVersion -->|Yes| SkipExit([✅ Exit: Already up to date]) |
| 95 | + CompareVersion -->|No| Download |
| 96 | + |
| 97 | + Download[📥 Download ZIP from<br/>GitHub releases] --> Extract[📦 Extract ZIP] |
| 98 | + Extract --> InstallBin[🚀 Move to /usr/local/bin<br/>chmod +x] |
| 99 | + |
| 100 | + InstallBin --> SetupHook[🔧 Setup Shell Hook] |
| 101 | + |
| 102 | + subgraph ShellHookSetup["Shell Hook Setup"] |
| 103 | + SetupHook --> CreateDir[Create ~/.luca/] |
| 104 | + CreateDir --> DownloadHook[Download shell_hook.sh] |
| 105 | + DownloadHook --> SourceHook[Source shell_hook.sh] |
| 106 | + SourceHook --> ModifyRC[Add to ~/.bashrc<br/>or ~/.zshrc] |
| 107 | + end |
| 108 | + |
| 109 | + ModifyRC --> GitHook{In git repo?} |
| 110 | + |
| 111 | + subgraph GitHookSetup["Git Hook Setup (Optional)"] |
| 112 | + GitHook -->|Yes| CheckHookExists{post-checkout<br/>exists?} |
| 113 | + GitHook -->|No| Complete |
| 114 | + CheckHookExists -->|No| InstallGitHook[Download & install<br/>post-checkout hook] |
| 115 | + CheckHookExists -->|Yes, ours| SkipGitHook[Already installed] |
| 116 | + CheckHookExists -->|Yes, other| WarnGitHook[⚠️ Warn: manual merge needed] |
| 117 | + InstallGitHook --> Complete |
| 118 | + SkipGitHook --> Complete |
| 119 | + WarnGitHook --> Complete |
| 120 | + end |
| 121 | + |
| 122 | + Complete([🎉 Installation Complete]) |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 3. Shell Hook Mechanism (`shell_hook.sh`) |
| 128 | + |
| 129 | +How the shell hook manages PATH dynamically as you navigate directories. |
| 130 | + |
| 131 | +```mermaid |
| 132 | +flowchart TD |
| 133 | + subgraph Initialization["🔧 Initialization (on shell start)"] |
| 134 | + Source[Shell sources<br/>~/.luca/shell_hook.sh] --> RegisterHook{Detect shell type} |
| 135 | + RegisterHook -->|Bash| AddPrompt["Add update_path to<br/>PROMPT_COMMAND"] |
| 136 | + RegisterHook -->|Zsh| AddPrecmd["Add update_path to<br/>precmd hook"] |
| 137 | + AddPrompt --> InitialUpdate[Run update_path<br/>for current dir] |
| 138 | + AddPrecmd --> InitialUpdate |
| 139 | + end |
| 140 | +
|
| 141 | + subgraph EveryPrompt["⚡ Before Every Prompt"] |
| 142 | + Prompt[User presses Enter<br/>or changes directory] --> UpdatePath[update_path runs] |
| 143 | + |
| 144 | + UpdatePath --> CheckLucaDir{".luca/active"<br/>exists in pwd?} |
| 145 | + |
| 146 | + CheckLucaDir -->|Yes| CheckInPath{Already in PATH?} |
| 147 | + CheckLucaDir -->|No| CleanupPath |
| 148 | + |
| 149 | + CheckInPath -->|Yes| Done1[Do nothing<br/>idempotent] |
| 150 | + CheckInPath -->|No| AddToPath["Add .luca/active<br/>to front of PATH"] |
| 151 | + |
| 152 | + AddToPath --> Done2[PATH updated ✅] |
| 153 | + |
| 154 | + CleanupPath{Any .luca/active<br/>entries in PATH?} |
| 155 | + CleanupPath -->|No| Done3[Nothing to clean] |
| 156 | + CleanupPath -->|Yes| FilterPath |
| 157 | + |
| 158 | + FilterPath[For each PATH entry...] |
| 159 | + FilterPath --> IsLucaEntry{Is .luca/active<br/>entry?} |
| 160 | + |
| 161 | + IsLucaEntry -->|No| Keep[Keep in PATH] |
| 162 | + IsLucaEntry -->|Yes| CheckSubdir{Current dir is<br/>project or subdir?} |
| 163 | + |
| 164 | + CheckSubdir -->|Yes| Keep |
| 165 | + CheckSubdir -->|No| Remove[Remove from PATH] |
| 166 | + |
| 167 | + Keep --> Done4[Continue filtering] |
| 168 | + Remove --> Done4 |
| 169 | + end |
| 170 | +
|
| 171 | + style Done1 fill:#90EE90 |
| 172 | + style Done2 fill:#90EE90 |
| 173 | + style Done3 fill:#90EE90 |
| 174 | +``` |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +## 4. Git Post-Checkout Hook (`post-checkout`) |
| 179 | + |
| 180 | +What happens when you switch branches in a Luca-enabled repository. |
| 181 | + |
| 182 | +```mermaid |
| 183 | +flowchart TD |
| 184 | + Start([Git checkout/switch<br/>triggers hook]) --> CheckType{Checkout type?} |
| 185 | + |
| 186 | + CheckType -->|"File checkout (0)"| Exit1([Exit: skip file checkouts]) |
| 187 | + CheckType -->|"Branch checkout (1)"| Continue[Continue processing] |
| 188 | + |
| 189 | + Continue --> FindRoot[Find git repo root] |
| 190 | + FindRoot --> CheckLucafile{Lucafile exists<br/>in repo root?} |
| 191 | + |
| 192 | + CheckLucafile -->|No| Exit2([Exit: no Lucafile]) |
| 193 | + CheckLucafile -->|Yes| CheckLuca{luca command<br/>available?} |
| 194 | + |
| 195 | + CheckLuca -->|No| InstallLuca[Download & run<br/>install.sh] |
| 196 | + CheckLuca -->|Yes| RunInstall |
| 197 | + |
| 198 | + InstallLuca --> CheckInstallResult{Install<br/>successful?} |
| 199 | + CheckInstallResult -->|No| ErrorExit([❌ Exit: install failed]) |
| 200 | + CheckInstallResult -->|Yes| RunInstall |
| 201 | + |
| 202 | + RunInstall["Run:<br/>luca install"] |
| 203 | + RunInstall --> CheckResult{Install<br/>successful?} |
| 204 | + |
| 205 | + CheckResult -->|Yes| Success[✅ Tools synchronized] |
| 206 | + CheckResult -->|No| Warning[⚠️ Some tools may<br/>have failed] |
| 207 | + |
| 208 | + Success --> NotifyPath |
| 209 | + Warning --> NotifyPath |
| 210 | + |
| 211 | + NotifyPath["ℹ️ PATH will update<br/>on next prompt"] |
| 212 | + NotifyPath --> Exit3([Exit: done]) |
| 213 | + |
| 214 | + style Exit1 fill:#FFE4B5 |
| 215 | + style Exit2 fill:#FFE4B5 |
| 216 | + style ErrorExit fill:#FFB6C1 |
| 217 | + style Success fill:#90EE90 |
| 218 | +``` |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +## 5. Uninstallation Flow (`uninstall.sh`) |
| 223 | + |
| 224 | +What gets removed when you run the uninstall script. |
| 225 | + |
| 226 | +```mermaid |
| 227 | +flowchart TD |
| 228 | + Start([Start uninstall.sh]) --> CheckExe{Luca executable<br/>exists?} |
| 229 | + |
| 230 | + CheckExe -->|Yes| GetVersion[Show current version] |
| 231 | + CheckExe -->|No| WarnNoExe[⚠️ Warn: not found] |
| 232 | + |
| 233 | + GetVersion --> RemoveExe |
| 234 | + WarnNoExe --> RemoveExe |
| 235 | + |
| 236 | + RemoveExe[🗑️ Remove<br/>/usr/local/bin/luca] |
| 237 | + RemoveExe --> DetectShell{Detect shell} |
| 238 | + |
| 239 | + DetectShell -->|Bash| UseBashrc[Use ~/.bashrc] |
| 240 | + DetectShell -->|Zsh| UseZshrc[Use ~/.zshrc] |
| 241 | + DetectShell -->|Other| WarnShell[⚠️ Manual cleanup needed] |
| 242 | + |
| 243 | + UseBashrc --> CheckHook |
| 244 | + UseZshrc --> CheckHook |
| 245 | + WarnShell --> RemoveDir |
| 246 | + |
| 247 | + CheckHook{Hook line in<br/>RC file?} |
| 248 | + CheckHook -->|Yes| RemoveHook[Remove hook line<br/>from RC file] |
| 249 | + CheckHook -->|No| InfoNoHook[ℹ️ No hook found] |
| 250 | + |
| 251 | + RemoveHook --> RemoveDir |
| 252 | + InfoNoHook --> RemoveDir |
| 253 | + |
| 254 | + RemoveDir{~/.luca/<br/>exists?} |
| 255 | + RemoveDir -->|Yes| DeleteDir[🗑️ rm -rf ~/.luca/] |
| 256 | + RemoveDir -->|No| InfoNoDir[ℹ️ Not found] |
| 257 | + |
| 258 | + DeleteDir --> Complete |
| 259 | + InfoNoDir --> Complete |
| 260 | + |
| 261 | + Complete([✅ Uninstallation Complete<br/>Restart terminal]) |
| 262 | +``` |
| 263 | + |
| 264 | +--- |
| 265 | + |
| 266 | +## 6. Directory Structure |
| 267 | + |
| 268 | +```mermaid |
| 269 | +flowchart LR |
| 270 | + subgraph System["System Locations"] |
| 271 | + BIN["/usr/local/bin/"] |
| 272 | + BIN --> LUCA["luca (executable)"] |
| 273 | + end |
| 274 | + |
| 275 | + subgraph Home["User Home (~/)"] |
| 276 | + LUCADIR[".luca/"] |
| 277 | + LUCADIR --> SHELLHOOK["shell_hook.sh"] |
| 278 | + |
| 279 | + RCFILES["Shell RC Files"] |
| 280 | + RCFILES --> BASHRC[".bashrc"] |
| 281 | + RCFILES --> ZSHRC[".zshrc"] |
| 282 | + end |
| 283 | + |
| 284 | + subgraph Project["Project Directory"] |
| 285 | + PROJROOT["project/"] |
| 286 | + PROJROOT --> LUCAFILE["Lucafile"] |
| 287 | + PROJROOT --> LUCAVER[".luca-version"] |
| 288 | + PROJROOT --> PROJLUCA[".luca/"] |
| 289 | + PROJLUCA --> ACTIVE["active/ (symlinks)"] |
| 290 | + |
| 291 | + PROJROOT --> GITDIR[".git/"] |
| 292 | + GITDIR --> HOOKS["hooks/"] |
| 293 | + HOOKS --> POSTCHECKOUT["post-checkout"] |
| 294 | + end |
| 295 | +``` |
| 296 | + |
| 297 | +--- |
| 298 | + |
| 299 | +## 7. Complete User Journey |
| 300 | + |
| 301 | +A sequence diagram showing a typical user workflow. |
| 302 | + |
| 303 | +```mermaid |
| 304 | +sequenceDiagram |
| 305 | + participant U as User |
| 306 | + participant T as Terminal |
| 307 | + participant IS as install.sh |
| 308 | + participant SH as shell_hook.sh |
| 309 | + participant G as Git |
| 310 | + participant PC as post-checkout |
| 311 | + participant L as luca CLI |
| 312 | +
|
| 313 | + Note over U,L: First-time Setup |
| 314 | + U->>T: curl ... | bash install.sh |
| 315 | + IS->>IS: Download luca binary |
| 316 | + IS->>IS: Install to /usr/local/bin |
| 317 | + IS->>SH: Download shell_hook.sh |
| 318 | + SH->>T: Modify ~/.zshrc |
| 319 | + IS->>PC: Install git hook (if in repo) |
| 320 | + IS-->>U: ✅ Installation complete |
| 321 | +
|
| 322 | + Note over U,L: Daily Usage - Opening Terminal |
| 323 | + U->>T: Open new terminal |
| 324 | + T->>SH: Source shell_hook.sh |
| 325 | + SH->>SH: Register precmd hook |
| 326 | + SH->>T: Check pwd for .luca/active |
| 327 | +
|
| 328 | + Note over U,L: Daily Usage - Switching Branches |
| 329 | + U->>G: git checkout feature-branch |
| 330 | + G->>PC: Trigger post-checkout |
| 331 | + PC->>PC: Check for Lucafile |
| 332 | + PC->>L: luca install --quiet |
| 333 | + L->>L: Install/update tools |
| 334 | + L-->>PC: Done |
| 335 | + PC-->>G: Done |
| 336 | + |
| 337 | + Note over U,L: Daily Usage - Navigating Directories |
| 338 | + U->>T: cd ~/project |
| 339 | + T->>SH: precmd triggers update_path |
| 340 | + SH->>SH: Add .luca/active to PATH |
| 341 | + U->>T: which <tool> |
| 342 | + T-->>U: ~/project/.luca/active/<tool> |
| 343 | + |
| 344 | + U->>T: cd ~ |
| 345 | + T->>SH: precmd triggers update_path |
| 346 | + SH->>SH: Remove .luca/active from PATH |
| 347 | +``` |
| 348 | + |
| 349 | +--- |
| 350 | + |
| 351 | +## Summary Table |
| 352 | + |
| 353 | +| Script | Purpose | When It Runs | |
| 354 | +|--------|---------|--------------| |
| 355 | +| `install.sh` | Downloads and installs Luca binary, shell hook, and git hook | Manually by user, or triggered by `post-checkout` | |
| 356 | +| `shell_hook.sh` | Manages PATH dynamically based on current directory | On every shell prompt (after `cd`) | |
| 357 | +| `post-checkout` | Syncs tools after branch switch | Automatically after `git checkout`/`git switch` | |
| 358 | +| `uninstall.sh` | Removes all Luca components | Manually by user | |
0 commit comments