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 @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- **The Pulls screen is redrawn, and its list is sorted by what each pull request needs.** Open ones are grouped into Ready to merge, Needs work, In review and Drafts, in place of the All, Ready, Drafts and Failing filters and the Approved state. Inside a pull request, its facts stand beside the description, and Copy link and Copy Markdown are in the `⋯` menu.
- **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.
- **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
5 changes: 3 additions & 2 deletions docs/ceilings.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ work when nobody knows it and that the call site never shows. The mechanism and
that leaves a file's added and removed counts as they were (a line rewritten in a file already changed by as many
lines), and a binary file that stays binary. A turn that moved HEAD (the agent committed) has no count, since the
two readings are against different commits; so does a checkout that is not a repository, or whose reading takes
more than five seconds. The window then shows the turn's end without a count. The count is not kept: a chat
read back from the provider's history shows its turns as done with none. A session opened in a subdirectory
more than five seconds. The window draws the files the turn's own edits changed and not this
count, which the turn's end event carries. The count is not kept: a chat read back from the provider's history
has none. A session opened in a subdirectory
counts only that subdirectory. Every provider with a chat reads it the same way.
- **The files a shell command or any call with no diff of its own changed are the same numstat reading, taken when
each call ends** (`internal/chat/files.go`, `ChatToolCall.Files`): every call that ends reads the checkout once and
Expand Down
87 changes: 46 additions & 41 deletions native/DESIGN.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion native/cmd/lich-native/chat_calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func TestACallAloneShowsItsTargetAndAGroupSaysWhatItDid(t *testing.T) {
toolItem("k3", "Read", "smoke/shot.png", api.ToolDone),
toolItem("k4", "Bash", "gh release create", api.ToolFailed),
})
u.chats.pane("s1").fold("done:1").open = true
r.settle(t)
writeShot(t, r, "calls-settled.png")
for _, s := range []string{"Ran", "git fetch -q origin", "Ran 2 commands, read 1 file", "· 1 failed"} {
for _, s := range []string{"Ran", "git fetch -q origin", "Ran 2 commands, read 1 file", "1 failed"} {
if !r.shows(s) {
t.Errorf("the chat lacks %q:\n%s", s, r.drawn())
}
Expand Down
8 changes: 0 additions & 8 deletions native/cmd/lich-native/chat_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ func compactRunning(items []backend.ChatItem) bool {
})
}

// compactTurn is whether turn was the person's compaction: its marker closes it,
// with no line of its own.
func compactTurn(items []backend.ChatItem, turn int) bool {
return slices.ContainsFunc(items, func(it backend.ChatItem) bool {
return it.Turn == turn && it.Compaction != nil && !it.Compaction.Auto && it.Compaction.State != api.CompactionCancelled
})
}

