mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
- Add bubbletea TUI for multi-skill audit results (side-by-side layout with skill list + detail panel, severity sorting, fuzzy filter) - Add progress bar during parallel scan via onDone callback - Add --quiet/-q flag to suppress clean skill lines - Add --yes/-y flag to skip large-scan confirmation prompt (>1000 skills) - Add --no-tui flag to force plain text output - Scale parallel workers to NumCPU (bounded 2–32) instead of fixed 8 - Use file cache in content-integrity check to avoid redundant disk reads - Replace line splitting with streaming scan (avoid full []string alloc) - Remove snippet truncation (preserve full trimmed line) - Differentiate LOW (bright blue) and INFO (medium gray) severity colors - Centralize log TUI color styles into `lc` struct - Export DisplayWidth and add BoxWithMinWidth/HeaderBoxWithMinWidth for aligned header + summary box widths - Update docs with TUI controls, new flags, and CI/CD auto-skip behavior
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package audit
|
|
|
|
import (
|
|
"runtime"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// workerCount returns a bounded worker count based on available CPUs.
|
|
// Floor: 2 (always some parallelism). Ceiling: 32 (avoid fd exhaustion).
|
|
func workerCount() int {
|
|
n := runtime.NumCPU()
|
|
if n < 2 {
|
|
return 2
|
|
}
|
|
if n > 32 {
|
|
return 32
|
|
}
|
|
return n
|
|
}
|
|
|
|
// SkillInput describes a skill to scan.
|
|
type SkillInput struct {
|
|
Name string
|
|
Path string
|
|
}
|
|
|
|
// ScanOutput holds the result of scanning a single skill.
|
|
type ScanOutput struct {
|
|
Result *Result
|
|
Err error
|
|
Elapsed time.Duration
|
|
}
|
|
|
|
// ParallelScan scans skills concurrently with bounded workers.
|
|
// projectRoot being empty means global mode; non-empty means project mode.
|
|
// onDone is called after each skill finishes (nil-safe); use it to drive a progress bar.
|
|
// Returns []ScanOutput aligned by index with the input slice.
|
|
func ParallelScan(skills []SkillInput, projectRoot string, onDone func()) []ScanOutput {
|
|
outputs := make([]ScanOutput, len(skills))
|
|
if len(skills) == 0 {
|
|
return outputs
|
|
}
|
|
|
|
sem := make(chan struct{}, workerCount())
|
|
var wg sync.WaitGroup
|
|
|
|
for i, sk := range skills {
|
|
wg.Add(1)
|
|
sem <- struct{}{}
|
|
go func(idx int, path string) {
|
|
defer wg.Done()
|
|
defer func() { <-sem }()
|
|
start := time.Now()
|
|
var res *Result
|
|
var err error
|
|
if projectRoot != "" {
|
|
res, err = ScanSkillForProject(path, projectRoot)
|
|
} else {
|
|
res, err = ScanSkill(path)
|
|
}
|
|
outputs[idx] = ScanOutput{
|
|
Result: res,
|
|
Err: err,
|
|
Elapsed: time.Since(start),
|
|
}
|
|
if onDone != nil {
|
|
onDone()
|
|
}
|
|
}(i, sk.Path)
|
|
}
|
|
wg.Wait()
|
|
|
|
return outputs
|
|
}
|