Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **The Git panel shows one thing at a time.** Changes and History are now two tabs, and a commit opens beside the log when you click it. The branches open from the branch's name in the panel's header: click one to check it out, type a new name to create it, and find the rest in its `⋯`.
- **A finished turn in the chat is your message, the answer and the files it changed.** The calls, thoughts and texts on the way fold under one line with the time they took, like Worked for 4m 6s; click it to read them in order. Each changed file is listed once under the answer, and a click opens all its edits.
- **A permission the agent asks for in the chat now waits over the message box.** It says what the agent wants to do and shows the whole command, or each file with its diff, with the answers always in view. Once you answer, only the call is left in the conversation, or a Denied line.
- **A command you run with `!` in the chat is one message with its output.** The command and what it printed stand together on your side of the conversation, with the time it took when it is a second or more, and in red when it fails. On Claude Code, Codex and opencode, the agents whose chat runs commands.
- **Review threads in Pulls show who answers whom.** Each thread is a card with its file and code, and its replies hang from a line under the comment they answer, in Conversation and between the lines in Files.
- **Long conversations no longer slow the window down.** Scrolling, typing and watching an answer come in cost about the
same in a chat of thousands of messages as in a new one, and several agents working at once take about a third of the
Expand Down
8 changes: 5 additions & 3 deletions native/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,11 @@ never makes the Latest pill show.
time takes it back.
- **Shell mode**: a line that starts with `!` turns the box's edge and fill toward `ToneWait`, the tone of a mode
that runs unchecked, and the box's foot shows "Shell mode" in that tone in the chips' place, which do not apply
to a command; Send stays at the right, wearing Enter's cap in place of its arrow. The command's call is a row of its own under
the person's message, hung by the connector, its output whole in mono under it, 20 lines and "Show N more
lines". Shift+Tab walks the mode chip's choices in the provider's order, never onto a `Danger` one.
to a command; Send stays at the right, wearing Enter's cap in place of its arrow. The command is the
person's, so it and all it printed are one balloon on their side (`chat_command.go`), never a call on the agent's:
the terminal glyph in the mark's place and the command in mono `TextSM` medium, the output under it in muted mono
`TextXS`, 20 lines and "Show N more lines". It shimmers while it runs; failed, the glyph and the output are
`Destructive`. How long it took stands before the message's time, "2s · 14:41", and not under a second. Shift+Tab walks the mode chip's choices in the provider's order, never onto a `Danger` one.
- **Background shells** (`chat_shells*.go`): while one runs, a chip in the box's foot says "2 shells · 1 monitor";
it and `/tasks` open a panel of them in the panel's place, "N running" beside the title, the running ones
under a Running group label and the ended ones under Ended. A row is a state glyph, the command in mono and its
Expand Down
171 changes: 171 additions & 0 deletions native/cmd/lich-native/chat_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package main

import (
"image"
"strings"
"time"

"gioui.org/font"
"gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/op/paint"

"github.com/lichdotdev/lich/api"
"github.com/lichdotdev/lich/native/backend"
"github.com/lichdotdev/lich/native/i18n"
"github.com/lichdotdev/lich/native/ui"
)

// chatCommandLines is how much of a shell command's output shows before the
// rest opens on a click.
const chatCommandLines = 20

// isCommand is whether it is a command the person ran after "!", in a chat
// whose provider runs it: a file attached makes the line a message.
func isCommand(it backend.ChatItem, runsShell bool) bool {
return runsShell && it.Kind == api.ItemUser && strings.HasPrefix(it.Text, chatShellMark) && len(it.Files) == 0
}

// chatCommand is the person's own shell command, in their message's place: the
// command, what it printed under it, and how long it took by its time.
func (u *window) chatCommand(gtx C, th *ui.Theme, p *chatPane, c *chatCopy, r chatRow) D {
text := commandText(r.item)
return c.hover(gtx, func(gtx C, over bool) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return chatBalloon(gtx, th, func(gtx C) D { return chatCommandBody(gtx, th.On(th.Accent), p, r, text) })
}),
ui.VGap(1),
layout.Rigid(func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
return u.chatStampRow(gtx, th, c, text, func(gtx C) D {
return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D { return chatCommandTook(gtx, th, r) }),
layout.Rigid(func(gtx C) D { return u.chatDatedStamp(gtx, th, p, r.item) }),
)
}, over, true)
})
}),
)
})
}

// commandText is the command the person's message it ran, without its mark.
func commandText(it backend.ChatItem) string {
return strings.TrimSpace(strings.TrimPrefix(it.Text, chatShellMark))
}