// drawnCompaction is whether a compaction item has a marker: one running is
// the live line's, and a cancelled one did nothing.
func drawnCompaction(it backend.ChatItem) bool {
Expand Down
8 changes: 4 additions & 4 deletions native/cmd/lich-native/chat_compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func TestACompactionIsTheLiveLineThenTheMarkerThatClosesItsTurn(t *testing.T) {
t.Errorf("a compaction running draws %q, want %q", got, want)
}
done := typedCompact(api.ChatCompaction{State: api.CompactionDone, Before: 182000, After: 9000})
if got, want := rowKinds(chatRows(done, claudeKind, false, now)), []string{"user", "agent", "user", "compaction"}; !slices.Equal(got, want) {
if got, want := rowKinds(endedRows(done, false, "end_turn")), []string{"user", "agent", "user", "compaction"}; !slices.Equal(got, want) {
t.Errorf("a compaction done draws %q, want %q", got, want)
}
failed := typedCompact(api.ChatCompaction{State: api.CompactionFailed, Error: "Not enough messages to compact."})
if got, want := rowKinds(chatRows(failed, claudeKind, false, now)), []string{"user", "agent", "user", "compaction"}; !slices.Equal(got, want) {
if got, want := rowKinds(endedRows(failed, false, stopError)), []string{"user", "agent", "user", "compaction"}; !slices.Equal(got, want) {
t.Errorf("a compaction failed draws %q, want %q", got, want)
}
cancelled := typedCompact(api.ChatCompaction{State: api.CompactionCancelled})
if got, want := rowKinds(chatRows(cancelled, claudeKind, false, now)), []string{"user", "agent", "user", "done"}; !slices.Equal(got, want) {
if got, want := rowKinds(endedRows(cancelled, false, stopCancelled)), []string{"user", "agent", "user", "done"}; !slices.Equal(got, want) {
t.Errorf("a compaction cancelled draws %q, want %q", got, want)
}
}
Expand All @@ -87,7 +87,7 @@ func TestAnAutomaticCompactionStandsWhereItHappened(t *testing.T) {
if got := rowKinds(chatRows(items, claudeKind, true, time.UnixMilli(9000))); !slices.Equal(got, []string{"user", "agent", "compaction", "agent", "live"}) {
t.Errorf("after it the turn draws %q", got)
}
if got := rowKinds(chatRows(items, claudeKind, false, time.UnixMilli(9000))); !slices.Equal(got, []string{"user", "agent", "compaction", "agent", "done"}) {
if got := rowKinds(endedRows(items, false, "end_turn")); !slices.Equal(got, []string{"user", "agent", "compaction", "agent"}) {
t.Errorf("once over the turn draws %q", got)
}
}
Expand Down
18 changes: 11 additions & 7 deletions native/cmd/lich-native/chat_copy_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"slices"
"strings"
"time"

"gioui.org/io/clipboard"
"gioui.org/io/key"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (u *window) messageMenu(gtx C, th *ui.Theme, p *chatPane, sv sessionView, c
}
e := []ui.MenuEntry{
{Label: i18n.T("chat.copy.menu.copy"), OnClick: func() { copying = text }},
{Label: i18n.T("chat.copy.menu.upToHere"), OnClick: func() { copying = u.conversationUpTo(p, sv, rowKey) }},
{Label: i18n.T("chat.copy.menu.upToHere"), OnClick: func() { copying = u.conversationUpTo(sv, rowKey) }},
}
if c.quoted != "" {
quoted := c.quoted
Expand Down Expand Up @@ -82,17 +83,20 @@ func (u *window) messageMenu(gtx C, th *ui.Theme, p *chatPane, sv sessionView, c
}

// conversationUpTo is sv's conversation as Markdown, from its start to row
// key and nothing after it; "" when the row is no longer in it.
func (u *window) conversationUpTo(p *chatPane, sv sessionView, key string) string {
i := slices.IndexFunc(p.drawn, func(r chatRow) bool { return chatRowKey(r) == key })
// key and nothing after it, in the order it went, a finished turn's folded
// work included; "" when the row is no longer in it.
func (u *window) conversationUpTo(sv sessionView, key string) string {
items, running := u.model.chat.of(sv.ID), u.model.chat.isRunning(sv.ID)
rows := chatRows(items, sv.Kind, running, time.Now())
i := slices.IndexFunc(rows, func(r chatRow) bool { return chatRowKey(r) == key })
if i < 0 {
return ""
}
live := -1
if items := u.model.chat.of(sv.ID); u.model.chat.isRunning(sv.ID) && len(items) > 0 {
if running && len(items) > 0 {
live = items[len(items)-1].Turn
}
return chatMarkdown(p.drawn[:i+1], u.providerName(sv), sv.path, live)
return chatMarkdown(rows[:i+1], u.providerName(sv), sv.path, live)
}

// chatMarkdown is rows as Markdown: each message under a heading, "You" or
Expand Down Expand Up @@ -128,7 +132,7 @@ func chatMarkdown(rows []chatRow, provider, checkout string, live int) string {

// chatRowMarkdown is row r's Markdown and whose section it goes in; "" for a
// row the copy leaves out: a thought, a notice, a question, a day or a turn's
// live or closing line.
// live line.
func chatRowMarkdown(r chatRow, checkout string) (string, chatSpeaker) {
noVeto := func(backend.ChatItem) bool { return false }
switch r.kind {
Expand Down
88 changes: 26 additions & 62 deletions native/cmd/lich-native/chat_done.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package main

import (
"gioui.org/layout"
"gioui.org/op/paint"
"github.com/lichdotdev/lich/native/ui/icons"
"image/color"
"time"

"github.com/lichdotdev/lich/native/i18n"
"github.com/lichdotdev/lich/native/ui"
Expand All @@ -16,74 +14,40 @@ const (
stopError = "error"
)

// chatDoneWord is how a turn's line names its end, by the stop reason the
// event carried: cancelled is Stopped and error is Failed, and any other stop
// a provider reports (a refusal, a token limit) still ended the turn.
// chatDoneGlyph is how a turn ended, in its tone: a check, the stop square
// muted, or the failed cross.
func chatDoneGlyph(th *ui.Theme, reason string) (*icons.Icon, color.NRGBA) {
// chatDoneLabel is how a finished turn's work reads, by the stop reason the
// event carried, with the time it took when that is known: cancelled is
// Stopped and error is Failed, and any other stop a provider reports (a
// refusal, a token limit) still ended the turn.
func chatDoneLabel(reason string, took time.Duration) string {
word, timed := "chat.done.worked", "chat.done.workedFor"
switch reason {
case stopCancelled:
return icChatStop, th.MutedForeground
word, timed = "chat.done.stopped", "chat.done.stoppedAfter"
case stopError:
return icToolsFailed, th.Destructive
word, timed = "chat.done.failed", "chat.done.failedAfter"
}
return icCheck, th.TonePass
}

func chatDoneWord(reason string) string {
switch reason {
case stopCancelled:
return i18n.T("chat.done.stopped")
case stopError:
return i18n.T("chat.done.failed")
if took < time.Second {
return i18n.T(word)
}
return i18n.T("chat.done.done")
return i18n.T(timed, i18n.Args{"time": chatElapsed(took)})
}

// chatDone is the line that closes a finished turn: the glyph that says how it
// ended, its word for whoever reads the window without seeing it, then, muted, its calls and how long it took, and "no changes" when
// the checkout says the turn changed nothing; what it did change is on its
// edits' rows (chatEdit). A turn with no count to give (the checkout could not
// be read, or the turn was read back with the history) shows its glyph alone.
// The line is drawn at opacity shown: 1 at rest, less while the live line
// turns into this one.
func (u *window) chatDone(gtx C, th *ui.Theme, sv sessionView, r chatRow, shown float32) D {
end, _ := u.model.chat.endOf(sv.ID, r.turn)
if r.refused {
end.StopReason = stopError
}
ic, ink := chatDoneGlyph(th, end.StopReason)
word := func(gtx C) D {
return labeledGlyph(gtx, chatDoneWord(end.StopReason), func(gtx C) D { return ic.Layout(gtx, ui.Space(4), ink) })
}
faded := func(w layout.Widget) layout.FlexChild {
if shown == 1 {
return layout.Rigid(w)
}
return layout.Rigid(func(gtx C) D {
defer paint.PushOpacity(gtx.Ops, shown).Pop()
return w(gtx)
})
}
first := true
muted := func(s string) []layout.FlexChild {
sep := []layout.FlexChild{ui.Gap(2)}
if !first {
sep = append(sep, faded(th.Text(ui.TextSM, "·").Muted().Layout), ui.Gap(2))
// chatDone is the line a finished turn's work is folded under: a click shows
// the calls, thoughts and texts that led to the answer, in the order they
// went. A turn stopped or failed has it with nothing to fold too.
func (u *window) chatDone(gtx C, th *ui.Theme, p *chatPane, r chatRow) D {
label := func(gtx C, fg color.NRGBA) D {
if r.reason == stopError {
fg = th.Destructive
}
first = false
return append(sep, faded(th.Text(ui.TextSM, s).Muted().Layout))
return th.Text(ui.TextSM, chatDoneLabel(r.reason, r.took)).In(fg).Layout(gtx)
}
line := []layout.FlexChild{faded(word)}
if len(r.tools) > 0 {
line = append(line, muted(i18n.T("chat.view.toolCalls", i18n.Args{"count": len(r.tools)})+" · "+chatTook(r.took))...)
if !r.folds {
return label(gtx, th.MutedForeground)
}
if c := end.Changes; c != nil && c.Files == 0 {
line = append(line, muted(i18n.T("chat.done.noChanges"))...)
f := p.fold(r.run)
if f.click.Clicked(gtx) {
p.turnFold(gtx, f)
}
// a line of text tall even when the glyph stands alone, so the live line
// turns into it in its slot
gtx.Constraints.Min.Y = gtx.Sp(chatRowLine)
return layout.W.Layout(gtx, func(gtx C) D { return layout.Flex{Alignment: layout.Middle}.Layout(gtx, line...) })
return chatFoldLine(gtx, th, f, nil, label)
}
Loading
Loading