You could walk the syntax tree to find all the lines that start a 1st-level nesting, collect foldEffects for those lines, and dispatch those. For big documents it may be somewhat tricky to get the editor to parse the entire document, but you can use ensureSyntaxTree if you want to force it to do that immediately.
I’m sorry, I don’t have the time or energy to help people write specific code here. I provide the library, I wrote docs, if you can’t take it from there you’ll have to do more studying or hire someone to implement this.