AbanteAI / mentat

Mentat - The AI Coding Assistant
https://mentat.ai
Apache License 2.0
2.41k stars 225 forks source link

Textual improvements #520

Open PCSwingle opened 4 months ago

PCSwingle commented 4 months ago

As discussed here https://github.com/AbanteAI/mentat/pull/502#pullrequestreview-1868117548:

CarlQLange commented 4 months ago

The UX here is strange because presumably users will almost never switch back and forth.

Just to chime in, I frequently change Emacs and CLI theme using pywal, like multiple times a day. It's a bit frustrating that the new Textual UI doesn't pick up the theme the rest of my CLI is using and I have burned my retinas twice already today :)

(Mildly related I would love to have a mentat --server so I could interface with mentat directly from Emacs, but that's beside the point)

jakethekoenig commented 4 months ago

@CarlQLange Thanks for the feedback.

You might already know this but as a quick fix you can change the theme by putting "theme": "dark" in your mentat config.

It seems in general like it's a hard problem to detect and match the user's terminal theme. It'd probably be good if we could at least serve dark mode if their bg color is darker than some threshold.

I like the idea of mentat --server. Maybe I'll make an issue for it. You imagine functionality similar to what e.g. nvim has: https://neovim.io/doc/user/remote.html

CarlQLange commented 4 months ago

I don't know enough about Textual really, but I guess I'm surprised there isn't a way to just 'passthrough' to the terminal's set colours.

Anyway - very interesting link to nvim. I think that would fit the bill quite nicely - what I really want is to implement a frontend (or 'porcelain') for mentat in Emacs. It would potentially also be nice to be able to drive mentat from shell scripts. For example I might need to convert docker-compose files into kubernetes yaml in 50 repos. Mentat does quite a good job of this but I wish I could just write the instructions once and run it over each repo.

CarlQLange commented 4 months ago

Following up on the colour theme stuff: I've had a peruse of the Textual documentation and it definitely doesn't seem like what I'm asking for will be easy and would require some work on Textual directly. Bit of a strange decision on Textual's part imho.

CarlQLange commented 4 months ago

There is an issue though - some of the text colour is affected by my theme, so contrast is all over the place depending on my pywal theme.

https://github.com/AbanteAI/mentat/assets/859820/fdc1eb3d-939e-44cc-be54-d17ab28a306f

jakethekoenig commented 4 months ago

@CarlQLange there is the python_client which you could use to build a front end. We should probably document it a bit better. I just use it for testing right now which you can see a few places in the codebase. Thanks for sharing the video. That is strange.

PCSwingle commented 4 months ago

Following up on the colour theme stuff: I've had a peruse of the Textual documentation and it definitely doesn't seem like what I'm asking for will be easy and would require some work on Textual directly. Bit of a strange decision on Textual's part imho.

I agree; I was looking into it when I was trying to do exactly what you're asking for and I couldn't find any way to do it. Definitely annoying that textual doesn't have this built in.

There is an issue though - some of the text colour is affected by my theme, so contrast is all over the place depending on my pywal theme.

Unfortunately there's no way for us to do anything with user selected terminal colors.

Thanks for taking the time to submit your feedback! I definitely knew these would be issues coming in, although I still don't think there's any way to fix them, but I'll definitely still keep thinking about.

CarlQLange commented 4 months ago

Other textual issues/improvements:

It seems like mentat uses quite a lot of CPU now - when it's streaming, it maxes out one of my cores. Related, it seems to stream characters a lot slower (and use more CPU) when there is a large chat - not even that large, two or three hundred lines will do it.

I can't select text from the chat anymore to copy-paste elsewhere, which is a workflow I didn't realise I had. (Shift key, thank you!)

jakethekoenig commented 4 months ago

@CarlQLange you probably can copy paste: https://textual.textualize.io/FAQ/

PCSwingle commented 4 months ago

It seems like mentat uses quite a lot of CPU now - when it's streaming, it maxes out one of my cores. Related, it seems to stream characters a lot slower (and use more CPU) when there is a large chat - not even that large, two or three hundred lines will do it.

I'm actually working on fixing this; the reason this happens is because every time text is added I just add it to the main content widget and update it; of course, this is n^2 on the length of the content (because strings are immutable). Unfortunately, it's more complicated than just creating new widgets for every bit of text and adding them on. There should be a way to fix it though, and hopefully I can figure it out soon.

CarlQLange commented 4 months ago

@PCSwingle Yeah, I took some time yesterday to see if I could use Textual's built-in RichLog widget instead, but it expects every write to be a line, and implementing a line buffer was too much hassle for me. I also don't know how it would impact the formatting.