MCPcopy Index your code
hub / github.com/codehamr/codehamr / FromHeaders

Function FromHeaders

internal/cloud/cloud.go:68–87  ·  view source on GitHub ↗

FromHeaders reads the budget header. Missing (e.g. local Ollama) yields the zero value and the UI skips the segment. Out-of-range values are clamped, not rejected, so server-side rounding past 1.0 doesn't blank the readout. NaN/±Inf are rejected: NaN slips past the clamp (all comparisons false), an

(h http.Header)

Source from the content-addressed store, hash-verified

66// the UI's int(NaN*100+0.5) yields MinInt64 → a garbage percentage. Both are
67// treated as "no signal", like a missing header.
68func FromHeaders(h http.Header) BudgetStatus {
69 raw := h.Get(headerRemaining)
70 if raw == "" {
71 return BudgetStatus{}
72 }
73 v, err := strconv.ParseFloat(raw, 64)
74 if err != nil {
75 return BudgetStatus{}
76 }
77 if math.IsNaN(v) || math.IsInf(v, 0) {
78 return BudgetStatus{}
79 }
80 switch {
81 case v < 0:
82 v = 0
83 case v > 1:
84 v = 1
85 }
86 return BudgetStatus{Set: true, Remaining: v}
87}
88
89// StatusSuffix builds the " · 73% pass" status-bar tail; "" before the first
90// snapshot. Rounded to nearest percent so it doesn't jitter on every token.

Callers 5

ProbeMethod · 0.92
runMethod · 0.92
TestFromHeadersMissingFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestFromHeadersMissingFunction · 0.68