package loop import ( "context" "git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/capacity" ) // capStateKey is the context key for the per-Run capacity-state accumulator. type capStateKey struct{} // capStateAccum holds the mutable capacity state for one Run so the state // progresses across a multi-step tool loop (quiet→awake→full) without leaking // between concurrent runs. It lives on the context seeded at the top of Run. type capStateAccum struct { state capacity.State } // withCapState returns a context carrying acc. func withCapState(ctx context.Context, acc *capStateAccum) context.Context { return context.WithValue(ctx, capStateKey{}, acc) } // capState returns the accumulator on ctx, or a fresh quiet one when none is // seeded (a defensive fallback for a caller that invokes toolSchemas outside // Run, where the state is not meant to persist). func capState(ctx context.Context) *capStateAccum { if acc, ok := ctx.Value(capStateKey{}).(*capStateAccum); ok { return acc } return &capStateAccum{state: capacity.StateQuiet} }