pi-agent: Implement progressive Target detection
This commit is contained in:
@@ -106,6 +106,12 @@ func fixedViewport(content string, width, height, offset int, wrap bool) string
|
||||
}
|
||||
|
||||
func (p terminalPresentation) targetBadge(item app.TargetSnapshot, applying bool) string {
|
||||
switch item.DetectionPhase {
|
||||
case app.TargetChecking:
|
||||
return p.theme.checking.Render("… Checking")
|
||||
case app.TargetDetectionFailed:
|
||||
return p.theme.checkFailed.Render("! Check failed")
|
||||
}
|
||||
if !item.Available {
|
||||
return p.theme.unavailable.Render("○ Unavailable")
|
||||
}
|
||||
@@ -115,8 +121,17 @@ func (p terminalPresentation) targetBadge(item app.TargetSnapshot, applying bool
|
||||
func (p terminalPresentation) targetDetails(item app.TargetSnapshot) string {
|
||||
state := p.targetBadge(item, false)
|
||||
evidence := item.Evidence
|
||||
if !item.Available {
|
||||
evidence = item.AvailabilityEvidence
|
||||
switch item.DetectionPhase {
|
||||
case app.TargetChecking:
|
||||
evidence = "Availability and configuration inspection are in progress."
|
||||
case app.TargetDetectionFailed:
|
||||
if evidence == "" {
|
||||
evidence = item.AvailabilityEvidence
|
||||
}
|
||||
default:
|
||||
if !item.Available {
|
||||
evidence = item.AvailabilityEvidence
|
||||
}
|
||||
}
|
||||
if evidence == "" {
|
||||
evidence = "No detection evidence reported."
|
||||
@@ -125,6 +140,9 @@ func (p terminalPresentation) targetDetails(item app.TargetSnapshot) string {
|
||||
var details strings.Builder
|
||||
details.WriteString(p.theme.section.Render(item.Description.Name))
|
||||
fmt.Fprintf(&details, "\nState: %s\nEvidence: %s", state, evidence)
|
||||
if item.DetectionPhase == app.TargetDetectionFailed && item.DetectionErr != nil {
|
||||
fmt.Fprintf(&details, "\nCheck error: %s", item.DetectionErr)
|
||||
}
|
||||
facts := []struct {
|
||||
label string
|
||||
value string
|
||||
@@ -150,9 +168,16 @@ func (p terminalPresentation) targetDetails(item app.TargetSnapshot) string {
|
||||
|
||||
func (p terminalPresentation) stateCountSummary(snapshot app.Snapshot) string {
|
||||
counts := countAvailableTargetStates(snapshot)
|
||||
return fmt.Sprintf("%s %d %s %d %s %d %s %d",
|
||||
summary := fmt.Sprintf("%s %d %s %d %s %d %s %d",
|
||||
p.theme.renderTargetState(target.Enabled, false), counts.enabled,
|
||||
p.theme.renderTargetState(target.Disabled, false), counts.disabled,
|
||||
p.theme.renderTargetState(target.External, false), counts.external,
|
||||
p.theme.renderTargetState(target.Drifted, false), counts.drifted)
|
||||
if counts.checking > 0 {
|
||||
summary += fmt.Sprintf(" %s %d", p.theme.checking.Render("… Checking"), counts.checking)
|
||||
}
|
||||
if counts.failed > 0 {
|
||||
summary += fmt.Sprintf(" %s %d", p.theme.checkFailed.Render("! Check failed"), counts.failed)
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user