func chatCommandBody(gtx C, th *ui.Theme, p *chatPane, r chatRow, text string) D {
failed := r.call != nil && r.call.State == api.ToolFailed
ink := th.MutedForeground
if failed {
ink = th.Destructive
}
command := th.Text(ui.TextSM, expandTabs(text)).Mono().Weight(font.Medium).Wrapped()
if r.live {
// The band lights toward Foreground, so the command runs muted to show it.
command = command.Muted().Shimmer()
}
rows := []layout.FlexChild{layout.Rigid(func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
// The glyph stands on the first line of a command that wraps.
return layout.Inset{Top: ui.Space(0.75)}.Layout(gtx, func(gtx C) D { return icToolRun.Layout(gtx, ui.Space(3.5), ink) })
}),
ui.Gap(2),
layout.Rigid(command.Layout),
)
})}
out := commandOutput(r.call)
if out == "" {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, rows...)
}
more := p.fold("out:" + r.item.ID)
more.update(gtx)
lines := strings.Split(out, "\n")
hidden := len(lines) - chatCommandLines
if hidden > 0 && !more.open {
lines = lines[:chatCommandLines]
}
rows = append(rows, ui.VGap(2))
for _, l := range lines {
rows = append(rows, layout.Rigid(th.Text(ui.TextXS, expandTabs(l)).Mono().In(ink).Wrapped().Layout))
}
if hidden > 0 {
rows = append(rows, layout.Rigid(func(gtx C) D { return chatCommandMore(gtx, th, more, hidden) }))
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, rows...)
}

// commandOutput is what call printed, whole; a failure that printed nothing
// says it failed.
func commandOutput(call *backend.ChatToolCall) string {
if call == nil {
return ""
}
out := strings.Trim(call.Output, "\n")
if out == "" && call.State == api.ToolFailed {
return i18n.T("chat.view.toolFailed")
}
return out
}

// chatCommandMore opens the lines of a command's output past the head, or
// shuts them again.
func chatCommandMore(gtx C, th *ui.Theme, more *chatFold, hidden int) D {
text := i18n.T("chat.view.shellMore", i18n.Args{"count": hidden})
if more.open {
text = i18n.T("chat.view.shellLess")
}
return layout.Inset{Top: ui.Space(1.5)}.Layout(gtx, func(gtx C) D {
return more.click.Layout(gtx, func(gtx C) D {
fg := th.MutedForeground
if more.click.Hovered() {
fg = th.Foreground
}
return th.Text(ui.TextXS, text).In(fg).Layout(gtx)
})
})
}

// chatCommandTook is how long the command has run or ran, from the person's
// message: Claude Code tells of the call only once it ended. Nothing under a
// second, or where a time is missing.
func chatCommandTook(gtx C, th *ui.Theme, r chatRow) D {
if r.item.At <= 0 {
return D{}
}
start := time.UnixMilli(r.item.At)
var took time.Duration
switch {
case r.live:
chatTick(gtx, start)
took = gtx.Now.Sub(start)
case r.call != nil && r.call.Ended > 0:
took = time.UnixMilli(r.call.Ended).Sub(start)
}
if took < time.Second {
return D{}
}
return th.Text(ui.TextXS, chatElapsed(took)+" · ").Muted().Layout(gtx)
}

// chatBalloon is w on the person's balloon, against the column's right edge,
// its corner by that edge tighter than the others.
func chatBalloon(gtx C, th *ui.Theme, w layout.Widget) D {
maxW := int(float32(gtx.Constraints.Max.X) * chatUserShare)
return layout.E.Layout(gtx, func(gtx C) D {
gtx.Constraints.Min = image.Point{}
gtx.Constraints.Max.X = maxW
return layout.Background{}.Layout(gtx,
func(gtx C) D {
r, tip := gtx.Dp(ui.RadiusXL), gtx.Dp(ui.RadiusSM)
box := clip.RRect{Rect: image.Rectangle{Max: gtx.Constraints.Min}, NW: r, NE: r, SW: r, SE: tip}
paint.FillShape(gtx.Ops, th.Accent, box.Op(gtx.Ops))
return D{Size: gtx.Constraints.Min}
},
func(gtx C) D {
return layout.Inset{Top: ui.Space(3), Bottom: ui.Space(3), Left: ui.Space(4), Right: ui.Space(4)}.Layout(gtx, w)
})
})
}
11 changes: 6 additions & 5 deletions native/cmd/lich-native/chat_copy_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const (
speakerYou chatSpeaker = iota // the person's message, under its own heading
speakerAgent // the agent's text, calls and edits, under the agent's heading
speakerAside // a compaction: no heading, and the next row starts a section
speakerSame // the person's shell command: in the section it follows
)

// messageMenu lays out message w under its right-click menu: Copy takes text,
Expand Down Expand Up @@ -139,9 +138,6 @@ func chatRowMarkdown(r chatRow, checkout string) (string, chatSpeaker) {
case chatRowWork:
label, _ := callSummary(r.tools, noVeto)
return label, speakerAgent
case chatRowShell:
label, _ := callSummary([]backend.ChatItem{r.item}, noVeto)
return label, speakerSame
case chatRowEdit:
t := r.item.Tool
if t == nil || t.State == api.ToolFailed {
Expand All @@ -152,7 +148,12 @@ func chatRowMarkdown(r chatRow, checkout string) (string, chatSpeaker) {
case chatRowItem:
switch it := r.item; it.Kind {
case api.ItemUser:
return userMessageMarkdown(it), speakerYou
said := userMessageMarkdown(it)
if r.call != nil {
label, _ := callSummary([]backend.ChatItem{{Kind: api.ItemTool, Tool: r.call}}, noVeto)
said += "\n\n" + label
}
return said, speakerYou
case api.ItemAgent:
return it.Text, speakerAgent
case api.ItemCompaction:
Expand Down
Loading
Loading