smart-tree 8.0.1

Smart Tree - An intelligent, AI-friendly directory visualization tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# ๐ŸŒณ Smart Tree Management Script for Windows ๐ŸŒณ
# PowerShell equivalent of manage.sh for Windows developers

param(
    [Parameter(Position = 0)]
    [string]$Command = "help",
    
    [Parameter(Position = 1, ValueFromRemainingArguments = $true)]
    [string[]]$Arguments
)

# Project info
$ProjectName = "Smart Tree (st)"
$ProjectDir = Split-Path -Parent $PSScriptRoot
$BinaryName = "st.exe"

# Helper functions
function Write-Header {
    param([string]$Message)
    Write-Host ""
    Write-Host "๐ŸŒณ $Message ๐ŸŒณ" -ForegroundColor Cyan
    Write-Host ""
}

function Write-Success {
    param([string]$Message)
    Write-Host "โœ… $Message" -ForegroundColor Green
}

function Write-Error {
    param([string]$Message)
    Write-Host "โŒ $Message" -ForegroundColor Red
    throw $Message
}

function Write-Info {
    param([string]$Message)
    Write-Host "๐Ÿ“Š $Message" -ForegroundColor Blue
}

function Write-Warning {
    param([string]$Message)
    Write-Host "โš ๏ธ  $Message" -ForegroundColor Yellow
}

# Build the project
function Invoke-Build {
    param(
        [string]$BuildType = "release",
        [string]$Features = ""
    )
    
    Write-Header "Building $ProjectName in $BuildType mode โš™๏ธ"
    
    Push-Location $ProjectDir
    
    try {
        $featureFlags = ""
        if ($Features) {
            $featureFlags = "--features $Features"
            Write-Info "Building with features: $Features"
        }
        
        if ($BuildType -eq "release") {
            Write-Info "Optimizing for maximum speed... ๐Ÿš€"
            cargo build --release $featureFlags
            
            $binaryPath = Join-Path $ProjectDir "target\release\$BinaryName"
            if (Test-Path $binaryPath) {
                $size = (Get-Item $binaryPath).Length / 1MB
                Write-Success "Release build complete! Binary size: $([math]::Round($size, 2)) MB"
            }
        } else {
            Write-Info "Building debug version with all the debugging goodies..."
            cargo build $featureFlags
            Write-Success "Debug build complete!"
        }
    } finally {
        Pop-Location
    }
}

# Run the project
function Invoke-Run {
    Write-Header "Running $ProjectName ๐Ÿš€"
    
    Push-Location $ProjectDir
    
    try {
        if ($Arguments.Count -eq 0) {
            Write-Info "No arguments provided, analyzing current directory..."
            cargo run --release -- .
        } else {
            cargo run --release -- $Arguments
        }
    } finally {
        Pop-Location
    }
}

# Run tests
function Invoke-Test {
    Write-Header "Testing $ProjectName ๐Ÿงช"
    
    Push-Location $ProjectDir
    
    try {
        $ErrorActionPreference = 'Stop'
        
        Write-Info "Running unit tests..."
        cargo test
        if ($LASTEXITCODE -ne 0) { throw "Tests failed" }
        
        Write-Info "Running clippy (our friendly neighborhood linter)..."
        cargo clippy -- -D warnings
        if ($LASTEXITCODE -ne 0) { throw "Clippy failed" }
        
        Write-Info "Checking formatting..."
        cargo fmt -- --check
        if ($LASTEXITCODE -ne 0) { throw "Format check failed" }
        
        Write-Success "All tests passed! Your tree is healthy! ๐ŸŒณ"
    } catch {
        Write-Warning "Some checks failed: $_"
        $global:LASTEXITCODE = 1
    } finally {
        Pop-Location
    }
}

# Format code
function Invoke-Format {
    Write-Header "Formatting code โœจ"
    
    Push-Location $ProjectDir
    
    try {
        cargo fmt
        Write-Success "Code formatted! Looking prettier than a bonsai tree! ๐ŸŽ‹"
    } finally {
        Pop-Location
    }
}

