package loop import "context" // muteKey is the context key for the "suppress UI broadcast" flag. When set, // a Run performs its work as usual but does NOT push stream/thinking/capacity // events to the UI channel (OnStream / OnCapacity). This is used by internal // autonomous passes (e.g. background reflection) whose intermediate reasoning // must not leak into the user-facing chat stream. The loop itself is unchanged; // only the outward event emission is muted. type muteKey struct{} // WithMutedBroadcast returns a context whose loop Run suppresses UI stream and // capacity broadcast, while still returning the final result to the caller. func WithMutedBroadcast(ctx context.Context) context.Context { return context.WithValue(ctx, muteKey{}, true) } // isMutedBroadcast reports whether the Run driving ctx should suppress UI // broadcast. An unset flag (the common case) returns false so normal chat // streaming is untouched. func isMutedBroadcast(ctx context.Context) bool { v, _ := ctx.Value(muteKey{}).(bool) return v }