I'm a long-time Memento user, but didn't bother with scripting until now. I've been reading the docs, to see if it's possible to get it to do what I want, and noticed that scripting has quite a few limitations...
But after a lot more thinking (and searching), I realised there are work-arounds for at least some of them, which I'll list below.
Please let me know if I'm mistaken, or if there's a better solution:
* No way for a Script field to access the fields of other entries (as libs() is not available). However, this is not quite true - there is a limited way to access another entry, and you can use this to access all the entries with a bit of work:
If your entry has a field which Links to another entry, then you can access the fields of that other entry... So if you give each entry a link to the Next (and/or Previous) entry in the library, then you can step through every entry in the library! So all you need now is a Script (ran manually or otherwise) which goes through all entries, and links them together using the Next (and/or Previous) fields. This solution is tested as working :)
* No way to store "global" state. The solution is to have another library, and have each entry link to an entry in that other library. In simple cases that other library would only have one entry, but in more complex cases you can have several entries (which store "semi-global" state). So you then just need a Script which runs when an entry is created, and have it set the entry to link to the "global" state.
However, as Memento appears to store when an entry is linked to by another entry, this will lead to one entry knowing it's linked to by hundreds of other entries. I'm unclear if this will cause Memento to perform badly (hopefully not). But at the very least you should tell Memento to NOT "Display on the card" & "Display aggregation" all the entries which link to an entry.
* No way to access or control the Filters. The solution I thought of is that every entry would have a boolean field (let's call it Hidden), and a single filter which hides entries with Hidden=True. Then instead of users changing filters in the normal way, you would have an Action script button(s) for changing what is filtered. Your script would probably have Arguments that the user can adjust, to choose what they want filtered. The script then goes through every entry, setting Hidden accordingly. I suspect this will be a bit slow, but seems like the best option unless JavaScript is allowed to control Filters directly. It could potentially also be optimised, by only recalculating Hidden for entries that may change state (although this would be a bit tricky).
Another alternative would be to make the Hidden field be a Script itself (with "Execute script in real time" enabled), which would calculate whether the entry should be visible (based only upon the entry's own fields - and those of any entries that it links to). You can use my 'global state' solution (i.e. a link to a shared entry in another library) as a way to give users control over what is filtered (and have that be persistent). On the downside I suspect this will perform worse.
* Limited ability to store data, as all entries must have the same fields. Probably obvious, but that just means you need to have multiple libraries! And probably Group them together to avoid things getting cluttered.
Effectively you can imagine that each Library is a class in an object-orientated language, and each Entry is an object of that class. So if your big program needs several types of objects, then you just need to have several libraries!
* libs().entries() does not give you any control over the order of the array, so you have to sort it every time (which is a bit slow). I read that the order of entries in the array is in Creation Time order. It also appears that you can read & write the "creationTime" field of an entry, so I'm planning to set this field directly. As long as I only want the entries() array in one particular order, then I should be able to force Memento to return the entries() array in that order!