# Clean build artifacts
function Invoke-Clean {
    Write-Header "Cleaning up ๐Ÿงน"
    
    Push-Location $ProjectDir
    
    try {
        cargo clean
        Write-Success "All clean! Fresh as a spring forest! ๐ŸŒฑ"
    } finally {
        Pop-Location
    }
}

# Show project status
function Show-Status {
    Write-Header "Project Status ๐Ÿ“Š"
    
    Push-Location $ProjectDir
    
    try {
        Write-Host "Project: " -NoNewline -ForegroundColor Magenta
        Write-Host $ProjectName
        
        Write-Host "Location: " -NoNewline -ForegroundColor Magenta
        Write-Host $ProjectDir
        
        Write-Host "Rust version: " -NoNewline -ForegroundColor Magenta
        rustc --version
        
        Write-Host "Cargo version: " -NoNewline -ForegroundColor Magenta
        cargo --version
        
        $releaseBinary = Join-Path $ProjectDir "target\release\$BinaryName"
        if (Test-Path $releaseBinary) {
            $size = (Get-Item $releaseBinary).Length / 1MB
            $modified = (Get-Item $releaseBinary).LastWriteTime
            
            Write-Host "Release binary: " -NoNewline -ForegroundColor Magenta
            Write-Host "$([math]::Round($size, 2)) MB"
            
            Write-Host "Last modified: " -NoNewline -ForegroundColor Magenta
            Write-Host $modified.ToString("yyyy-MM-dd HH:mm:ss")
        } else {
            Write-Host "Release binary: " -NoNewline -ForegroundColor Magenta
            Write-Host "Not built yet"
        }
        
        Write-Host ""
        Write-Host "Dependencies:" -ForegroundColor Magenta
        cargo tree --depth 1 | Select-Object -First 20
        
        Write-Host ""
        Write-Host "Git status:" -ForegroundColor Magenta
        if (Get-Command git -ErrorAction SilentlyContinue) {
            git status --short
        } else {
            Write-Host "  Git not found"
        }
    } finally {
        Pop-Location
    }
}

# Install binary
function Install-Binary {
    param([string]$InstallDir = "$env:LOCALAPPDATA\Programs\st")
    
    Write-Header "Installing $ProjectName ๐ŸŽฏ"
    
    Push-Location $ProjectDir
    
    try {
        Write-Info "Building release version..."
        cargo build --release
        
        if (-not (Test-Path $InstallDir)) {
            New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
        }
        
        $sourcePath = Join-Path $ProjectDir "target\release\$BinaryName"
        $destPath = Join-Path $InstallDir $BinaryName
        
        Copy-Item $sourcePath $destPath -Force
        Write-Success "Installed to $destPath"
        
        # Check if in PATH
        $userPath = [Environment]::GetEnvironmentVariable("Path", "User")
        if ($userPath -notlike "*$InstallDir*") {
            Write-Info "Adding $InstallDir to your PATH..."
            $newPath = "$($userPath.TrimEnd(';'));$InstallDir"
            [Environment]::SetEnvironmentVariable("Path", $newPath, "User")
            Write-Success "Added to PATH. Please restart your terminal."
        }
        
        Write-Info "You can now use '$BinaryName' from anywhere! ๐Ÿš€"
    } finally {
        Pop-Location
    }
}

