1234567891011121314151617181920212223242526(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)type('context,'action)option_={action:'action;label:string;score:'context->float}letscores(options:('context,'action)option_list)(c:'context):('action*float)list=List.map(funo->(o.action,o.scorec))optionsletchoose?current?(inertia=0.)(options:('context,'action)option_list)(c:'context):'actionoption=letbonusa=ifSomea=currenttheninertiaelse0.inList.fold_left(funbest(a,s)->lets=s+.bonusainmatchbestwithSome(_,s')whens'>=s->best|_->Some(a,s))None(scoresoptionsc)|>Option.mapfstletclamp01(x:float):float=Float.max0.(Float.min1.x)letlinear~(lo:float)~(hi:float)(x:float):float=clamp01((x-.lo)/.(hi-.lo))