Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Conversation

fiam
Copy link
Contributor

@fiam fiam commented Aug 26, 2025

  • Use bubbletea to implement a readline-like interface
  • Support arrow keys as well as the common readline keybindings for search
  • Implement /copy command for copying the latest response
  • Maintain backward compatibility with triple-quote formatting

Signed-off-by: Alberto Garcia Hierro [email protected]

@fiam
Copy link
Contributor Author

fiam commented Aug 26, 2025

Demo

Screen.Recording.2025-08-26.at.12.03.56.mov

@fiam fiam requested review from doringeman and xenoscopic August 26, 2025 11:05
Copy link
Collaborator

@doringeman doringeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!
There was an initiative to have the same TUI as Gordon, has anything been decided on that? CC @krissetto

- Use bubbletea to implement a readline-like interface
- Support arrow keys as well as the common readline keybindings for search
- Implement /copy command for copying the latest response
- Maintain backward compatibility with triple-quote formatting
- When piping stdin into the run command, read the stdin and use it as the prompt

Signed-off-by: Alberto Garcia Hierro <[email protected]>
@ericcurtin
Copy link
Contributor

I was having a go at implementing this yesterday but this is better! "Home" and "End" keys are worth implementing/testing also to navigate to the start and end of the string.

@ericcurtin
Copy link
Contributor

One not so great thing about clipboard, is it's dependant on xlib for linux:

$ make
Building model-cli...
go build -ldflags="-s -w" -o model-cli .
# golang.design/x/clipboard
clipboard_linux.c:14:10: fatal error: X11/Xlib.h: No such file or directory
   14 | #include <X11/Xlib.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:14: build] Error 1

xlib is kinda dead in favour of Wayland-based solutions.

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 26, 2025

Up and down should probably cycle through command history, could be in a follow on PR...

In other similar tools like RamaLama and Ollama Ctrl-c stops the LLM from responding but doesn't quit the application, this is useful in case the LLM keeps talking. But Ctrl-d does quit.

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 26, 2025

I wonder is the /copy functionality worth clipboard and all its dependencies (could be just a UI feature), goes above and beyond what a CLI interface normally does, one can highlight, copy and paste.

commands/run.go Outdated

text := textinput.New()
text.Placeholder = placeholder
text.Prompt = ">>> "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda liked the single > prior to this change, two extra characters in a terminal for real text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! I've changed it back to a single >.

@fiam fiam changed the title feat: enhance chat interface with comprehensive UI improvements feat: enhance chat interface Aug 26, 2025
Signed-off-by: Alberto Garcia Hierro <[email protected]>
@fiam
Copy link
Contributor Author

fiam commented Aug 26, 2025

Up and down should probably cycle through command history, could be in a follow on PR...

That's already implemented in this PR.

In other similar tools like RamaLama and Ollama Ctrl-c stops the LLM from responding but doesn't quit the application, this is useful in case the LLM keeps talking. But Ctrl-d does quit.

We could do that in a followup.

@fiam fiam marked this pull request as draft August 26, 2025 19:53
@fiam fiam marked this pull request as ready for review August 26, 2025 20:32
@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 26, 2025

Up and down should probably cycle through command history, could be in a follow on PR...

That's already implemented in this PR.

I tried and with this branch and it didn't seem to work, let me try again 😊

In other similar tools like RamaLama and Ollama Ctrl-c stops the LLM from responding but doesn't quit the application, this is useful in case the LLM keeps talking. But Ctrl-d does quit.

We could do that in a followup.

@ericcurtin
Copy link
Contributor

Home and End worked, I tried

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 26, 2025

The up and down arrows work on my machine with the latest commit, but some oddities noticed:

  • up arrow loops around, should probably just finish when you get to the end of the history, like bash/ollama/ramalama would
  • when we cycle through the history, cursor stays at the start of the prompt rather than the end

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 27, 2025

There's an odd bug now, type "Hello", press up twice "1Hello" appears:

$ ./model-cli run 354bf30d0aa3
Interactive chat mode started. Type '/bye' to exit.
> Hello                                                                                                                                                                          
Hello, how can I assist you today?
> 1Hello

@fiam
Copy link
Contributor Author

fiam commented Aug 27, 2025

There's an odd bug now, type "Hello", press up twice "1Hello" appears:

$ ./model-cli run 354bf30d0aa3
Interactive chat mode started. Type '/bye' to exit.
> Hello                                                                                                                                                                          
Hello, how can I assist you today?
> 1Hello

I cannot reproduce this. Could you please delete ~/.docker/model-cli/history.txt and try that with a clean history file?

@ericcurtin
Copy link
Contributor

ericcurtin commented Aug 27, 2025

There's an odd bug now, type "Hello", press up twice "1Hello" appears:

$ ./model-cli run 354bf30d0aa3
Interactive chat mode started. Type '/bye' to exit.
> Hello                                                                                                                                                                          
Hello, how can I assist you today?
> 1Hello

I cannot reproduce this. Could you please delete ~/.docker/model-cli/history.txt and try that with a clean history file?

That worked, maybe 1Hello was in my history... The other difference I see between this and bash/ollama/etc. is when you cycle back down again, normally the last down entry in blank. Here it's not.

Copy link
Contributor

@xenoscopic xenoscopic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this functionality overall, but I'd like to discuss it with @mia-docker first since this is a very UI/UX-heavy change. I'd also like to discuss how we plan to implement chat history in Docker Desktop with @qodesmith (who will be back next week) to make sure that we're aligned on storing those that data. @fiam are you okay with one of us following up on this PR next week once we discuss further? I think others on the team could contribute to it as well in case you're time-constrained at that point.

"github.com/docker/model-cli/desktop"
"github.com/docker/model-cli/pkg/history"
"github.com/spf13/cobra"
"golang.design/x/clipboard"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using golang.design/x/clipboard that relies on cgo, can we just use the github.com/atotto/clipboard dependency that we've already brought in via bubbletea? The API looks like it would provide the same functionality we need, and it already operates via shelling our rather than using cgo.

// New creates a new History instance and loads all previous history, if it exists.
func New(cli *command.DockerCli) (*History, error) {
dirname := filepath.Dir(cli.ConfigFile().Filename)
p := filepath.Join(dirname, "model-cli", "history.txt")
Copy link
Contributor

@xenoscopic xenoscopic Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should discuss where we want to store this, because we also have chat history as a near-term roadmap item for the GUI, and I think it would be nice if we could share chat output between them. I get that this is more of a readline()-style history, but I think we should discuss with @mia-docker and @qodesmith about how we want the two to interact.

@fiam fiam marked this pull request as draft August 29, 2025 08:31
@fiam
Copy link
Contributor Author

fiam commented Aug 29, 2025

Convering to draft while we discuss this approach, to prevent an accidental merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants