diff --git a/internal/server/handler_update.go b/internal/server/handler_update.go index 0d24c8abb..44f9780d3 100644 --- a/internal/server/handler_update.go +++ b/internal/server/handler_update.go @@ -22,10 +22,12 @@ type updateRequest struct { } type updateResultItem struct { - Name string `json:"name"` - Action string `json:"action"` // "updated", "up-to-date", "skipped", "error", "blocked" - Message string `json:"message,omitempty"` - IsRepo bool `json:"isRepo"` + Name string `json:"name"` + Action string `json:"action"` // "updated", "up-to-date", "skipped", "error", "blocked" + Message string `json:"message,omitempty"` + IsRepo bool `json:"isRepo"` + AuditRiskScore int `json:"auditRiskScore,omitempty"` + AuditRiskLabel string `json:"auditRiskLabel,omitempty"` } func (s *Server) handleUpdate(w http.ResponseWriter, r *http.Request) { @@ -178,23 +180,29 @@ func (s *Server) updateTrackedRepo(name, repoPath string, force, skipAudit bool) } // Post-pull audit gate - if !skipAudit { - if blocked := s.auditGateTrackedRepo(name, repoPath, info.BeforeHash); blocked != nil { - return *blocked - } - } - - return updateResultItem{ + item := updateResultItem{ Name: name, Action: "updated", Message: fmt.Sprintf("%d commits, %d files changed", len(info.Commits), info.Stats.FilesChanged), IsRepo: true, } + if !skipAudit { + blocked, auditResult := s.auditGateTrackedRepo(name, repoPath, info.BeforeHash) + if blocked != nil { + return *blocked + } + if auditResult != nil { + item.AuditRiskScore = auditResult.RiskScore + item.AuditRiskLabel = auditResult.RiskLabel + } + } + + return item } // auditGateTrackedRepo scans a tracked repo after pull and rolls back if HIGH/CRITICAL. -// Returns a blocked result item, or nil if the update should proceed. -func (s *Server) auditGateTrackedRepo(name, repoPath, beforeHash string) *updateResultItem { +// Returns (blocked item, audit result). blocked is non-nil when the update should be rejected. +func (s *Server) auditGateTrackedRepo(name, repoPath, beforeHash string) (*updateResultItem, *audit.Result) { var result *audit.Result var err error if s.IsProjectMode() { @@ -213,7 +221,7 @@ func (s *Server) auditGateTrackedRepo(name, repoPath, beforeHash string) *update Action: "blocked", Message: msg, IsRepo: true, - } + }, nil } if result.HasHigh() { @@ -228,10 +236,10 @@ func (s *Server) auditGateTrackedRepo(name, repoPath, beforeHash string) *update Action: "blocked", Message: msg, IsRepo: true, - } + }, result } - return nil + return nil, result } func (s *Server) updateRegularSkill(name, skillPath string, skipAudit bool) updateResultItem { @@ -249,7 +257,8 @@ func (s *Server) updateRegularSkill(name, skillPath string, skipAudit bool) upda if s.IsProjectMode() { opts.AuditProjectRoot = s.projectRoot } - if _, err = install.Install(source, skillPath, opts); err != nil { + result, err := install.Install(source, skillPath, opts) + if err != nil { return updateResultItem{ Name: name, Action: "error", @@ -257,11 +266,16 @@ func (s *Server) updateRegularSkill(name, skillPath string, skipAudit bool) upda } } - return updateResultItem{ + item := updateResultItem{ Name: name, Action: "updated", Message: "reinstalled from source", } + if result != nil && result.AuditRiskLabel != "" { + item.AuditRiskScore = result.AuditRiskScore + item.AuditRiskLabel = result.AuditRiskLabel + } + return item } func (s *Server) updateAll(force, skipAudit bool) []updateResultItem { diff --git a/internal/server/handler_update_test.go b/internal/server/handler_update_test.go index 24bf25046..5d30a71a8 100644 --- a/internal/server/handler_update_test.go +++ b/internal/server/handler_update_test.go @@ -63,7 +63,7 @@ func TestAuditGateTrackedRepo_RollbackFailure_ReportsWarning(t *testing.T) { s := &Server{cfg: cfg} // Pass an invalid beforeHash so git reset --hard will fail - result := s.auditGateTrackedRepo("test-repo", repoDir, "0000000000000000000000000000000000000000") + result, _ := s.auditGateTrackedRepo("test-repo", repoDir, "0000000000000000000000000000000000000000") if result == nil { t.Fatal("expected blocked result, got nil (audit should detect HIGH finding)") @@ -88,7 +88,7 @@ func TestAuditGateTrackedRepo_ScanError_RollbackFailure_ReportsWarning(t *testin // Non-existent path โ†’ audit.ScanSkill returns error, git.ResetHard also fails nonExistentPath := filepath.Join(t.TempDir(), "does-not-exist") - result := s.auditGateTrackedRepo("test-repo", nonExistentPath, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") + result, _ := s.auditGateTrackedRepo("test-repo", nonExistentPath, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") if result == nil { t.Fatal("expected blocked result") @@ -125,8 +125,14 @@ func TestAuditGateTrackedRepo_Clean_ReturnsNil(t *testing.T) { cfg := &config.Config{Source: t.TempDir()} s := &Server{cfg: cfg} - result := s.auditGateTrackedRepo("clean-repo", repoDir, "doesntmatter") - if result != nil { - t.Errorf("expected nil for clean repo, got action=%q message=%q", result.Action, result.Message) + blocked, auditResult := s.auditGateTrackedRepo("clean-repo", repoDir, "doesntmatter") + if blocked != nil { + t.Errorf("expected nil for clean repo, got action=%q message=%q", blocked.Action, blocked.Message) + } + if auditResult == nil { + t.Fatal("expected audit result for clean repo") + } + if auditResult.RiskLabel != "clean" { + t.Errorf("expected riskLabel=clean, got %q", auditResult.RiskLabel) } } diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index 24883b604..3be1e3eb0 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -298,6 +298,8 @@ export interface UpdateResultItem { action: string; // "updated", "up-to-date", "skipped", "error", "blocked" message?: string; isRepo: boolean; + auditRiskScore?: number; + auditRiskLabel?: string; } export interface AvailableTarget { diff --git a/ui/src/pages/SkillDetailPage.tsx b/ui/src/pages/SkillDetailPage.tsx index 05a213161..a405984eb 100644 --- a/ui/src/pages/SkillDetailPage.tsx +++ b/ui/src/pages/SkillDetailPage.tsx @@ -219,7 +219,10 @@ export default function SkillDetailPage() { const res = await api.update({ name: skillName, skipAudit }); const item = res.results[0]; if (item?.action === 'updated') { - toast(`Updated: ${item.name} โ€” ${item.message}`, 'success'); + const auditInfo = item.auditRiskLabel + ? ` ยท Security: ${item.auditRiskLabel.toUpperCase()}${item.auditRiskScore ? ` (${item.auditRiskScore}/100)` : ''}` + : ''; + toast(`Updated: ${item.name} โ€” ${item.message}${auditInfo}`, 'success'); refetch(); } else if (item?.action === 'up-to-date') { toast(`${item.name} is already up to date.`, 'info');