Y
This is a custom JS extension built for Superdoc, which is also a self-hosted, open source, browser-based docx editor. So obviously I didn't create the actual word editor platform, the only thing I did was to add the sidebar at the right, which lets you plug in a self-hosted LLM model of your choice using Ollama. Technically the concept sounds easy enough - you just have to (1) send the selected text to the LLM, and tell it how to amend the clause (2) get the revised clause back from the LLM, and (3) redline the differences.
Part (3), as expected, was the most difficult because diff logic is HARD (for me). First I had to actually AMEND google's diff-match-patch library based on its documentation (which ChatGPT kindly explained to me) to create word-level diff instead of character-level (too granular) or line-level diff (too coarse).
Then, Cursor led me down the merry path of computing positional logic (ie remember the actual position of each word to be replaced) which always screwed up. I sparred it with ChatGPT back and forth until they actually GAVE UP and told me to use whole clause replacement (i.e. what I already achieved in my previous post) because it was "simpler".
So after cracking the whip a bit and getting them to read the documentation (which I also had to read from time to time) Claude Sonnet finally gave me the golden answer which is to perform each change SEPARATELY and immediately dispatch it to the editor without having to remember positions. That worked like a charm and solved the problem.
And I feel like I shouldn't have had to figure out (with CS help of course) from scratch how to implement basic diff logic - or to be precise, the insertion/deletion logic - because shouldn't all this stuff be all out there already??
P.S. Am really glad to have gone with diff match patch, which is superbly designed AND documented. CS originally recommended this really under-documented diff library which would definitely have led to a lot more hair pulling! I wish more people spent time creating these wonderful BASIC libraries instead of more sexy stuff. P.P.S. Yes, I know the redraft isn't exactly lawyerly, just wanted something simple for laughs.