# Show examples
function Show-Examples {
    Write-Header "Usage Examples โœจ"
    
    Write-Host @"
Basic usage:
  st                          # Analyze current directory
  st C:\path\to\dir           # Analyze specific directory
  
Output modes:
  st -m hex                   # Hexadecimal format (AI-friendly)
  st -m json                  # JSON output
  st -m ai                    # AI-optimized format
  st -m digest                # Super compact digest
  st -m stats                 # Statistics only
  
Filtering:
  st --find "*.rs"            # Find Rust files
  st --type rs                # Only .rs files
  st --min-size 1M            # Files larger than 1MB
  
Options:
  st --no-emoji               # Plain text output
  st --depth 3                # Limit depth
  st -z                       # Compress output
  
Streaming Mode:
  st --stream                 # Stream output as files are found
  st --stream -m hex          # Great for huge directories
  
File Content Search:
  st --search "TODO"          # Find TODO in all text files
  st --type rs --search "fn"  # Search for "fn" in Rust files
  
PowerShell Integration:
  st --mode json . | ConvertFrom-Json
  st | Out-File tree.txt
  
MCP (Model Context Protocol):
  .\manage.ps1 mcp-run        # Run as MCP server
  .\manage.ps1 mcp-config     # Show Claude Desktop config
"@
}

# Show help
function Show-Help {
    Write-Host @"
๐ŸŒณ Smart Tree Management Script for Windows ๐ŸŒณ

Usage: .\manage.ps1 [command] [options]

Commands:
  build [debug|release]       Build the project
  run [args...]              Run st with arguments
  test                       Run tests, linting, and format check
  format                     Format code with rustfmt
  clean                      Clean build artifacts
  status                     Show project status
  install [dir]              Install binary (default: %LOCALAPPDATA%\Programs\st)
  examples                   Show usage examples
  help                       Show this help message

MCP Commands:
  mcp-run                    Run as MCP server
  mcp-config                 Show Claude Desktop configuration

Examples:
  .\manage.ps1 build         # Build release version
  .\manage.ps1 run -- -m hex .  # Run with hex output on current dir
  .\manage.ps1 test          # Run all tests
  .\manage.ps1 install       # Install to default location

Made with โœจ and ๐ŸŒณ by the Smart Tree team!
"@
}

# MCP commands
function Invoke-McpRun {
    Write-Header "Running MCP server ๐Ÿค–"
    
    Push-Location $ProjectDir
    
    try {
        $binaryPath = Join-Path $ProjectDir "target\release\$BinaryName"
        if (-not (Test-Path $binaryPath)) {
            Write-Warning "Binary not found. Building release version..."
            Invoke-Build -BuildType release
        }
        
        Write-Info "Starting MCP server on stdio..."
        Write-Info "Press Ctrl+C to stop"
        & $binaryPath --mcp
    } finally {
        Pop-Location
    }
}

function Show-McpConfig {
    Write-Header "MCP Configuration ๐Ÿค–"
    
    Push-Location $ProjectDir
    
    try {
        $binaryPath = Join-Path $ProjectDir "target\release\$BinaryName"
        if (-not (Test-Path $binaryPath)) {
            Write-Warning "Building release version first..."
            Invoke-Build -BuildType release
        }
        
        & $binaryPath --mcp-config
    } finally {
        Pop-Location
    }
}

# Main command dispatcher
switch ($Command.ToLower()) {
    "build" {
        $buildType = if ($Arguments.Count -gt 0) { $Arguments[0] } else { "release" }
        $features = if ($Arguments.Count -gt 1) { $Arguments[1] } else { "" }
        Invoke-Build -BuildType $buildType -Features $features
    }
    "run" {
        Invoke-Run
    }
    "test" {
        Invoke-Test
    }
    "format" {
        Invoke-Format
    }
    "fmt" {
        Invoke-Format
    }
    "clean" {
        Invoke-Clean
    }
    "status" {
        Show-Status
    }
    "info" {
        Show-Status
    }
    "install" {
        $installDir = if ($Arguments.Count -gt 0) { $Arguments[0] } else { "$env:LOCALAPPDATA\Programs\st" }
        Install-Binary -InstallDir $installDir
    }
    "examples" {
        Show-Examples
    }
    "mcp-run" {
        Invoke-McpRun
    }
    "mcp-config" {
        Show-McpConfig
    }
    "help" {
        Show-Help
    }
    "-h" {
        Show-Help
    }
    "--help" {
        Show-Help
    }
    default {
        Write-Host ""
        Show-Help
        Write-Error "Unknown command: $Command"
    }
}