package loop import "context" // loopSessionIDKey is the context key for the session id the current Run is // driving. It is seeded at the top of Run and read where the loop emits a // session-scoped UI event (capacity_awaken), so the event carries the right // session rather than being treated as global. type loopSessionIDKey struct{} // withLoopSession returns a context carrying the Run's session id. func withLoopSession(ctx context.Context, sessionID string) context.Context { return context.WithValue(ctx, loopSessionIDKey{}, sessionID) } // loopSession returns the session id on ctx, or "" when none was seeded (a // defensive fallback for a caller that drives the loop outside Run). func loopSession(ctx context.Context) string { s, _ := ctx.Value(loopSessionIDKey{}).(string) return s }