mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* feat(audit): honor findings accepted with --force via --respect-accepted install and update --force record the findings a user accepted in audit_accepted, but audit ignored that record. A skill installed with --force therefore kept failing `skillshare audit` in CI with no way to let the accepted findings pass (#869). audit --respect-accepted marks those findings as acknowledged. They stay in every output (JSON acknowledged: true, a text/TUI note, "(accepted earlier)" in Markdown, SARIF external suppressions), but they are counted in summary.accepted instead of their severity and no longer fail the audit. Without the flag nothing changes, so existing CI gates keep their behavior. A changed file or snippet produces a new key and blocks again. Tracked repositories record acceptances at the repo root with paths relative to it, so ApplyAcceptedFindings walks up from each skill to match them. The install, update and edit gates use the same function and now honor repo-wide acceptances for skills inside tracked repos too. The dashboard always honors accepted findings: the Audit page mutes them and counts them apart, the skill Audit tab collapses them, and the Dashboard attention card no longer lists a skill whose only blocking findings were accepted. The CLI JSON summary and the server summary share Result.CountOpenBySeverity so both count accepted findings the same way. The oplog records the accepted count and the log views show it. * fix(audit): match acceptances when a single file is scanned A single-file scan names its findings by the file's base name, but the ancestor lookup used the file's whole path as the prefix, so it hashed SKILL.md/SKILL.md instead of the recorded SKILL.md. Auditing a skill file directly with --respect-accepted, and auditing agents inside a tracked repository in the CLI or the dashboard, still failed on unchanged accepted findings. For a file target the prefix is now the file's own directory.
100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"skillshare/internal/audit"
|
|
)
|
|
|
|
// handleAuditStream serves an SSE endpoint that streams audit progress in real time.
|
|
// Events:
|
|
// - "start" → {"total": N} after skill discovery
|
|
// - "progress" → {"scanned": N} every 200ms during scan
|
|
// - "done" → {"results":…,"summary":…} final payload (same shape as GET /api/audit)
|
|
func (s *Server) handleAuditStream(w http.ResponseWriter, r *http.Request) {
|
|
safeSend, ok := initSSE(w)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
start := time.Now()
|
|
|
|
// Snapshot config under RLock, then release before slow I/O.
|
|
s.mu.RLock()
|
|
source, resultKind, isAgents := s.resolveAuditSource(r)
|
|
projectRoot := s.projectRoot
|
|
policy := s.auditPolicy()
|
|
s.mu.RUnlock()
|
|
|
|
// 1. Discover skills/agents
|
|
walk := s.skillsWalk()
|
|
var skills []skillEntry
|
|
var err error
|
|
if isAgents {
|
|
skills, err = discoverAuditAgents(source)
|
|
} else {
|
|
skills, err = discoverAuditSkills(source, walk)
|
|
}
|
|
if err != nil {
|
|
safeSend("error", map[string]string{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
safeSend("start", map[string]int{"total": len(skills)})
|
|
|
|
// 2. Atomic counter + ticker for progress events
|
|
var scanned atomic.Int64
|
|
ctx := r.Context()
|
|
done := make(chan struct{})
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
ticker := time.NewTicker(200 * time.Millisecond)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
safeSend("progress", map[string]int64{"scanned": scanned.Load()})
|
|
case <-done:
|
|
return
|
|
case <-ctx.Done():
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
onDone := func() { scanned.Add(1) }
|
|
|
|
// 3. Parallel scan (blocks until all skills are scanned)
|
|
var inputs []audit.SkillInput
|
|
if isAgents {
|
|
inputs = make([]audit.SkillInput, len(skills))
|
|
for i, s := range skills {
|
|
inputs[i] = audit.SkillInput{Name: s.name, Path: s.path, IsFile: true}
|
|
}
|
|
} else {
|
|
inputs = skillsToAuditInputs(skills)
|
|
}
|
|
outputs := audit.ParallelScan(inputs, projectRoot, onDone, nil, walk.Follow)
|
|
close(done) // signal ticker goroutine to stop
|
|
wg.Wait() // wait for it to fully exit before writing to w
|
|
|
|
// 4. Process results
|
|
agg := processAuditResults(skills, outputs, policy, projectRoot, source)
|
|
for i := range agg.Results {
|
|
agg.Results[i].Kind = resultKind
|
|
}
|
|
s.writeAuditLog(agg.Status, start, agg.LogArgs, agg.Message)
|
|
|
|
// 5. Send final result (no concurrent writers at this point)
|
|
safeSend("done", withSourceLinkStatus(map[string]any{
|
|
"results": agg.Results,
|
|
"summary": agg.Summary,
|
|
}, walk))
|
|
}
|