From 9571ad4158f19ea5363a7011fe524a40fdd93053 Mon Sep 17 00:00:00 2001 From: omartelo Date: Fri, 4 Dec 2026 13:47:59 -0300 Subject: [PATCH] feat(native): fold a finished chat turn to its answer and its files A long turn weighed every text on the way the same as its conclusion. When a turn ends, its calls, thoughts and interim texts now fold under one line over the answer, and the files it changed stand once each under it. Rows share one left edge, and the closing line and the millisecond times are gone. --- CHANGELOG.md | 1 + docs/ceilings.md | 5 +- native/DESIGN.md | 87 +++--- native/cmd/lich-native/chat_calls_test.go | 3 +- native/cmd/lich-native/chat_compaction.go | 8 - .../cmd/lich-native/chat_compaction_test.go | 8 +- native/cmd/lich-native/chat_copy_menu.go | 18 +- native/cmd/lich-native/chat_done.go | 88 ++---- native/cmd/lich-native/chat_done_test.go | 197 ++---------- native/cmd/lich-native/chat_edit.go | 188 ++++++----- native/cmd/lich-native/chat_edit_diff.go | 2 +- native/cmd/lich-native/chat_edit_test.go | 36 +-- native/cmd/lich-native/chat_envelope_draw.go | 3 +- native/cmd/lich-native/chat_group_test.go | 10 +- native/cmd/lich-native/chat_items.go | 185 +++++------ native/cmd/lich-native/chat_lich_test.go | 2 + native/cmd/lich-native/chat_life_test.go | 39 +-- native/cmd/lich-native/chat_motion.go | 120 ++++--- native/cmd/lich-native/chat_motion_test.go | 40 +-- native/cmd/lich-native/chat_question_test.go | 4 +- native/cmd/lich-native/chat_row_cache.go | 20 +- native/cmd/lich-native/chat_row_cache_test.go | 4 +- native/cmd/lich-native/chat_rows.go | 84 +++-- native/cmd/lich-native/chat_shell_test.go | 1 + native/cmd/lich-native/chat_turn_fold.go | 217 +++++++++++++ native/cmd/lich-native/chat_turn_fold_test.go | 292 ++++++++++++++++++ native/cmd/lich-native/chat_veto_test.go | 6 +- native/cmd/lich-native/chat_view.go | 77 +++-- native/cmd/lich-native/chat_view_test.go | 1 + native/cmd/lich-native/login_offer_test.go | 4 +- .../cmd/lich-native/settings_themes_cover.go | 3 +- .../lich-native/settings_themes_preview.go | 26 +- native/i18n/locales/en/chat.json | 19 +- native/i18n/locales/en/session.json | 1 - native/i18n/locales/es/chat.json | 19 +- native/i18n/locales/es/session.json | 1 - native/i18n/locales/ja/chat.json | 16 +- native/i18n/locales/ja/session.json | 1 - native/i18n/locales/ko/chat.json | 16 +- native/i18n/locales/ko/session.json | 1 - native/i18n/locales/pt-br/chat.json | 19 +- native/i18n/locales/pt-br/session.json | 1 - native/i18n/locales/ru/chat.json | 25 +- native/i18n/locales/ru/session.json | 1 - native/i18n/locales/zh-cn/chat.json | 16 +- native/i18n/locales/zh-cn/session.json | 1 - 46 files changed, 1138 insertions(+), 778 deletions(-) create mode 100644 native/cmd/lich-native/chat_turn_fold.go create mode 100644 native/cmd/lich-native/chat_turn_fold_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 2395e5a69..f752865ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/ceilings.md b/docs/ceilings.md index 3e689940b..264d66e76 100644 --- a/docs/ceilings.md +++ b/docs/ceilings.md @@ -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 diff --git a/native/DESIGN.md b/native/DESIGN.md index b54fe61fd..24baafa13 100644 --- a/native/DESIGN.md +++ b/native/DESIGN.md @@ -37,7 +37,7 @@ Elements are defined by space, hover and islands, not by enclosure. island's edge and an input's edge, since a field needs one to read as editable; the code editor's gutter rule is the one line inside a view (see The editor). - **Group labels and heads count in the states' tones.** A group's label is `Text2XS`, uppercase, semibold and - muted (SERVICES, EDITED, a panel's RUNNING); what it counts follows it, each part in its state's tone and + muted (SERVICES, a panel's RUNNING); what it counts follows it, each part in its state's tone and " · " between them (the services' "2 running · 1 failed", the bell's "1 waiting · 3 done", a zoomed pane's "· 1 waiting"), muted when no part carries a state. - **State is the glyph.** A check, a dot, a switch, a spinner or a lock says it; a word joins the glyph only @@ -494,7 +494,8 @@ The answer starts max(32, 1.8×B) under the person's message and its time (`chat `chatAnswerGapLines`), and the next turn max(48, 2.8×B) under the last row (`chatTurnGapMin`, `chatTurnGapLines`), in the person's message or the day line over it, B the prose size: at the default size 32 and 48, and both grow with the text. Each gap belongs to one row, so two never stack. Rounds are told apart by -that space alone, never by a rule. +that space alone, never by a rule. Every row starts on the column's left edge, with the text: a fold's chevron comes +after its words, and a row that leads with a glyph puts the glyph there. A conversation shorter than the view rests on the composer, its newest message at the bottom and the older ones above, and a new one comes in under them and pushes them up, as in a messaging app; one taller than the view stays pinned to its end while items arrive, until the person scrolls up. The list ends `Space(6)` @@ -520,8 +521,29 @@ never makes the Latest pill show. is underlined in its color and takes the hand, and a click with it opens a file in the stage editor (`followCodeRef`) and a folder in the dock's Code tab, unfolded down to it (`chat_paths.go`). A path it does not hold stays text. Anything else in code is plain. An answer has no header: who wrote it is the - foot's (see A message's time); the provider's avatar marks no row of the chat: no answer, call, notice of lich's or closing line. Two kinds of row are excepted: the harness's own notes about its background work (see A harness's background note) and what another session sent this one (see A message from another session). A thought is a muted fold, closed, with the + foot's (see A message's time); the provider's avatar marks no row of the chat: no answer, call or notice of lich's. Two kinds of row are excepted: the harness's own notes about its background work (see A harness's background note) and what another session sent this one (see A message from another session). A thought is a muted fold, closed, with the sparkles before its label. +- **A finished turn** (`chat_turn_fold.go`) is what the person said, its answer and the files it changed: the way + there folds, when the turn ends, under one muted `TextSM` line over the answer, "Worked for 4m 6s", from their + message to the last thing the turn did, "Worked" where nobody reported times or under a second. In a long turn + the texts on the way ("now the tests") weighed as much as the conclusion, which had to be hunted for. The + answer is the last run of the agent's texts; what folds is every other text, thought, run of calls, failed + edit and answered permission. Never folded: a message or a steer, an answer to a question, a plan, a `!` + command, a compaction and a notice; what stands between two of the first five is a stretch with its own line + and answer. A turn with nothing to fold has no line, unless it was stopped, "Stopped after 41s", or failed, + "Failed after 12s" in `Destructive`, which say so with nothing under them too. There is no closing line and no + check: the work folding and the live line leaving are the end. A click on the line shows the rows in the + order they went, the texts in `MutedForeground` so the answer still leads, `chatPartGap` (20px) over the + answer; the line stays where it was clicked and the rows open under it, though the list was at its end. Every + finished turn folds, a history read back too; a turn that ends while the person is scrolled up in it stays + open, so nothing folds under their eyes. The rows go and come as any row does, up to `chatMoved` (40) at once; + more land dry. +- **The files a finished turn changed** stand once each under its answer, with all the edits the turn made to + them, and no longer where each edit ran: "Changed 4 files" in muted `TextSM` with the summed `+a -d` at the + right, whose click opens Review as the footer's changes item does, then an edit's line per file (see An edit), + whose diff is the file's edits one after the other. One file has no head. Past 6, the first 5 show + (`chatFilesShown`) over a muted `TextXS` "Show 8 more files", which turns into "Show less": a long list would + push the answer out of view. - **A turn's tool calls** fold by run: the calls between two of the agent's texts (or the person's message and the first text) fold into one muted line where the first of them came. One line for the whole turn stood where the turn began while the agent went on working minutes below it; a run's line stands where its calls ran. A @@ -529,11 +551,10 @@ never makes the Latest pill show. Codex and Claude Code desktop) leaves the agent's mark off its calls. A run of one call is no fold: it is that call's row, its target in view, the complaint most heard of the apps that fold it. Several read as what they did, a clause per kind in one sentence ("Ran 4 commands, read 2 files", `chat_calls.go`: edited, ran, read, - searched, fetched, "made N lich calls", then "used N other tools"), then, muted, how long the run took, from its first call to its - last call's end, and "· 1 failed" in `Destructive` when one did (a call lich opened as a card is not a - failure); the turn's total is on its closing line. While a call runs the line is that call instead, its + searched, fetched, "made N lich calls", then "used N other tools"), then "1 failed" in `Destructive` when one did (a call lich opened as a card is + not a failure); the turn's line has the time. While a call runs the line is that call instead, its running verb and target shimmering ("Running go test ./…", cut at 60 characters), the run's time counting, - and "· 3 tool calls" muted. Open, each call is a 28px row under the line, indented past its chevron, with no + and "· 3 tool calls" muted. Open, each call is a 28px row under the line, on its edge, with no connector. The line starts shut, whether the turn is in flight or ended, and only a click opens it, which holds as the person left it. Open, it shows only its last 5 calls (`chatCallsShown`): a turn can run fifty, which would push the view past its height. The rest wait behind a first row, muted `TextXS` @@ -552,24 +573,11 @@ never makes the Latest pill show. target is an open session (`chat_lich.go`: send, close, rename, control, file) draws the same badge in place of its target, its name in mono `Foreground` as the other targets read and its dot and arrow muted, pulled left by its own inset so the name starts on the targets' column; the time stays. A failed one keeps its plain - row, which says why. A time that stands still reads in milliseconds under a second ("476ms"), the line's - own time too; a call whose end nobody reported (most histories) shows no time. A call that changed a file is + row, which says why. A call that took under a second shows no time, nor does one whose end nobody reported + (most histories). A call that changed a file is not in the fold: it is an edit, a line of its own (see An edit). The group never opens on its own. Only the turn in flight is alive: a call an ended turn left running (interrupted) stops with it, its time up to the turn's end, or none where nobody saw it. -- **A turn's closing line** stands once, after the last item of the conversation's last turn, when that turn - has ended: a glyph that says how it ended, with no avatar, then, when it ran any, muted "34 tool calls · 6m 4s", - all its runs' calls and how long the turn took, then muted "· no changes" when the turn changed nothing. The - glyph is a check in `TonePass` for a turn that finished, the stop square muted for one the person cancelled, and - the failed cross in `Destructive` for one that ended in an error; "Done", "Stopped" and "Failed" are its - semantic label (`chatDoneGlyph`). The line keeps a line of text's height with the glyph alone, so the live line - turns into it in its slot. No files, no lines and no rule: the turn's edits already say them, in their group - (see An edit), whose head opens Review. The line leaves when the person's next message begins a turn, and - none stands while a turn runs, where the live line is; older turns have none, in a history read back too. A - turn whose checkout lich could not read (not a repository, or a commit made during the turn) shows its glyph - alone, and so does one read back with the history, whose end nobody reported to the window: the line never - invents a count. The theme preview in - Settings › Appearance closes its turn the same way (`previewDone`). - **A compaction** (`chat_compaction.go`). While the turn compacts, the live line says "Compacting the conversation" in place of the verb, shimmering with its clock, and the `fold-vertical` glyph stands in the flame's place, squeezing to 0.55 of its height every 1.4s; under the words, indented to them, a `WaveBar` of @@ -578,7 +586,7 @@ never makes the Latest pill show. and set apart by the turn's space: the glyph, the title in `TextSM` medium `Foreground` ("Conversation compacted", "Conversation compacted automatically" for one the provider ran on its own), then muted "· 182K → 9K tokens" when both counts are known. A failure reads "Couldn't compact" in `Destructive` with the provider's reason muted. The - person's /compact ends its turn in the marker, with no closing line and none of the command's output; an + person's /compact ends its turn in the marker, with no line of its own and none of the command's output; an automatic one leaves its turn to carry on and close as any other. What the compaction's hooks printed is the marker's tooltip, and its summary opens under it on a click, a chevron at the marker's end saying so. A cancelled compaction draws nothing. @@ -594,10 +602,8 @@ never makes the Latest pill show. ease-in), so its text and the flame never draw at a fractional size; the conversation read when the pane opens, or after it, or drawn again after the TUI, does not play as arrivals. A list at its end stays at its end while rows grow in. -- **A row that becomes another changes in its slot** (`chat_motion.go`). A turn ending turns the live line into - the closing line where it stood: the flame, verb and clock fade out in 120ms ease-in, then the glyph - and count fade in by 280ms, ease-out; the slot eases to the closing line's height in 160ms, since the two differ by a few pixels. Neither row - plays its own entry or exit. A question answered leaves the composer at once, and its answer enters the +- **What changes, changes in its place** (`chat_motion.go`). A turn ending folds its work and its live line away as + rows leave, while its line and its files come in (see A finished turn). A question answered leaves the composer at once, and its answer enters the conversation as a new row does. A fold, a thought's text, a group's calls or an edit's diff, opens and shuts with `ui.Collapse`, 200ms, its first draw landing where it stands, and a group opens and shuts that way at the edges of its run of calls; a call that comes into an open group enters as a row does. Sending a message while the list is scrolled up, queued or steered @@ -625,18 +631,15 @@ never makes the Latest pill show. is each file a call with no diff of its own changed (a shell command's `sed`, a script), right after that call (`ChatToolCall.Files`, `fileRows`). Edit lines that follow one another with nothing between them are one group standing on the conversation, with no ground, no hairline and no box per file, because the turn's - evidence must never weigh more than the answer around it. A group of two files or more opens with a head row, - its group label "EDITED", the file count muted beside it ("3 files", distinct paths) and the summed `+a -d` in - the tones at its right, leaving out running and failed edits; a click on the head opens Review as the footer's - changes item does. A lone edit is the same line with no head. A line is the + evidence must never weigh more than the answer around it. It has no head while the turn runs; once the turn ends its edits + leave for the files under its answer, whose lines are these (see The files a finished turn changed). A line is the file's icon (`th.FileIcon`), its name in mono `TextSM` medium, then its folder in mono `TextXS` muted without - its slash, the part cut first, with a `Space(4)` icon in a `Space(3)`×`Space(2)` inset, the path relative to - the checkout, then `+a -d` (`th.DiffStat`) at the right, room for the hover chevron always kept so the counts - never move. The name leads because it is what the eye looks for. No tool name, glyph or time: the line is + its slash, the part cut first, with a `Space(4)` icon, `Space(1.5)` over and under, the path relative to + the checkout, then `+a -d` (`th.DiffStat`) at the column's right edge. The name leads because it is what the eye looks for. No tool name, glyph or time: the line is the file. While the call runs its path shimmers and no counts show; failed, the failed glyph and the first line of what the tool answered, why it failed, stand in their place in `Destructive` mono, cut at half the line - (`chatEditWhyShare`) so the name stays in view. Hover fills it with the kit's hover; a chevron at its right - shows on hover and while open. A click unfolds the diff under it, set apart by space, and a second folds it; + (`chatEditWhyShare`) so the name stays in view. Hover fills it with the kit's hover, `Space(2)` past the column each side so the line itself + keeps its edges; a chevron after its folder shows on hover and while open. A click unfolds the diff under it, set apart by space, and a second folds it; a Ctrl+click opens the file in the editor instead. The open diff is the Review panel's code view (`chat_edit_diff.go`, `ui/diffview`), unified, in the editors' code font on `Background`: line numbers, the code's colors, the words that changed, a bare separator between hunks, never git's header lines. It shows @@ -676,7 +679,7 @@ never makes the Latest pill show. conversation. Answered, it is the person's own message at the column's right, the bubble of what they type: a `TextSM` line per ask, the header muted and the answer, their own words in quotes; declined, a muted "Not answered" at the right. -- **A notice** is a muted line; one saying the provider refused the turn for want of a login has an outline `SizeSM` Log in under it, the same button a profile's row offers, which opens Settings on the session's project at its provider and logs in the profile the session runs in (`chat_login.go`); a provider with no profiles has none. Its turn closes on the failure mark whether or not the window heard the turn end (`chatRow.refused`). The turn in flight ends the column with a pixel flame (`chat_flame.go`: an 11x14 sprite of 1.5dp pixels, drawn as rectangles, in 16 frames of 100ms; only its 11 bottom rows take the line, the tips and sparks burning over the line above; a window without focus looks in at `StillFrame` instead) and a verb of the turn, shimmering like "Thinking" with the time it has run beside it; the verb is picked from the language's own list (`chat.view.verbs`, `|`-separated, each language writes its own length) by the session and the turn, so it holds for the whole turn; left out +- **A notice** is a muted line; one saying the provider refused the turn for want of a login has an outline `SizeSM` Log in under it, the same button a profile's row offers, which opens Settings on the session's project at its provider and logs in the profile the session runs in (`chat_login.go`); a provider with no profiles has none. Its turn reads Failed whether or not the window heard it end. The turn in flight ends the column with a pixel flame (`chat_flame.go`: an 11x14 sprite of 1.5dp pixels, drawn as rectangles, in 16 frames of 100ms; only its 11 bottom rows take the line, the tips and sparks burning over the line above; a window without focus looks in at `StillFrame` instead) and a verb of the turn, shimmering like "Thinking" with the time it has run beside it; the verb is picked from the language's own list (`chat.view.verbs`, `|`-separated, each language writes its own length) by the session and the turn, so it holds for the whole turn; left out while a permission or a question waits: its box already says so. The flame's colors are tokens, never a fixed hue: the core is `Primary` halfway to the lighter of `Foreground` and `Background`, the body `Primary`, the edge @@ -916,11 +919,13 @@ never makes the Latest pill show. without (`chatCopySlot`), so it pushes nothing; the button is a little larger than the line and reaches past it. Texts the agent writes one after another in a turn, nothing between them, read as one answer: only the last keeps the time and copy line, and its copy takes the whole run, so the texts stand a row gap apart, not a line apart. + The texts on the way to the answer, and every text while the turn runs, have neither: the line, empty at rest, + set them twice as far from the row under them as from the one above. Their right click still copies. A right click on a message, the person's or an answer, opens its menu (`chat_copy_menu.go`, opened through `MenuState.OpenFrom` from the message's hover area, since a `ContextMenu` trigger clips its content and would cut the floating Quote): Copy, what the hover button takes; Copy conversation up to here; and, under a separator, - Quote while text in that message is selected. The conversation is Markdown built from the rows the chat - draws, never past the clicked message: each message under "## You" or "## ()", a run of + Quote while text in that message is selected. The conversation is Markdown built from its rows in the + order they went, folded or not, never past the clicked message: each message under "## You" or "## ()", a run of calls as its fold's sentence, an edit as its path and lines, files by name with a line saying their bytes were not copied, a compaction as one line, and "(incomplete)" closing a turn still running. Thoughts, notices, questions and permissions stay out. Its words are the interface language's: lich types none of it @@ -1488,12 +1493,12 @@ repository URL, a file, the template). - **A cover is drawn, never a picture.** The catalog carries every theme in full, so a card's 16:10 cover is a small lich window in the pack's first dark theme: a sidebar, a person's message on the theme's accent, a code - block in its syntax colors, the Done line in its tones and a strip of its terminal colors + block in its syntax colors, a check and two counts in its tones and a strip of its terminal colors (`settings_themes_cover.go`). Under it, the name with a check at its right, bright for In use and muted for Installed, the word its semantic label, the publisher in mono, a dot per variant in its background, the count of variants and their schemes, and the stars. - **The detail** is the pack's whole window in the chosen variant (`settings_themes_preview.go`): the tabs, a - sidebar of sessions, a chat with its code block, the closing line, a terminal with all sixteen colors and the + sidebar of sessions, a chat with its turn's line and its code block, a terminal with all sixteen colors and the composer. The variants are a segmented control over the description; the one Primary is Install, or Use once installed. A pack written for a newer lich keeps Install disabled, the version it needs in the tooltip. - **Try** paints the window in the variant and stores nothing: a bar on `Popover` at the window's foot, on diff --git a/native/cmd/lich-native/chat_calls_test.go b/native/cmd/lich-native/chat_calls_test.go index e257d2572..21dfc40bd 100644 --- a/native/cmd/lich-native/chat_calls_test.go +++ b/native/cmd/lich-native/chat_calls_test.go @@ -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()) } diff --git a/native/cmd/lich-native/chat_compaction.go b/native/cmd/lich-native/chat_compaction.go index a7d0db541..b6854b252 100644 --- a/native/cmd/lich-native/chat_compaction.go +++ b/native/cmd/lich-native/chat_compaction.go @@ -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 { diff --git a/native/cmd/lich-native/chat_compaction_test.go b/native/cmd/lich-native/chat_compaction_test.go index 876ca6364..e43703c9d 100644 --- a/native/cmd/lich-native/chat_compaction_test.go +++ b/native/cmd/lich-native/chat_compaction_test.go @@ -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) } } @@ -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) } } diff --git a/native/cmd/lich-native/chat_copy_menu.go b/native/cmd/lich-native/chat_copy_menu.go index b24d3de49..3486a954d 100644 --- a/native/cmd/lich-native/chat_copy_menu.go +++ b/native/cmd/lich-native/chat_copy_menu.go @@ -5,6 +5,7 @@ import ( "path/filepath" "slices" "strings" + "time" "gioui.org/io/clipboard" "gioui.org/io/key" @@ -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 @@ -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 @@ -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 { diff --git a/native/cmd/lich-native/chat_done.go b/native/cmd/lich-native/chat_done.go index 6aa4a97c6..e5a675cb8 100644 --- a/native/cmd/lich-native/chat_done.go +++ b/native/cmd/lich-native/chat_done.go @@ -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" @@ -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) } diff --git a/native/cmd/lich-native/chat_done_test.go b/native/cmd/lich-native/chat_done_test.go index 618e86864..0270dec20 100644 --- a/native/cmd/lich-native/chat_done_test.go +++ b/native/cmd/lich-native/chat_done_test.go @@ -1,7 +1,6 @@ package main import ( - "strings" "testing" "time" @@ -10,74 +9,38 @@ import ( "github.com/lichdotdev/lich/native/i18n" ) -func TestADoneLineNamesHowTheTurnEnded(t *testing.T) { - for reason, want := range map[string]string{ - "end_turn": "Done", - "cancelled": "Stopped", - "error": "Failed", - "max_tokens": "Done", - "": "Done", +func TestATurnsLineSaysHowItEndedAndWhen(t *testing.T) { + for _, c := range []struct { + reason string + took time.Duration + want string + }{ + {"end_turn", 64 * time.Second, "Worked for 1m 4s"}, + {"max_tokens", 48 * time.Second, "Worked for 48s"}, + {"", 753 * time.Millisecond, "Worked"}, + {stopCancelled, 41 * time.Second, "Stopped after 41s"}, + {stopCancelled, 0, "Stopped"}, + {stopError, 12 * time.Second, "Failed after 12s"}, + {stopError, 0, "Failed"}, } { - if got := chatDoneWord(reason); got != want { - t.Errorf("a turn that stopped for %q reads %q, want %q", reason, got, want) + if got := chatDoneLabel(c.reason, c.took); got != c.want { + t.Errorf("a turn that stopped for %q after %v reads %q, want %q", c.reason, c.took, got, c.want) } } } -// The group's head is the EDITED label and how many files, in the plural the -// language takes (contract changed: it was one sentence, "Edited 3 files"). -func TestAGroupOfEditsReadsAsTheFilesItChanged(t *testing.T) { - for count, want := range map[int]string{1: "1 file", 3: "3 files"} { - if got := chatEditsCount(count); got != want { - t.Errorf("%d files read %q, want %q", count, got, want) - } +// The files' head says how many, in the plural the language takes. +func TestTheFilesHeadCountsThem(t *testing.T) { + if got := chatFilesCount(3); got != "Changed 3 files" { + t.Errorf("3 files read %q", got) } defer i18n.SetCurrent(i18n.EN) i18n.SetCurrent(i18n.RU) - if got := chatEditsCount(2); got != "2 файла" { + if got := chatFilesCount(2); got != "Изменено 2 файла" { t.Errorf("two files in Russian read %q, want its few form", got) } } -func TestOnlyTheLastFinishedTurnEndsInADoneRow(t *testing.T) { - items := []backend.ChatItem{ - {ID: "n0", Kind: api.ItemNotice, Turn: 0, Text: "resumed"}, - {ID: "u1", Kind: api.ItemUser, Turn: 1, At: 1000}, - {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: 2000}, - {ID: "u2", Kind: api.ItemUser, Turn: 2, At: 3000}, - {ID: "a2", Kind: api.ItemAgent, Turn: 2, At: 4000}, - } - done := func(items []backend.ChatItem, running bool) (turns []int) { - for _, r := range chatRows(items, claudeKind, running, time.UnixMilli(5000)) { - if r.kind == chatRowDone { - turns = append(turns, r.turn) - } - } - return turns - } - if got := done(items, false); len(got) != 1 || got[0] != 2 { - t.Errorf("done rows %v for a conversation of two finished turns, want turn 2 alone", got) - } - rows := chatRows(items, claudeKind, false, time.UnixMilli(5000)) - if last := rows[len(rows)-1]; last.kind != chatRowDone || chatRowKey(last) != "done:2" { - t.Errorf("the conversation ends in %+v, want turn 2's done row", last) - } - if got := done(items, true); got != nil { - t.Errorf("done rows %v while turn 2 runs, want none: the live row stands there", got) - } - // The person's next message takes the line away: turn 3 has begun. - next := append(items[:5:5], backend.ChatItem{ID: "u3", Kind: api.ItemUser, Turn: 3, At: 6000}) - if got := done(next, true); got != nil { - t.Errorf("done rows %v once turn 3 began, want none", got) - } - if got := done(items[:1], false); got != nil { - t.Errorf("done rows %v for a conversation no message opened", got) - } - if got := done(nil, false); got != nil { - t.Errorf("done rows %v for an empty conversation", got) - } -} - func TestTheStoreTiesATurnEndToTheTurnItClosed(t *testing.T) { var s chatStore s.history("s1", []backend.ChatItem{{ID: "u1", Kind: api.ItemUser, Turn: 1}, {ID: "u2", Kind: api.ItemUser, Turn: 2}}) @@ -98,123 +61,3 @@ func TestTheStoreTiesATurnEndToTheTurnItClosed(t *testing.T) { t.Error("a conversation the window never heard has an end") } } - -// endedTurn is a chat of one finished turn whose end event said end. -func endedTurn(t *testing.T, end api.ChatTurn) (*window, *frameRig) { - t.Helper() - u, r := stampFrames(t) - u.dock = new(dock) - u.model.chat.history("s1", []backend.ChatItem{ - {ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 58), Text: "go"}, - {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 59), Text: "did it"}, - }) - end.SessionID = "s1" - u.model.chat.turn(end) - r.settle(t) - return u, r -} - -// What the turn changed is on its edits' rows, which open Review -// (TestAGroupOfEditsHeadsItsFilesAndOpensReview), not on its closing line. -func TestTheDoneLineLeavesTheTurnsChangesToItsEdits(t *testing.T) { - _, r := endedTurn(t, api.ChatTurn{StopReason: "end_turn", Changes: &api.ChatTurnChanges{Files: 3, Added: 12, Removed: 4}}) - if !r.shows("Done") { - t.Fatalf("no Done:\n%s", r.drawn()) - } - for _, label := range []string{"3 files", "+12", "\u22124", "no changes"} { - if r.shows(label) { - t.Errorf("the closing line shows %q:\n%s", label, r.drawn()) - } - } -} - -func TestTheDoneLineOfATurnThatChangedNothingIsNotAClick(t *testing.T) { - u, r := endedTurn(t, api.ChatTurn{StopReason: "end_turn", Changes: &api.ChatTurnChanges{}}) - if !r.shows("Done") || !r.shows("no changes") { - t.Fatalf("want Done, no changes:\n%s", r.drawn()) - } - r.clickLabel(t, "no changes") - if u.dock.tab == dockReview { - t.Error("\"no changes\" opened Review") - } -} - -func TestTheDoneLineOfAStoppedAndAFailedTurn(t *testing.T) { - for reason, want := range map[string]string{"cancelled": "Stopped", "error": "Failed"} { - _, r := endedTurn(t, api.ChatTurn{StopReason: reason, Changes: &api.ChatTurnChanges{Files: 1, Added: 1}}) - if !r.shows(want) || r.shows("Done") { - t.Errorf("a turn that stopped for %q:\n%s", reason, r.drawn()) - } - } -} - -func TestTheDoneLineWithoutACountIsItsWordAlone(t *testing.T) { - _, r := endedTurn(t, api.ChatTurn{StopReason: "end_turn"}) - if !r.shows("Done") || r.shows("no changes") || r.shows("0 files") { - t.Errorf("a turn whose checkout could not be read:\n%s", r.drawn()) - } -} - -func TestTheDoneLineOfATurnReadBackWithTheHistoryIsDoneAlone(t *testing.T) { - u, r := stampFrames(t) - u.model.chat.history("s1", []backend.ChatItem{ - {ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 58), Text: "go"}, - {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 59), Text: "did it"}, - }) - r.settle(t) - if !r.shows("Done") || r.shows("no changes") { - t.Errorf("a turn nobody reported the end of:\n%s", r.drawn()) - } -} - -func TestAHistoryOfSeveralTurnsClosesOnlyTheLast(t *testing.T) { - u, r := stampFrames(t) - u.model.chat.history("s1", []backend.ChatItem{ - {ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 50), Text: "one"}, - {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 51), Text: "first"}, - {ID: "u2", Kind: api.ItemUser, Turn: 2, At: novDay(18, 17, 58), Text: "two"}, - {ID: "a2", Kind: api.ItemAgent, Turn: 2, At: novDay(18, 17, 59), Text: "second"}, - }) - r.settle(t) - if n := strings.Count(r.drawn(), `"Done"`); n != 1 { - t.Errorf("%d done lines over two turns read back, want the last turn's alone:\n%s", n, r.drawn()) - } -} - -func TestTheNextMessageTakesTheDoneLineAway(t *testing.T) { - u, r := endedTurn(t, api.ChatTurn{StopReason: "end_turn", Changes: &api.ChatTurnChanges{Files: 3, Added: 12, Removed: 4}}) - if !r.shows("Done") { - t.Fatalf("no done line before the message:\n%s", r.drawn()) - } - u.model.chat.turn(api.ChatTurn{SessionID: "s1", Running: true}) - u.model.chat.apply(api.ChatItemUpdate{SessionID: "s1", Item: backend.ChatItem{ID: "u2", Kind: api.ItemUser, Turn: 2, At: novDay(18, 18, 0), Text: "next"}}) - for range 60 { - r.now = r.now.Add(frameStep) - r.frame() - } - if r.shows("Done") || r.shows("3 files") { - t.Errorf("the line is still there once the next message was sent:\n%s", r.drawn()) - } -} - -// The line does not play an exit: the turn that begins takes it away in the -// frame it is heard, or it would stand beside the live line for a moment. -func TestTheDoneLineLeavesInTheFrameTheNextTurnBegins(t *testing.T) { - for name, begin := range map[string]func(u *window){ - "the turn is heard first": func(u *window) { u.model.chat.turn(api.ChatTurn{SessionID: "s1", Running: true}) }, - "the message is heard first": func(u *window) { - u.model.chat.apply(api.ChatItemUpdate{SessionID: "s1", Item: backend.ChatItem{ID: "u2", Kind: api.ItemUser, Turn: 2, At: novDay(18, 18, 0), Text: "next"}}) - }, - } { - u, r := endedTurn(t, api.ChatTurn{StopReason: "end_turn", Changes: &api.ChatTurnChanges{Files: 3, Added: 12, Removed: 4}}) - if !r.shows("Done") { - t.Fatalf("%s: no done line before the next turn:\n%s", name, r.drawn()) - } - begin(u) - r.now = r.now.Add(frameStep) - r.frame() - if r.shows("Done") || r.shows("3 files") { - t.Errorf("%s: the line is drawn in the frame the next turn began:\n%s", name, r.drawn()) - } - } -} diff --git a/native/cmd/lich-native/chat_edit.go b/native/cmd/lich-native/chat_edit.go index af7607e5c..dcdd283e1 100644 --- a/native/cmd/lich-native/chat_edit.go +++ b/native/cmd/lich-native/chat_edit.go @@ -1,6 +1,7 @@ package main import ( + "image" "path" "path/filepath" "strings" @@ -18,11 +19,18 @@ import ( // diffNoFile is the side of a unified diff a file created or deleted lacks. const diffNoFile = "/dev/null" -// chatEdit is a call that changed a file: one line with the file's type, its -// path and its counts, the diff under it once clicked; a Ctrl+click opens the -// file instead. While the call runs its path shimmers; failed, it says so. -// Edits one after another are one group under a label, the first of them -// heading it; the group stands on the conversation, with no ground. +// chatEditPadY is the room over and under an edit's line, and chatEditBleed how +// far its hover fill runs past it, which starts and ends with the text. +var ( + chatEditPadY = ui.Space(1.5) + chatEditBleed = ui.Space(2) +) + +// chatEdit is a call that changed a file, or a file a finished turn changed +// with all its edits: one line with the file's type, its path and its counts, +// the diff under it once clicked; a Ctrl+click opens the file instead. While +// the call runs its path shimmers; failed, it says so. It stands on the +// conversation, with no ground. func (u *window) chatEdit(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r chatRow) D { t := r.item.Tool if t == nil { @@ -30,7 +38,16 @@ func (u *window) chatEdit(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r ch } f := p.fold("edit:" + r.item.ID) file := editPath(t, sv.path) - _, added, deleted, body := splitDiff(t.Diff) + diff, body, added, deleted := t.Diff, []string(nil), 0, 0 + if len(r.edits) > 0 { + diff = joinDiffs(r.edits) + for _, it := range r.edits { + _, a, d, lines := splitDiff(it.Tool.Diff) + added, deleted, body = added+a, deleted+d, append(body, lines...) + } + } else { + _, added, deleted, body = splitDiff(diff) + } if f.click.Clicked(gtx) { if p.paths != nil && p.paths.Held && p.paths.Link(file) { p.paths.Open(file) @@ -39,32 +56,12 @@ func (u *window) chatEdit(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r ch } } running := r.live && callRunning(r.item) - pad := layout.Inset{Left: ui.Space(3), Right: ui.Space(3), Top: ui.Space(2), Bottom: ui.Space(2)} - if r.editAbove || len(r.edits) > 0 { - pad.Top = ui.Space(1.5) - } - if r.editBelow { - pad.Bottom = ui.Space(1.5) - } - head := func(gtx C) D { - return f.click.Layout(gtx, func(gtx C) D { - return layout.Background{}.Layout(gtx, chatEditHoverFill(th, &f.click), func(gtx C) D { - gtx.Constraints.Min.X = gtx.Constraints.Max.X - return pad.Layout(gtx, func(gtx C) D { - return chatEditLine(gtx, th, f, t, file, running, added, deleted, len(body) > 0) - }) - }) - }) - } - m := op.Record(gtx.Ops) - d := layout.Flex{Axis: layout.Vertical}.Layout(gtx, + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - if len(r.edits) == 0 { - return D{} - } - return u.chatEditsHead(gtx, th, p, sv, r) + return chatBleedLine(gtx, th, &f.click, func(gtx C) D { + return chatEditLine(gtx, th, f, t, file, running, added, deleted, len(body) > 0) + }) }), - layout.Rigid(head), layout.Rigid(func(gtx C) D { if f.shut(gtx.Now) { return f.body.Layout(gtx, false, chatNothing) @@ -72,55 +69,88 @@ func (u *window) chatEdit(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r ch return f.body.Layout(gtx, f.open, func(gtx C) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, ui.VGap(1), - layout.Rigid(func(gtx C) D { return u.chatEditDiff(gtx, th.On(th.Background), p, f, t.Diff, body) }), + layout.Rigid(func(gtx C) D { return u.chatEditDiff(gtx, th.On(th.Background), p, f, diff, body) }), ) }) }), ) - call := m.Stop() - call.Add(gtx.Ops) - return d } -// chatEditsHead heads a group of edits, a group's label: EDITED, how many -// files muted and all their lines in the tones; a click opens Review, as the -// footer's changes item does. -func (u *window) chatEditsHead(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r chatRow) D { - f := p.fold("edits:" + r.item.ID) +// joinDiffs is the diffs of a file's edits one after the other, each with git's +// line, which tells where the next one starts. +func joinDiffs(edits []backend.ChatItem) string { + if len(edits) == 1 { + return edits[0].Tool.Diff + } + var b strings.Builder + for _, it := range edits { + b.WriteString(strings.TrimRight(gitPatch(it.Tool.Diff), "\n") + "\n") + } + return b.String() +} + +// chatBleedLine is a line of the turn's files, w in the text's column and the +// fill under the pointer chatEditBleed past it each side. +func chatBleedLine(gtx C, th *ui.Theme, click *ui.Clickable, w layout.Widget) D { + bleed := gtx.Dp(chatEditBleed) + width := gtx.Constraints.Max.X + gtx.Constraints.Max.X += 2 * bleed + gtx.Constraints.Min.X = gtx.Constraints.Max.X + defer op.Offset(image.Pt(-bleed, 0)).Push(gtx.Ops).Pop() + d := click.Layout(gtx, func(gtx C) D { + return layout.Background{}.Layout(gtx, chatEditHoverFill(th, click), func(gtx C) D { + return layout.Inset{Left: chatEditBleed, Right: chatEditBleed, Top: chatEditPadY, Bottom: chatEditPadY}.Layout(gtx, w) + }) + }) + return D{Size: image.Pt(width, d.Size.Y)} +} + +// chatFilesHead heads the files a finished turn changed: how many, and all +// their lines in the tones; a click opens Review, as the footer's changes item +// does. +func (u *window) chatFilesHead(gtx C, th *ui.Theme, p *chatPane, r chatRow) D { + f := p.fold(chatRowKey(r)) if f.click.Clicked(gtx) { u.dock.show(dockReview) } - files := map[string]bool{} added, deleted := 0, 0 for _, it := range r.edits { - files[editPath(it.Tool, sv.path)] = true - if it.Tool.State == api.ToolFailed || callRunning(it) { - continue - } _, a, d, _ := splitDiff(it.Tool.Diff) added, deleted = added+a, deleted+d } - return f.click.Layout(gtx, func(gtx C) D { - return layout.Background{}.Layout(gtx, chatEditHoverFill(th, &f.click), func(gtx C) D { - gtx.Constraints.Min.X = gtx.Constraints.Max.X - return layout.Inset{Left: ui.Space(3), Right: ui.Space(3), Top: ui.Space(2), Bottom: ui.Space(1)}.Layout(gtx, func(gtx C) D { - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(th.Text(ui.Text2XS, strings.ToUpper(i18n.T("chat.view.edited"))).Muted().Weight(font.SemiBold).Leading(text2XSLeading).Layout), - ui.Gap(1.5), - layout.Flexed(1, th.Text(ui.TextXS, chatEditsCount(len(files))).Muted().Layout), - ui.Gap(2), - layout.Rigid(th.DiffStat(added, deleted).Layout), - ui.Gap(2), - layout.Rigid(layout.Spacer{Width: ui.Space(4)}.Layout), - ) - }) - }) + return chatBleedLine(gtx, th, &f.click, func(gtx C) D { + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Flexed(1, ui.Spanning(th.Text(ui.TextSM, chatFilesCount(r.count)).Muted().Layout)), + ui.Gap(2), + layout.Rigid(th.DiffStat(added, deleted).Layout), + ) }) } -// chatEditsCount is how many files a group of edits changed, beside its label. -func chatEditsCount(files int) string { - return i18n.T("common.count.file", i18n.Args{"count": files}) +// chatFilesCount is how many files a finished turn changed. +func chatFilesCount(files int) string { + return i18n.T("chat.done.changed", i18n.Args{"count": files}) +} + +// chatFilesRest shows the files past chatFilesShown, or hides them again. +func chatFilesRest(gtx C, th *ui.Theme, p *chatPane, r chatRow) D { + f := p.fold(r.run) + if f.click.Clicked(gtx) { + p.turnFold(gtx, f) + } + text := i18n.T("chat.done.moreFiles", i18n.Args{"count": r.count}) + if f.open { + text = i18n.T("chat.view.shellLess") + } + return layout.Inset{Top: chatEditPadY, Bottom: chatEditPadY}.Layout(gtx, func(gtx C) D { + return f.click.Layout(gtx, func(gtx C) D { + fg := th.MutedForeground + if f.click.Hovered() { + fg = th.Foreground + } + return th.Text(ui.TextXS, text).In(fg).Layout(gtx) + }) + }) } // chatEditHover is how much of Accent the line takes under the pointer, the @@ -156,9 +186,9 @@ func chatEditFailure(gtx C, th *ui.Theme, t *backend.ChatToolCall) D { const chatEditWhyShare = 0.5 // chatEditLine is the edit's line: the file's type, its name, its folder -// muted and cut first when the line is short, the counts once done or why it -// failed, and the chevron while there is a diff to show and the pointer is on -// it or it is open. +// muted and cut first when the line is short, the chevron while there is a diff +// to show and the pointer is on it or it is open, and at the right the counts +// once done or why it failed. func chatEditLine(gtx C, th *ui.Theme, f *chatFold, t *backend.ChatToolCall, file string, running bool, added, deleted int, diff bool) D { dir, name := path.Split(file) base, folder := th.Text(ui.TextSM, name).Mono().Weight(font.Medium), th.Text(ui.TextXS, strings.TrimSuffix(dir, "/")).Mono().Muted() @@ -171,8 +201,23 @@ func chatEditLine(gtx C, th *ui.Theme, f *chatFold, t *backend.ChatToolCall, fil layout.Rigid(base.Layout), ui.Gap(2), layout.Flexed(1, func(gtx C) D { + gtx.Constraints.Min.X = 0 + full, chevron := gtx.Constraints.Max.X, gtx.Dp(ui.Space(3.5)) + gtx.Constraints.Max.X = max(full-chevron-gtx.Dp(ui.Space(1.5)), 0) d := folder.Layout(gtx) - d.Size.X = gtx.Constraints.Max.X + if diff && (f.open || f.click.Hovered()) { + ic, at := icChatClosed, 0 + if f.open { + ic = icChatOpen + } + if d.Size.X > 0 { + at = d.Size.X + gtx.Dp(ui.Space(1.5)) + } + off := op.Offset(image.Pt(at, (d.Size.Y-chevron)/2)).Push(gtx.Ops) + ic.Layout(gtx, ui.Space(3.5), th.MutedForeground) + off.Pop() + } + d.Size.X = full return d }), ui.Gap(2), @@ -185,17 +230,6 @@ func chatEditLine(gtx C, th *ui.Theme, f *chatFold, t *backend.ChatToolCall, fil } return th.DiffStat(added, deleted).Layout(gtx) }), - ui.Gap(2), - layout.Rigid(func(gtx C) D { - if !diff || !f.open && !f.click.Hovered() { - return layout.Spacer{Width: ui.Space(4)}.Layout(gtx) - } - ic := icChatClosed - if f.open { - ic = icChatOpen - } - return ic.Layout(gtx, ui.Space(4), th.MutedForeground) - }), ) } diff --git a/native/cmd/lich-native/chat_edit_diff.go b/native/cmd/lich-native/chat_edit_diff.go index d5515f7f5..331c094d1 100644 --- a/native/cmd/lich-native/chat_edit_diff.go +++ b/native/cmd/lich-native/chat_edit_diff.go @@ -179,7 +179,7 @@ func chatDiffMore(gtx C, th *ui.Theme, c *ui.Clickable, hidden int) D { if c.Hovered() { fg = th.Foreground } - return layout.Inset{Left: ui.Space(3), Right: ui.Space(3), Top: ui.Space(1.5)}.Layout(gtx, + return layout.Inset{Top: ui.Space(1.5), Bottom: ui.Space(1.5)}.Layout(gtx, th.Text(ui.TextXS, i18n.T("chat.view.moreLines", i18n.Args{"count": hidden})).In(fg).Layout) }) } diff --git a/native/cmd/lich-native/chat_edit_test.go b/native/cmd/lich-native/chat_edit_test.go index 7075efc87..115596f16 100644 --- a/native/cmd/lich-native/chat_edit_test.go +++ b/native/cmd/lich-native/chat_edit_test.go @@ -63,7 +63,7 @@ func TestAnEditIsALineThatOpensItsDiff(t *testing.T) { t.Errorf("the edit line lacks %q:\n%s", s, r.drawn()) } } - if r.shows("Edit") || r.shows("EDITED") { + if r.shows("Edit") || r.shows(chatFilesCount(1)) { t.Fatalf("the edit shows its tool's name or a group's head:\n%s", r.drawn()) } if name, folder := labelBox(t, r, "page.tsx").Min, labelBox(t, r, "app").Min; folder.X <= name.X || abs(folder.Y-name.Y) > 4 { @@ -72,7 +72,7 @@ func TestAnEditIsALineThatOpensItsDiff(t *testing.T) { r.click(t, r.at(t, "page.tsx")) r.settle(t) writeShot(t, r, "edit-open.png") - f := u.chats.pane("s1").fold("edit:e1") + f := u.chats.pane("s1").fold("edit:changed:1#app/page.tsx") if !f.open || f.diff == nil || f.diff.fail || len(f.diff.files) != 1 || f.diff.files[0].rows != 4 { t.Fatalf("the open edit's diff = %+v, want one file of 4 rows in the code view", f.diff) } @@ -108,7 +108,7 @@ func TestALongEditShowsItsFirstRowsAndTheWayToTheRest(t *testing.T) { } r.click(t, r.at(t, "Show 30 more lines")) r.settle(t) - if r.shows("Show 30 more lines") || !u.chats.pane("s1").fold("edit:e1").diff.whole { + if r.shows("Show 30 more lines") || !u.chats.pane("s1").fold("edit:changed:1#a.go").diff.whole { t.Errorf("the edit still holds rows back after the click:\n%s", r.drawn()) } } @@ -130,7 +130,7 @@ func TestAFoldedEditScrollsItsHiddenRows(t *testing.T) { r.settle(t) r.click(t, r.at(t, "a.go")) r.settle(t) - diff := u.chats.pane("s1").fold("edit:e1").diff + diff := u.chats.pane("s1").fold("edit:changed:1#a.go").diff over := r.at(t, "Show 30 more lines").Sub(f32.Pt(0, 60)) wheel := func(dy float32) { r.router.Queue(pointer.Event{Kind: pointer.Scroll, Source: pointer.Mouse, Position: over, Scroll: f32.Pt(0, dy)}) @@ -248,27 +248,23 @@ func TestEditsOneAfterAnotherShareAGroup(t *testing.T) { if r.kind != chatRowEdit { continue } - var ids []string - for _, it := range r.edits { - ids = append(ids, it.ID) - } - got = append(got, fmt.Sprintf("%s above=%v below=%v head=%v", r.item.ID, r.editAbove, r.editBelow, ids)) + got = append(got, fmt.Sprintf("%s above=%v", r.item.ID, r.editAbove)) } want := []string{ - "e1 above=false below=true head=[e1 e2]", - "e2 above=true below=false head=[]", - "e3 above=false below=false head=[]", - "b#x.go above=false below=true head=[b#x.go b#y.go]", - "b#y.go above=true below=false head=[]", + "e1 above=false", + "e2 above=true", + "e3 above=false", + "b#x.go above=false", + "b#y.go above=true", } if !slices.Equal(got, want) { t.Errorf("edit rows\n%v\nwant\n%v", strings.Join(got, "\n"), strings.Join(want, "\n")) } } -// A group of edits heads its rows with how many files they changed and all -// their lines, and the head opens Review; each row still opens its own diff. -func TestAGroupOfEditsHeadsItsFilesAndOpensReview(t *testing.T) { +// A finished turn heads its files with how many they are and all their lines, +// and the head opens Review; each row still opens its own diff. +func TestTheFilesATurnChangedAreHeadedAndOpenReview(t *testing.T) { u, r, _ := chatFrames(t, api.ViewChat) u.dock = new(dock) r.theme.Code = godemirror.DarkTheme @@ -295,18 +291,18 @@ func TestAGroupOfEditsHeadsItsFilesAndOpensReview(t *testing.T) { }) r.settle(t) writeShot(t, r, "edit-group.png") - for _, s := range []string{"EDITED", chatEditsCount(3), "+40", "-12", "downloads.go", "internal/browser", "+18", "ceilings.md", "docs"} { + for _, s := range []string{chatFilesCount(3), "+40", "-12", "downloads.go", "internal/browser", "+18", "ceilings.md", "docs"} { if !r.shows(s) { t.Errorf("the group lacks %q:\n%s", s, r.drawn()) } } - r.clickLabel(t, chatEditsCount(3)) + r.clickLabel(t, chatFilesCount(3)) if u.dock.tab != dockReview { t.Errorf("the group's head opened tab %v, want Review", u.dock.tab) } r.clickLabel(t, "ceilings.md") r.settle(t) - if f := u.chats.pane("s1").fold("edit:e3"); !f.open { + if f := u.chats.pane("s1").fold("edit:changed:1#docs/ceilings.md"); !f.open { t.Error("a click on a row of the group left its diff shut") } } diff --git a/native/cmd/lich-native/chat_envelope_draw.go b/native/cmd/lich-native/chat_envelope_draw.go index ad55490e5..16da362fc 100644 --- a/native/cmd/lich-native/chat_envelope_draw.go +++ b/native/cmd/lich-native/chat_envelope_draw.go @@ -280,8 +280,7 @@ func (u *window) chatWorkerNote(gtx C, th *ui.Theme, p *chatPane, key string, en // plain text, and code spans and bold read as their marks there. var markdownMarks = strings.NewReplacer("`", "", "**", "") -// workerNoteGlyph is the glyph of how a worker's task ended, in the tone the -// turn's closing line gives the same end. +// workerNoteGlyph is the glyph of how a worker's task ended, in its tone. func workerNoteGlyph(th *ui.Theme, kind string) (*icons.Icon, color.NRGBA) { switch kind { case "worker-finished": diff --git a/native/cmd/lich-native/chat_group_test.go b/native/cmd/lich-native/chat_group_test.go index a6ffea2bc..ec13bb4e9 100644 --- a/native/cmd/lich-native/chat_group_test.go +++ b/native/cmd/lich-native/chat_group_test.go @@ -102,6 +102,7 @@ func TestAnOpenGroupShowsItsLastCallsFirst(t *testing.T) { Tool: &backend.ChatToolCall{Name: "Grep", Title: "call-" + strconv.Itoa(i), State: api.ToolDone}}) } u, r := lifeFrames(t, items, false) + u.chats.pane("s1").fold("done:1").open = true r.play(15) u.chats.pane("s1").fold("work:c0").open = true r.play(15) @@ -125,7 +126,7 @@ func TestAnOpenGroupShowsItsLastCallsFirst(t *testing.T) { } // A turn's calls fold into one line per run, a run ending where the agent -// speaks, each line where its run began; the turn's end counts them all. +// speaks, each line where its run began. func TestATurnFoldsEachRunOfCallsWhereItRan(t *testing.T) { call := func(id string) backend.ChatItem { return backend.ChatItem{ID: id, Kind: api.ItemTool, Turn: 1, Tool: &backend.ChatToolCall{Name: "Grep", State: api.ToolDone}} @@ -139,19 +140,16 @@ func TestATurnFoldsEachRunOfCallsWhereItRan(t *testing.T) { {ID: "a2", Kind: api.ItemAgent, Turn: 1, Text: "done"}, } var got []string - done := 0 for _, r := range chatRows(items, claudeKind, false, time.Time{}) { switch r.kind { case chatRowWork: got = append(got, chatRowKey(r)+"="+strconv.Itoa(len(r.tools))) case chatRowItem: got = append(got, r.item.ID) - case chatRowDone: - done = len(r.tools) } } want := []string{"u", "work:k1=2", "a1", "th", "work:k3=1", "a2"} - if !slices.Equal(got, want) || done != 3 { - t.Errorf("rows %v and %d calls at the end, want %v and 3", got, done, want) + if !slices.Equal(got, want) { + t.Errorf("rows %v, want %v", got, want) } } diff --git a/native/cmd/lich-native/chat_items.go b/native/cmd/lich-native/chat_items.go index e557d28c1..762a38f4f 100644 --- a/native/cmd/lich-native/chat_items.go +++ b/native/cmd/lich-native/chat_items.go @@ -40,8 +40,8 @@ var ( const chatShellLines = 20 var ( - // chatBranchGutter is the room a tool row gives its connector, and - // chatBranchX where the connector runs: under the fold's chevron. + // chatBranchGutter is the room a shell command's call gives its connector, + // and chatBranchX where the connector runs. chatBranchGutter = ui.Space(6) chatBranchX = ui.Space(1.75) ) @@ -64,10 +64,11 @@ func (u *window) chatRow(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r cha } return chatLive(gtx, th, u.chatVerbs, sv.ID, r) case chatRowDone: - if p.swap.key == chatRowKey(r) && p.swap.playing(gtx.Now) { - return u.chatSwapLine(gtx, th, p, sv, r) - } - return u.chatDone(gtx, th, sv, r, 1) + return u.chatDone(gtx, th, p, r) + case chatRowFiles: + return u.chatFilesHead(gtx, th, p, r) + case chatRowFilesRest: + return chatFilesRest(gtx, th, p, r) case chatRowDay: return layout.Center.Layout(gtx, th.Text(ui.TextXS, dayLabel(time.UnixMilli(r.day).In(gtx.Now.Location()), gtx.Now)).Muted().Layout) } @@ -83,6 +84,11 @@ func (u *window) chatRow(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r cha c := p.copyOf(it.ID) return u.messageMenu(gtx, th, p, sv, c, it.ID, "user:"+it.ID, it.Text, func(gtx C) D { return u.chatUserRow(gtx, th, p, c, it) }) case api.ItemAgent: + if r.tucked != "" { + dim := *th + dim.Palette.Foreground = th.MutedForeground + th = &dim + } return u.chatAgent(gtx, th, p, sv, r) case api.ItemCompaction: return u.chatCompaction(gtx, th, p, it) @@ -224,8 +230,9 @@ func (f *chatFold) update(gtx C) { } } -// chatFoldLine is a fold's line: its chevron, a glyph of the step when it has -// one and the label, muted, lit on hover. +// chatFoldLine is a fold's line: a glyph of the step when it has one, the label +// and its chevron, muted, lit on hover. The chevron comes last, so the words +// start where the conversation's text does. func chatFoldLine(gtx C, th *ui.Theme, f *chatFold, lead icons.Glyph, label func(gtx C, fg color.NRGBA) D) D { ic := icChatClosed if f.open { @@ -236,14 +243,12 @@ func chatFoldLine(gtx C, th *ui.Theme, f *chatFold, lead icons.Glyph, label func if f.click.Hovered() { fg = th.Foreground } - row := []layout.FlexChild{ - layout.Rigid(func(gtx C) D { return ic.Layout(gtx, ui.Space(3.5), fg) }), - ui.Gap(1.5), - } + var row []layout.FlexChild if lead != nil { row = append(row, layout.Rigid(func(gtx C) D { return lead.Layout(gtx, ui.Space(3.5), fg) }), ui.Gap(1.5)) } - row = append(row, layout.Rigid(func(gtx C) D { return label(gtx, fg) })) + row = append(row, layout.Rigid(func(gtx C) D { return label(gtx, fg) }), + ui.Gap(1.5), layout.Rigid(func(gtx C) D { return ic.Layout(gtx, ui.Space(3.5), fg) })) return layout.Flex{Alignment: layout.Middle}.Layout(gtx, row...) }) } @@ -278,7 +283,7 @@ func chatThought(gtx C, th *ui.Theme, f *chatFold, it backend.ChatItem, live boo return f.body.Layout(gtx, false, chatNothing) } return f.body.Layout(gtx, f.open, func(gtx C) D { - return layout.Inset{Top: ui.Space(1.5), Left: ui.Space(5)}.Layout(gtx, th.Text(ui.TextSM, expandTabs(it.Text)).Muted().Wrapped().Layout) + return layout.Inset{Top: ui.Space(1.5)}.Layout(gtx, th.Text(ui.TextSM, expandTabs(it.Text)).Muted().Wrapped().Layout) }) }), ) @@ -286,7 +291,7 @@ func chatThought(gtx C, th *ui.Theme, f *chatFold, it backend.ChatItem, live boo // chatWork is a run of tool calls between the agent's texts: one call alone // is its own row; several fold into a line saying what they did, a clause per -// kind with the time they took and how many failed, opening on a row per call. +// kind and how many failed, opening on a row per call. // While a call runs the line is that call, shimmering, beside the count. func (u *window) chatWork(gtx C, th *ui.Theme, p *chatPane, f *chatFold, sv sessionView, r chatRow) D { outcome, vetoed := u.chatOutcome(p, sv) @@ -316,13 +321,9 @@ func chatWorkLabel(gtx C, th *ui.Theme, r chatRow, vetoed func(backend.ChatItem) ) } label, failed := callSummary(r.tools, vetoed) - row := []layout.FlexChild{ - layout.Rigid(th.Text(ui.TextSM, label).In(fg).Layout), - ui.Gap(1.5), - layout.Rigid(th.Text(ui.TextSM, chatTook(r.took)).Muted().Layout), - } + row := []layout.FlexChild{layout.Rigid(th.Text(ui.TextSM, label).In(fg).Layout)} if failed != "" { - row = append(row, ui.Gap(1.5), layout.Rigid(th.Text(ui.TextSM, "· "+failed).In(th.Destructive).Layout)) + row = append(row, ui.Gap(1.5), layout.Rigid(th.Text(ui.TextSM, failed).In(th.Destructive).Layout)) } return layout.Flex{Alignment: layout.Baseline}.Layout(gtx, row...) } @@ -343,9 +344,8 @@ func chatShort(s string) string { // turn of fifty calls would run past the view; the rest are a click away. const chatCallsShown = 5 -// chatCalls are a group's calls, under the line and indented past its -// chevron, each in a fold of its own that opens and -// shuts with the group: its last chatCallsShown, under a line that shows the +// chatCalls are a group's calls, under the line, each in a fold of its own that +// opens and shuts with the group: its last chatCallsShown, under a line that shows the // earlier ones until earlier is opened. A call that comes once the group is // drawn enters as a row does. func chatCalls(gtx C, th *ui.Theme, f, earlier *chatFold, r chatRow, outcome func(backend.ChatItem) *chatOpened) []layout.FlexChild { @@ -364,9 +364,7 @@ func chatCalls(gtx C, th *ui.Theme, f, earlier *chatFold, r chatRow, outcome fun return fold.Layout(gtx, false, chatNothing) } return fold.Layout(gtx, f.open, func(gtx C) D { - return layout.Inset{Top: ui.Space(1)}.Layout(gtx, func(gtx C) D { - return layout.Inset{Left: chatBranchGutter}.Layout(gtx, func(gtx C) D { return chatEarlierCalls(gtx, th, earlier, hidden) }) - }) + return layout.Inset{Top: ui.Space(1)}.Layout(gtx, func(gtx C) D { return chatEarlierCalls(gtx, th, earlier, hidden) }) }) })) } @@ -385,9 +383,7 @@ func chatCalls(gtx C, th *ui.Theme, f, earlier *chatFold, r chatRow, outcome fun if i == 0 && hidden == 0 { top = ui.Space(1) } - return layout.Inset{Top: top}.Layout(gtx, func(gtx C) D { - return layout.Inset{Left: chatBranchGutter}.Layout(gtx, func(gtx C) D { return chatToolWith(gtx, th, it, r.live, outcome(it), verbW) }) - }) + return layout.Inset{Top: top}.Layout(gtx, func(gtx C) D { return chatToolWith(gtx, th, it, r.live, outcome(it), verbW) }) }) }) })) @@ -455,7 +451,7 @@ func chatShellMore(gtx C, th *ui.Theme, more *chatFold, hidden int) D { } // chatEarlierCalls shows a group's calls before its last chatCallsShown, or -// hides them again, a row on the group's branch. +// hides them again. func chatEarlierCalls(gtx C, th *ui.Theme, earlier *chatFold, hidden int) D { text := i18n.T("chat.view.earlierCalls", i18n.Args{"count": hidden}) if earlier.open { @@ -467,9 +463,7 @@ func chatEarlierCalls(gtx C, th *ui.Theme, earlier *chatFold, hidden int) D { if earlier.click.Hovered() { fg = th.Foreground } - return layout.W.Layout(gtx, func(gtx C) D { - return layout.Inset{Left: ui.Space(2)}.Layout(gtx, th.Text(ui.TextXS, text).In(fg).Layout) - }) + return layout.W.Layout(gtx, th.Text(ui.TextXS, text).In(fg).Layout) }) } @@ -519,58 +513,56 @@ func chatToolWith(gtx C, th *ui.Theme, it backend.ChatItem, live bool, opened *c line := func(gtx C) D { h := gtx.Dp(chatToolRow) gtx.Constraints.Min.Y, gtx.Constraints.Max.Y = h, h - return layout.Inset{Right: ui.Space(2)}.Layout(gtx, func(gtx C) D { - ink := th.MutedForeground - if t.State == api.ToolFailed { - ink = th.Destructive - } - verb := th.Text(ui.TextXS, callVerb(t, running)).In(ink).Truncated() - target := th.Text(ui.TextXS, cleanLine(t.Title)).Mono() - if running { - // The band lights toward Foreground, so the target runs muted to show it. - verb, target = verb.Shimmer(), target.Muted().Shimmer() - } - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(func(gtx C) D { - if opened != nil && opened.mark != nil { - return opened.mark(gtx) - } - return toolIcon(t.Name).Layout(gtx, ui.Space(3.5), ink) - }), - ui.Gap(2), - layout.Rigid(func(gtx C) D { - if verbW > 0 { - gtx.Constraints.Max.X = verbW - } - d := verb.Layout(gtx) - d.Size.X = max(d.Size.X, verbW) - return d - }), - ui.Gap(2), - layout.Flexed(1, func(gtx C) D { - if opened != nil && opened.target != nil { - gtx.Constraints.Min.X = 0 - d := opened.target(gtx) - d.Size.X = gtx.Constraints.Max.X - return d - } - // The text's own width, not the room's: the band sweeps the words. + ink := th.MutedForeground + if t.State == api.ToolFailed { + ink = th.Destructive + } + verb := th.Text(ui.TextXS, callVerb(t, running)).In(ink).Truncated() + target := th.Text(ui.TextXS, cleanLine(t.Title)).Mono() + if running { + // The band lights toward Foreground, so the target runs muted to show it. + verb, target = verb.Shimmer(), target.Muted().Shimmer() + } + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Rigid(func(gtx C) D { + if opened != nil && opened.mark != nil { + return opened.mark(gtx) + } + return toolIcon(t.Name).Layout(gtx, ui.Space(3.5), ink) + }), + ui.Gap(2), + layout.Rigid(func(gtx C) D { + if verbW > 0 { + gtx.Constraints.Max.X = verbW + } + d := verb.Layout(gtx) + d.Size.X = max(d.Size.X, verbW) + return d + }), + ui.Gap(2), + layout.Flexed(1, func(gtx C) D { + if opened != nil && opened.target != nil { gtx.Constraints.Min.X = 0 - d := target.Layout(gtx) + d := opened.target(gtx) d.Size.X = gtx.Constraints.Max.X return d - }), - layout.Rigid(func(gtx C) D { - if opened != nil && opened.links != nil { - return opened.links(gtx) - } - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(func(gtx C) D { return chatToolTime(gtx, th, it, running) }), - layout.Rigid(func(gtx C) D { return chatToolOutcome(gtx, th, t) }), - ) - }), - ) - }) + } + // The text's own width, not the room's: the band sweeps the words. + gtx.Constraints.Min.X = 0 + d := target.Layout(gtx) + d.Size.X = gtx.Constraints.Max.X + return d + }), + layout.Rigid(func(gtx C) D { + if opened != nil && opened.links != nil { + return opened.links(gtx) + } + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Rigid(func(gtx C) D { return chatToolTime(gtx, th, it, running) }), + layout.Rigid(func(gtx C) D { return chatToolOutcome(gtx, th, t) }), + ) + }), + ) } if t.Diff == "" { return line(gtx) @@ -601,7 +593,8 @@ func chatVerbWidth(gtx C, th *ui.Theme, tools []backend.ChatItem, live bool) int } // chatToolTime is the time a call has run, counting while running, standing -// still once it ended, and nothing where its start or end is unknown. +// still once it ended, and nothing where its start or end is unknown or it took +// under a second. func chatToolTime(gtx C, th *ui.Theme, it backend.ChatItem, running bool) D { if it.At <= 0 { return D{} @@ -617,11 +610,10 @@ func chatToolTime(gtx C, th *ui.Theme, it backend.ChatItem, running bool) D { default: return D{} } - text := chatTook(took) - if running { - text = chatElapsed(took) + if !running && took < time.Second { + return D{} } - return layout.Inset{Left: ui.Space(2.5)}.Layout(gtx, th.Text(ui.TextXS, text).Mono().Muted().Layout) + return layout.Inset{Left: ui.Space(2.5)}.Layout(gtx, th.Text(ui.TextXS, chatElapsed(took)).Mono().Muted().Layout) } // chatToolOutcome is why a call failed, the first line of its output in @@ -858,7 +850,7 @@ func (u *window) chatAgent(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r c return u.messageMenu(gtx, th, p, sv, c, it.ID, it.ID, text, func(gtx C) D { return u.chatAnswer(gtx, th, p, sv, r, c) }) } -// chatAnswer is chatAgent's text and, on the run's last text, its foot. +// chatAnswer is chatAgent's text and, under a finished turn's answer, its foot. func (u *window) chatAnswer(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r chatRow, c *chatCopy) D { it := r.item src := it.Text @@ -870,9 +862,9 @@ func (u *window) chatAnswer(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r return p.md.LayoutLinksWindow(gtx, th, it.ID, src, links, p.window) }), } - // a text another follows reads on into it: the run's last one keeps - // the time and the copy, which takes the whole run - if !r.more { + // the foot is the answer's alone: under the texts on the way to it the + // line would only set the rows apart + if r.foot { stamped := it if r.runText != "" { stamped.Text = r.runText @@ -901,15 +893,6 @@ func chatElapsed(d time.Duration) string { return unit("session.age.hour", int(d/time.Hour)) + " " + unit("session.age.minute", int(d%time.Hour/time.Minute)) } -// chatTook is a time that stands still: chatElapsed's, in milliseconds under a -// second, where a counter would read 0s. -func chatTook(d time.Duration) string { - if d < time.Second { - return i18n.T("session.age.millisecond", i18n.Args{"count": int(max(d, 0) / time.Millisecond)}) - } - return chatElapsed(d) -} - // chatTick asks for the frame at which the time since start reads differently, // the next second: a counter redraws once a second, not once a frame. func chatTick(gtx C, since time.Time) { diff --git a/native/cmd/lich-native/chat_lich_test.go b/native/cmd/lich-native/chat_lich_test.go index 0532efed7..10bfe0b3d 100644 --- a/native/cmd/lich-native/chat_lich_test.go +++ b/native/cmd/lich-native/chat_lich_test.go @@ -119,6 +119,8 @@ func TestLichCallShots(t *testing.T) { scheme := map[bool]string{false: "dark", true: "light"}[light] writeShot(t, compactShot(t, rows, false, light), "lich-rows-"+scheme+".png") r := compactShot(t, group, false, light) + r.click(t, r.at(t, chatDoneLabel("", 0))) + r.frames(maxSettleFrames) r.click(t, r.at(t, callSummaryLabel(group))) r.frames(maxSettleFrames) writeShot(t, r, "lich-group-"+scheme+".png") diff --git a/native/cmd/lich-native/chat_life_test.go b/native/cmd/lich-native/chat_life_test.go index 1dec0efdd..685fe5535 100644 --- a/native/cmd/lich-native/chat_life_test.go +++ b/native/cmd/lich-native/chat_life_test.go @@ -164,8 +164,8 @@ func TestAThoughtBeingThoughtShimmersAndCountsItsTime(t *testing.T) { } // A group names the call running while it runs, beside how many calls it -// holds; once over it says what its calls did and how long they ran. -func TestARunningGroupCountsItsCallsAndAFinishedOneSaysHowLongTheyRan(t *testing.T) { +// holds; once over it says what its calls did. +func TestARunningGroupCountsItsCallsAndAFinishedOneSaysWhatTheyDid(t *testing.T) { calls := func(state string) []backend.ChatItem { return []backend.ChatItem{ {ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 59), Text: "go"}, @@ -180,12 +180,11 @@ func TestARunningGroupCountsItsCallsAndAFinishedOneSaysHowLongTheyRan(t *testing t.Errorf("no %q on the live group's line:\n%s", s, r.drawn()) } } - _, r = lifeFrames(t, calls(api.ToolDone), false) - r.frame() - for _, s := range []string{"Ran 1 command, read 1 file", chatTook(0)} { - if !r.shows(s) { - t.Errorf("no %q:\n%s", s, r.drawn()) - } + u, done := lifeFrames(t, calls(api.ToolDone), false) + u.chats.pane("s1").fold("done:1").open = true + done.frame() + if s := "Ran 1 command, read 1 file"; !done.shows(s) { + t.Errorf("no %q:\n%s", s, done.drawn()) } } @@ -197,6 +196,7 @@ func TestAnOpenGroupListsItsCallsAndOnlyAFailureSpeaks(t *testing.T) { {ID: "k1", Kind: api.ItemTool, Turn: 1, At: novDay(18, 17, 58), Tool: &backend.ChatToolCall{Name: "Read", Title: "a.go", State: api.ToolDone, Output: "84 lines"}}, {ID: "k2", Kind: api.ItemTool, Turn: 1, At: novDay(18, 17, 59), Tool: &backend.ChatToolCall{Name: "Bash", Title: "go test", State: api.ToolFailed}}, }, false) + u.chats.pane("s1").fold("done:1").open = true u.chats.pane("s1").fold("work:k1").open = true r.settle(t) for _, label := range []string{"Read", "a.go", "Ran", "go test", i18n.T("chat.view.toolFailed")} { @@ -260,7 +260,7 @@ func TestARunningCallShimmersAndCountsAndAnEndedOneStandsStill(t *testing.T) { done.Tool = &backend.ChatToolCall{Name: "Bash", Title: "go test", State: api.ToolDone} r = newFrameRig(image.Pt(400, 40), draw(done, false)) r.frame() - if r.shows(chatElapsed(0)) || r.shows(chatTook(0)) { + if r.shows(chatElapsed(0)) { t.Errorf("a call with no end shows a time:\n%s", r.drawn()) } } @@ -370,7 +370,7 @@ func TestACallOfAnEndedTurnStandsStill(t *testing.T) { for _, tc := range []struct { ended int64 want string - }{{start.Add(3 * time.Second).UnixMilli(), chatTook(3 * time.Second)}, {0, ""}} { + }{{start.Add(3 * time.Second).UnixMilli(), chatElapsed(3 * time.Second)}, {0, ""}} { it := call(tc.ended) var row chatRow for _, r := range chatRows(items(it), claudeKind, false, start.Add(time.Minute)) { @@ -393,12 +393,15 @@ func TestACallOfAnEndedTurnStandsStill(t *testing.T) { } } -// A time that stands still under a second reads in milliseconds. -func TestAStillTimeUnderASecondReadsInMilliseconds(t *testing.T) { - for d, want := range map[time.Duration]string{476 * time.Millisecond: "476ms", 0: "0ms", 2 * time.Second: chatElapsed(2 * time.Second)} { - if got := chatTook(d); got != want { - t.Errorf("chatTook(%v) = %q, want %q", d, got, want) - } +// A call that took under a second shows no time: it says nothing. +func TestACallUnderASecondShowsNoTime(t *testing.T) { + start := time.Unix(1000, 0) + it := backend.ChatItem{ID: "k1", Kind: api.ItemTool, At: start.UnixMilli(), + Tool: &backend.ChatToolCall{Name: "Bash", Title: "ls", State: api.ToolDone, Ended: start.Add(476 * time.Millisecond).UnixMilli()}} + r := newFrameRig(image.Pt(400, 40), func(gtx C, th *ui.Theme) { chatTool(gtx, th, it, false) }) + r.frame() + if r.shows(chatElapsed(0)) || !r.shows("ls") { + t.Errorf("want the call with no time:\n%s", r.drawn()) } } @@ -406,8 +409,8 @@ func TestEachAnswerNamesItsModelInItsFootAndNoHeaderNamesTheProvider(t *testing. u, r := lifeFrames(t, []backend.ChatItem{ {ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 58), Text: "go"}, {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 58), Text: "one", Model: "Haiku 5.5", Effort: "Medium"}, - {ID: "k1", Kind: api.ItemTool, Turn: 1, At: novDay(18, 17, 58), Tool: &backend.ChatToolCall{Name: "Read", State: api.ToolDone}}, - {ID: "a2", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 59), Text: "two"}, + {ID: "u2", Kind: api.ItemUser, Turn: 2, At: novDay(18, 17, 59), Text: "and"}, + {ID: "a2", Kind: api.ItemAgent, Turn: 2, At: novDay(18, 17, 59), Text: "two"}, }, false) u.model.chat.setOptions("s1", chatOptions()) r.settle(t) diff --git a/native/cmd/lich-native/chat_motion.go b/native/cmd/lich-native/chat_motion.go index 50d75a4a8..2249fe014 100644 --- a/native/cmd/lich-native/chat_motion.go +++ b/native/cmd/lich-native/chat_motion.go @@ -1,27 +1,18 @@ package main import ( - "image" + "slices" "time" - "gioui.org/layout" "gioui.org/op" - "gioui.org/op/clip" - "gioui.org/op/paint" "github.com/lichdotdev/lich/api" "github.com/lichdotdev/lich/native/ui" ) // The chat's own motions, past its rows coming and going (native/DESIGN.md › -// The chat view): a row that becomes another plays the change in its slot. +// The chat view). const ( - // The live line turning into the closing line: the flame, verb and clock - // go by chatSwapOut, the word and count come in up to chatSwapIn, and the - // slot takes the closing line's height over chatSwapHeight. - chatSwapOut = 120 * time.Millisecond - chatSwapIn = 280 * time.Millisecond - chatSwapHeight = 160 * time.Millisecond // chatToEndRun is the list's run back to its end when a message is sent // from above it. chatToEndRun = 220 * time.Millisecond @@ -45,65 +36,66 @@ func chatPhase(gtx C, start time.Time, from, to time.Duration, curve func(float3 return curve(float32(e-from) / float32(to-from)) } -// chatSwap is the live line turning into the closing line key in its slot, -// from at; live is the line as it last stood. -type chatSwap struct { - key string - at time.Time - live chatRow +// chatMoved is how many rows may come or go at once and play it: past it they +// land as they are, or a long turn folding would lay out every row it holds in +// its last frames. +const chatMoved = 40 + +// turnFold opens or shuts f, a fold whose rows are the list's own. +func (v *chatView) turnFold(gtx C, f *chatFold) { + f.open, f.turned, v.refold = !f.open, gtx.Now, true + v.held = f.open + gtx.Execute(op.InvalidateCmd{}) } -// playing is whether the swap plays at now. -func (s chatSwap) playing(now time.Time) bool { return s.key != "" && now.Sub(s.at) < chatSwapIn } - -// chatSwapLine is the closing line r while the live line turns into it. -func (u *window) chatSwapLine(gtx C, th *ui.Theme, p *chatPane, sv sessionView, r chatRow) D { - s := p.swap - out := 1 - chatPhase(gtx, s.at, 0, chatSwapOut, paneEaseIn) - in := chatPhase(gtx, s.at, chatSwapOut, chatSwapIn, paneEaseOut) - height := chatPhase(gtx, s.at, 0, chatSwapHeight, paneEaseOut) - return chatCrossfade(gtx, layout.W, height, out, 1, - func(gtx C) D { return chatLive(gtx, th, u.chatVerbs, sv.ID, s.live) }, - func(gtx C) D { return u.chatDone(gtx, th, sv, r, in) }) +// keepPlace holds the list where it stands while the rows under it change from +// was to shown: on the row at its top, or on the next one still there, when it +// is scrolled up; and on the line just clicked, whose rows open under it +// instead of pushing it up, when it is at its end. +func (v *chatView) keepPlace(was, shown []string) { + pos := &v.list.Position + if v.held { + pos.BeforeEnd = true + } + if !v.list.ScrollToEnd || !pos.BeforeEnd { + return + } + for i := pos.First; i < len(was); i++ { + if j := slices.Index(shown, was[i]); j >= 0 { + if i != pos.First { + pos.Offset = 0 + } + pos.First = j + return + } + } } -// chatCrossfade draws out leaving and in arriving in one slot, each placed in -// it by at: out at opacity outA and taking no input, in at inA, and the slot's -// height run from out's to in's by height. Out is no longer drawn once it is -// gone and its height no longer counts. -func chatCrossfade(gtx C, at layout.Direction, height, outA, inA float32, out, in layout.Widget) D { - gtx.Constraints.Min.Y = 0 - m := op.Record(gtx.Ops) - di := in(gtx) - ci := m.Stop() - var do D - var co op.CallOp - if outA > 0 || height < 1 { - m = op.Record(gtx.Ops) - do = out(gtx.Disabled()) - co = m.Stop() - } - h := di.Size.Y - if height < 1 { - h = do.Size.Y + int(float32(di.Size.Y-do.Size.Y)*height+0.5) - } - size := image.Pt(max(do.Size.X, di.Size.X), h) - defer clip.Rect{Max: size}.Push(gtx.Ops).Pop() - for _, l := range []struct { - d D - call op.CallOp - a float32 - }{{do, co, outA}, {di, ci, inA}} { - if l.a <= 0 { - continue +// dry puts the rows of shown that come in, more than chatMoved of them, at +// rest, and takes out those that leave, when they are. +func (v *chatView) dry(was, shown []string) []string { + old := make(map[string]bool, len(was)) + for _, k := range was { + old[k] = true + } + var in []string + out := 0 + for _, k := range shown { + if v.rows.Leaving(k) { + out++ + } else if !old[k] { + in = append(in, k) } - off := op.Offset(at.Position(l.d.Size, size)).Push(gtx.Ops) - fade := paint.PushOpacity(gtx.Ops, l.a) - l.call.Add(gtx.Ops) - fade.Pop() - off.Pop() } - return D{Size: size} + if len(in) > chatMoved { + for _, k := range in { + v.rows.Settle(k) + } + } + if out > chatMoved { + shown = slices.DeleteFunc(shown, v.rows.Leaving) + } + return shown } // chatToEnd is the list's run back to its end after a message was sent from diff --git a/native/cmd/lich-native/chat_motion_test.go b/native/cmd/lich-native/chat_motion_test.go index e54fdde91..0f0f72ef0 100644 --- a/native/cmd/lich-native/chat_motion_test.go +++ b/native/cmd/lich-native/chat_motion_test.go @@ -152,45 +152,6 @@ func TestAnEmptyConversationDraws(t *testing.T) { r.settle(t) } -// The turn ending turns the live line into the closing line in its slot: -// Done stands where the live line's verb was in every frame of the change, -// never under it, and the slot only eases from one line's height to the -// other's (at 1x the flame's 11 rows of 2px are 22px, the word's line less). -func TestTheLiveLineTurnsIntoDoneInItsSlot(t *testing.T) { - items := []backend.ChatItem{{ID: "u1", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 59), Text: "go"}} - u, r := lifeFrames(t, items, true) - r.frames(3) - verb, done := chatVerb("", "s1", 1), i18n.T("chat.done.done") - // the verb is text, whose label runs on past its line: its centre is its - // line's; Done is a glyph whose label is its own box (contract changed: - // the closing line says how the turn ended with a glyph) - centre := func(label string) int { b := labelBox(t, r, label); return (b.Min.Y + b.Max.Y) / 2 } - lineCentre := func(label string) int { return labelBox(t, r, label).Min.Y + int(chatRowLine)/2 } - top, verbAt := labelTop(t, r, "go"), lineCentre(verb) - u.model.chat.turn(api.ChatTurn{SessionID: "s1"}) - last := top - var tops []int - for i := range 30 { - r.frame() - got := labelTop(t, r, "go") - tops = append(tops, got) - if (got-last)*(got-top) < 0 || i > 0 && chatSwapHeight <= time.Duration(i-1)*frameStep && got != last { - t.Errorf("the message above went %v: want it easing one way, within %v", tops, chatSwapHeight) - } - if at := centre(done); abs(at-verbAt-(got-top)) > 2 { - t.Errorf("frame %d: Done centred at y=%d, the verb was at %d and the slot moved by %d: it is not in the verb's place", i, at, verbAt, got-top) - } - if i == 3 && !r.shows(verb) { - t.Errorf("48ms into the change the verb is gone: it does not fade") - } - last = got - r.now = r.now.Add(frameStep) - } - if r.shows(verb) { - t.Error("the verb is still drawn after the change") - } -} - func abs(n int) int { return max(n, -n) } // A message sent while the list is scrolled up takes the list back to its @@ -253,6 +214,7 @@ func TestAThoughtFoldOpensOverItsCollapse(t *testing.T) { {ID: "t1", Kind: api.ItemThought, Turn: 1, At: novDay(18, 17, 58), Text: "pondering"}, {ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 59), Text: "answer"}, }, false) + u.chats.pane("s1").fold("done:1").open = true r.settle(t) shut := labelTop(t, r, "go") r.clickLabel(t, i18n.T("chat.view.thought")) diff --git a/native/cmd/lich-native/chat_question_test.go b/native/cmd/lich-native/chat_question_test.go index 562f9b38a..c68594b9d 100644 --- a/native/cmd/lich-native/chat_question_test.go +++ b/native/cmd/lich-native/chat_question_test.go @@ -243,14 +243,14 @@ func TestTheComposerSendsPastAWaitingQuestion(t *testing.T) { } // A waiting question stands in for the live row, and a window that opened -// mid-turn, which heard no turn start, draws no closing line under it. +// mid-turn, which heard no turn start, does not fold it. func TestNoLiveOrDoneRowWhileAQuestionWaits(t *testing.T) { items := []backend.ChatItem{ {ID: "u1", Kind: api.ItemUser, Turn: 1}, {ID: "q1", Kind: api.ItemQuestion, Turn: 1, Question: &backend.ChatQuestion{Questions: []api.ChatAsk{askFruit}}}, } for _, running := range []bool{true, false} { - for _, r := range chatRows(items, claudeKind, running, time.Now()) { + for _, r := range endedRows(items, running, stopCancelled) { if r.kind == chatRowLive || r.kind == chatRowDone { t.Errorf("running=%v: a row of kind %d under a waiting question", running, r.kind) } diff --git a/native/cmd/lich-native/chat_row_cache.go b/native/cmd/lich-native/chat_row_cache.go index a82ac7f9d..f3a996d96 100644 --- a/native/cmd/lich-native/chat_row_cache.go +++ b/native/cmd/lich-native/chat_row_cache.go @@ -16,6 +16,7 @@ type chatRowCache struct { items []backend.ChatItem kind string running bool + fold turnFold rows []chatRow // ticking are the rows whose took still runs. ticking []int @@ -28,26 +29,25 @@ type chatRowCache struct { sent []string } -// rowsOf is chatRows, good until the next call, and the first row that may be +// rowsOf is fold's rows, good until the next call, and the first row that may be // another than the last call's, their times aside: len(rows) for none. -func (c *chatRowCache) rowsOf(items []backend.ChatItem, kind string, running bool, now time.Time) (rows []chatRow, changed int) { - if c.rows != nil && c.kind == kind && c.running == running && sameItems(c.items, items) { +func (c *chatRowCache) rowsOf(items []backend.ChatItem, kind string, running bool, now time.Time, fold turnFold) (rows []chatRow, changed int) { + moved := c.fold.checkout != fold.checkout + c.fold = fold + if c.rows != nil && !moved && c.kind == kind && c.running == running && sameItems(c.items, items) { for _, i := range c.ticking { c.rows[i].tick(now) } return c.rows, len(c.rows) } head := lastTurnStart(items) - if c.kind != kind || c.headItems != head || len(c.items) < head || !slices.EqualFunc(c.items[:head], items[:head], sameItem) { - c.rows, c.headDay = chatRowsAfter(time.Time{}, items[:head], kind, false, now) - if n := len(c.rows); n > 0 && c.rows[n-1].kind == chatRowDone { - c.rows = c.rows[:n-1] - } + if moved || c.kind != kind || c.headItems != head || len(c.items) < head || !slices.EqualFunc(c.items[:head], items[:head], sameItem) { + c.rows, c.headDay = fold.rows(time.Time{}, items[:head], kind, false, now) c.headItems, c.headRows = head, len(c.rows) } else { changed = c.headRows } - tail, _ := chatRowsAfter(c.headDay, items[head:], kind, running, now) + tail, _ := fold.rows(c.headDay, items[head:], kind, running, now) c.rows = append(c.rows[:c.headRows], tail...) c.items, c.kind, c.running = items, kind, running c.ticking = c.ticking[:0] @@ -70,7 +70,7 @@ func (c *chatRowCache) sentOf(items []backend.ChatItem) []string { // lastTurnStart is where the conversation's last turn begins when the turns // before it can be folded without it: 0 when turns are out of order, when it // opens with a call, whose row may join the one above, or when one before it -// still waits on the person, which the last turn's closing line looks at. +// still waits on the person, which keeps the last turn from folding. func lastTurnStart(items []backend.ChatItem) int { at := len(items) for at > 0 && items[at-1].Turn == items[len(items)-1].Turn { diff --git a/native/cmd/lich-native/chat_row_cache_test.go b/native/cmd/lich-native/chat_row_cache_test.go index 951f1a377..ef70b90ad 100644 --- a/native/cmd/lich-native/chat_row_cache_test.go +++ b/native/cmd/lich-native/chat_row_cache_test.go @@ -62,8 +62,8 @@ func TestChatRowCacheFollowsTheConversation(t *testing.T) { step.do() now := time.UnixMilli(at).Add(time.Duration(i) * time.Minute) items := s.of("s1") - rows, changed := c.rowsOf(items, claudeKind, running, now) - want := chatRows(items, claudeKind, running, now) + rows, changed := c.rowsOf(items, claudeKind, running, now, turnFold{}) + want, _ := turnFold{}.rows(time.Time{}, items, claudeKind, running, now) if !reflect.DeepEqual(rows, want) { t.Fatalf("%s: the rows kept are not the ones the conversation folds to:\n got %+v\nwant %+v", step.name, rows, want) } diff --git a/native/cmd/lich-native/chat_rows.go b/native/cmd/lich-native/chat_rows.go index 7c99e1dc3..8ee1d3780 100644 --- a/native/cmd/lich-native/chat_rows.go +++ b/native/cmd/lich-native/chat_rows.go @@ -13,13 +13,15 @@ import ( type chatRowKind uint8 const ( - chatRowItem chatRowKind = iota // one item as it is - chatRowWork // a run of tool calls between the agent's words, folded into one line - chatRowShell // the call of the person's shell command, its output under it - chatRowEdit // a call that changed a file, its diff under it, out of the turn's fold - chatRowLive // the turn in flight, unless a permission or a question says it waits - chatRowDay // the day a turn starts on, when it is not the day of the turn before - chatRowDone // the line that closes a finished turn + chatRowItem chatRowKind = iota // one item as it is + chatRowWork // a run of tool calls between the agent's words, folded into one line + chatRowShell // the call of the person's shell command, its output under it + chatRowEdit // a call that changed a file, its diff under it, out of the turn's fold + chatRowLive // the turn in flight, unless a permission or a question says it waits + chatRowDay // the day a turn starts on, when it is not the day of the turn before + chatRowDone // the line a finished turn's work is folded under + chatRowFiles // the head of the files a finished turn changed + chatRowFilesRest // the line that shows the rest of them ) // chatRow is one line of the chat view. @@ -43,23 +45,32 @@ type chatRow struct { ended int64 // turn, tools and took are a work row's: its tool calls and how long they // ran; a live row has the turn and how long it has run, and a done row the - // turn's calls and how long the turn took. + // turn and how long its work took. turn int tools []backend.ChatItem took time.Duration // since is when a row whose took still runs began, unix ms. since int64 - // refused marks a done row whose turn the provider refused for want of - // a login: it failed, whether or not the window heard its end. - refused bool - // run names a work row: its first call's id. + // reason is why a done row's turn stopped, and folds whether it has work + // folded under it. + reason string + folds bool + // tucked is the fold a row is drawn in only while open, "" for none. + tucked string + // foot marks the answer of a finished turn, whose time, model and copy + // stand under it. + foot bool + // count is how many files a files row stands for. + count int + // run names a work row by its first call's id, and is the key of the fold + // a done row and a files rest row open. run string - // Edit rows one after another with nothing between them read as one - // group: edits holds the group's calls on its first row, when there are - // two or more, and editAbove and editBelow mark a row that has another - // edit right above or under it. - edits []backend.ChatItem - editAbove, editBelow bool + // edits are the calls a files row, or the row of a file a finished turn + // changed, stands for. + edits []backend.ChatItem + // editAbove marks an edit row with another right above it, with nothing + // between them: they read as one group. + editAbove bool } // chatRun is one run of a turn's tool calls, from one of the agent's texts to @@ -71,7 +82,6 @@ type chatRun struct { type chatTurnSpan struct { start, end int64 - tools []backend.ChatItem // began is the first time any item of the turn carries, 0 for none: a // conversation read back from the provider may leave the person's message // without one, and its answer still tells the day. @@ -99,7 +109,6 @@ func chatRowsAfter(turnDay time.Time, items []backend.ChatItem, kind string, run items = slices.DeleteFunc(slices.Clone(items), isPlan) } spans := map[int]*chatTurnSpan{} - asked := map[int]bool{} shell := map[string]bool{} runsShell := slices.Contains(chatRunShellKinds, kind) var prev backend.ChatItem @@ -126,7 +135,6 @@ func chatRowsAfter(turnDay time.Time, items []backend.ChatItem, kind string, run } if it.Kind == api.ItemTool && !shell[it.ID] { if !isEdit(it) { - sp.tools = append(sp.tools, it) joinRun(runs, runOf, open, it) } if it.Tool != nil { @@ -136,7 +144,6 @@ func chatRowsAfter(turnDay time.Time, items []backend.ChatItem, kind string, run if it.Kind == api.ItemAgent || it.Kind == api.ItemUser { delete(open, it.Turn) } - asked[it.Turn] = asked[it.Turn] || it.Kind == api.ItemUser last = max(last, it.Turn) } rows := make([]chatRow, 0, len(items)+2) @@ -198,15 +205,6 @@ func chatRowsAfter(turnDay time.Time, items []backend.ChatItem, kind string, run rows = append(rows, work) rows = append(rows, fileRows(it)...) } - // The conversation's last turn, once it has ended, closes with a line of - // its own, unless it was the person's compaction, whose marker closes it; - // the person's next message takes it away. A question still - // waiting holds the turn open, whatever a window opened mid-turn heard. - if !running && len(items) > 0 && asked[last] && questionWaiting(items) == nil && !compactTurn(items, last) { - sp := spans[last] - rows = append(rows, chatRow{kind: chatRowDone, turn: last, tools: sp.tools, took: time.Duration(max(sp.end-sp.start, 0)) * time.Millisecond, - refused: slices.ContainsFunc(items, func(it backend.ChatItem) bool { return it.Turn == last && it.Kind == api.ItemNotice && it.Login })}) - } if running && permissionWaiting(items) == nil && questionWaiting(items) == nil { live := chatRow{kind: chatRowLive, turn: last, movable: movable(items), compacting: compactRunning(items)} if sp := spans[last]; sp != nil && sp.start > 0 && !now.IsZero() { @@ -225,22 +223,10 @@ func (r *chatRow) tick(now time.Time) { r.took = time.Duration(max(now.UnixMilli()-r.since, 0)) * time.Millisecond } -// markEditRuns sets edits, editAbove and editBelow on each run of edit rows -// that follow one another. +// markEditRuns sets editAbove on each edit row that follows another. func markEditRuns(rows []chatRow) { - for i := 0; i < len(rows); { - j := i - for rows[j].kind == chatRowEdit && j+1 < len(rows) && rows[j+1].kind == chatRowEdit { - rows[j].editBelow, rows[j+1].editAbove = true, true - j++ - } - if j > i { - rows[i].edits = make([]backend.ChatItem, 0, j-i+1) - for k := i; k <= j; k++ { - rows[i].edits = append(rows[i].edits, rows[k].item) - } - } - i = j + 1 + for i := 1; i < len(rows); i++ { + rows[i].editAbove = rows[i].kind == chatRowEdit && rows[i-1].kind == chatRowEdit } } @@ -337,7 +323,11 @@ func chatRowKey(r chatRow) string { case chatRowDay: return "day:" + strconv.Itoa(r.turn) case chatRowDone: - return "done:" + strconv.Itoa(r.turn) + return r.run + case chatRowFiles: + return "files:" + strconv.Itoa(r.turn) + case chatRowFilesRest: + return r.run case chatRowLive: return chatLiveKey } diff --git a/native/cmd/lich-native/chat_shell_test.go b/native/cmd/lich-native/chat_shell_test.go index ee589b438..b21efcb41 100644 --- a/native/cmd/lich-native/chat_shell_test.go +++ b/native/cmd/lich-native/chat_shell_test.go @@ -233,6 +233,7 @@ func TestAShellCommandsOutputIsShownWhole(t *testing.T) { {ID: "tool-2", Kind: api.ItemTool, Turn: 2, Tool: &api.ChatToolCall{Name: "Bash", Title: "git status", Output: "On branch main\nnothing to commit", State: api.ToolDone}}, {ID: "agent-2", Kind: api.ItemAgent, Text: "Clean.", Turn: 2}, }) + u.chats.pane("s1").fold("done:2").open = true r.now = r.now.Add(time.Second) r.frames(3) if !r.showsAll("AGENTS.md", "CLAUDE.md", " README.md") { diff --git a/native/cmd/lich-native/chat_turn_fold.go b/native/cmd/lich-native/chat_turn_fold.go new file mode 100644 index 000000000..1267ccb4d --- /dev/null +++ b/native/cmd/lich-native/chat_turn_fold.go @@ -0,0 +1,217 @@ +package main + +import ( + "slices" + "strconv" + "time" + + "github.com/lichdotdev/lich/api" + "github.com/lichdotdev/lich/native/backend" +) + +// chatFilesShown is how many of a turn's files show under its answer: a long +// list would push the answer out of view. +const chatFilesShown = 5 + +// turnFold is what folding finished turns takes besides their rows: how the +// turn called ended, "" when nobody said, and the checkout its files are in. +type turnFold struct { + stop func(turn int) string + checkout string +} + +// rows is chatRowsAfter with every finished turn folded. +func (f turnFold) rows(turnDay time.Time, items []backend.ChatItem, kind string, running bool, now time.Time) ([]chatRow, time.Time) { + rows, day := chatRowsAfter(turnDay, items, kind, running, now) + last := 0 + for _, it := range items { + last = max(last, it.Turn) + } + open := running || questionWaiting(items) != nil || permissionWaiting(items) != nil + pieces := map[int]int{} + for i, r := range rows { + if i == 0 || chatRowTurn(rows[i-1]) != chatRowTurn(r) { + pieces[chatRowTurn(r)]++ + } + } + out := make([]chatRow, 0, len(rows)+2) + for i := 0; i < len(rows); { + turn, j := chatRowTurn(rows[i]), i+1 + for j < len(rows) && chatRowTurn(rows[j]) == turn { + j++ + } + // A turn a late item split around another is left as it came. + if turn == last && open || pieces[turn] > 1 { + out = append(out, rows[i:j]...) + } else { + out = append(out, f.turn(rows[i:j], turn)...) + } + i = j + } + return out, day +} + +// turn folds one finished turn: each stretch of work between what the person +// said is tucked under a line of its own but for its answer, and the files the +// turn changed stand once each at its end. +func (f turnFold) turn(rows []chatRow, turn int) []chatRow { + reason := "" + if f.stop != nil { + reason = f.stop(turn) + } + // The marker of the person's compaction closes its turn, however it ended. + if slices.ContainsFunc(rows, func(r chatRow) bool { return isItemOf(r, api.ItemCompaction) && !r.item.Compaction.Auto }) { + reason = "" + } + if slices.ContainsFunc(rows, func(r chatRow) bool { return isItemOf(r, api.ItemNotice) && r.item.Login }) { + reason = stopError + } + out := make([]chatRow, 0, len(rows)+2) + var edits []backend.ChatItem + stretch := 0 + for i := 0; i <= len(rows); { + j := i + for j < len(rows) && !standsAlone(rows[j]) { + j++ + } + head := chatRow{kind: chatRowDone, turn: turn, run: "done:" + strconv.Itoa(turn)} + if stretch > 0 { + head.run += ":" + strconv.Itoa(stretch) + } + if j == len(rows) { + head.reason = reason + } + if i > 0 && isItemOf(rows[i-1], api.ItemUser) { + head.since = rows[i-1].item.At + } + at := len(out) + out, edits = foldStretch(out, edits, head, rows[i:j]) + if len(out) > at && out[at].kind == chatRowDone { + stretch++ + } + if j < len(rows) { + out = append(out, rows[j]) + } + i = j + 1 + } + return append(out, f.files(edits, turn)...) +} + +// foldStretch adds to out the stretch of work rows under head, left out when it +// has nothing to fold or to say, and to edits the calls that changed a file. +func foldStretch(out []chatRow, edits []backend.ChatItem, head chatRow, rows []chatRow) ([]chatRow, []backend.ChatItem) { + first, last := answerOf(rows) + at := len(out) + out = append(out, head) + began, ended := int64(0), int64(0) + for i, r := range rows { + from, to := rowSpan(r) + if from > 0 && (began == 0 || from < began) { + began = from + } + ended = max(ended, to) + if r.kind == chatRowEdit && r.item.Tool.State != api.ToolFailed && !callRunning(r.item) { + edits = append(edits, r.item) + continue + } + answer := i >= first && i <= last + r.foot = answer && !r.more + if !answer && tucks(r) { + r.tucked, head.folds = head.run, true + } + out = append(out, r) + } + if head.since > 0 { + began = head.since + } + if began > 0 { + head.took = time.Duration(max(ended-began, 0)) * time.Millisecond + } + head.since = 0 + if !head.folds && head.reason != stopCancelled && head.reason != stopError { + return slices.Delete(out, at, at+1), edits + } + out[at] = head + return out, edits +} + +// answerOf is the last run of the agent's texts in rows, first after last for +// none. +func answerOf(rows []chatRow) (first, last int) { + for i, row := range slices.Backward(rows) { + if !isItemOf(row, api.ItemAgent) { + continue + } + first = i + for first > 0 && rows[first-1].more { + first-- + } + return first, i + } + return 0, -1 +} + +func isItemOf(r chatRow, kind string) bool { return r.kind == chatRowItem && r.item.Kind == kind } + +// standsAlone is whether r is the person's or marks the conversation, and so +// ends a stretch of work: a message, an answer to a question, their command, a +// day or a compaction. +func standsAlone(r chatRow) bool { + return r.kind == chatRowDay || r.kind == chatRowShell || + isItemOf(r, api.ItemUser) || isItemOf(r, api.ItemQuestion) || isItemOf(r, api.ItemCompaction) +} + +// tucks is whether r is the agent's way to its answer. A notice is lich's or +// the provider's word to the person, and is never hidden. +func tucks(r chatRow) bool { + return r.kind == chatRowWork || r.kind == chatRowEdit || isItemOf(r, api.ItemAgent) || isItemOf(r, api.ItemThought) || isItemOf(r, api.ItemPermission) +} + +// rowSpan is when r began and ended, unix ms, 0 for unknown. +func rowSpan(r chatRow) (from, to int64) { + if r.kind == chatRowWork { + return r.since, r.ended + } + from, to = r.item.At, r.item.At + if r.item.Tool != nil { + to = max(to, r.item.Tool.Ended) + } + return from, to +} + +// files are the rows of what a turn's edits changed: one a file with all its +// edits, under a head when there are several, those past chatFilesShown +// behind a line that shows them. +func (f turnFold) files(edits []backend.ChatItem, turn int) []chatRow { + var paths []string + of := map[string][]backend.ChatItem{} + for _, it := range edits { + p := editPath(it.Tool, f.checkout) + if of[p] == nil { + paths = append(paths, p) + } + of[p] = append(of[p], it) + } + n := strconv.Itoa(turn) + var rows []chatRow + if len(paths) > 1 { + rows = append(rows, chatRow{kind: chatRowFiles, turn: turn, edits: edits, count: len(paths)}) + } + // One more is as tall as the line that would hide it. + shown := len(paths) + if shown > chatFilesShown+1 { + shown = chatFilesShown + } + for i, p := range paths { + r := chatRow{kind: chatRowEdit, turn: turn, edits: of[p], editAbove: len(paths) > 1, + item: backend.ChatItem{ID: "changed:" + n + "#" + p, Kind: api.ItemTool, Turn: turn, Tool: of[p][0].Tool}} + if i >= shown { + r.tucked = "files-rest:" + n + } + rows = append(rows, r) + } + if hidden := len(paths) - shown; hidden > 0 { + rows = append(rows, chatRow{kind: chatRowFilesRest, turn: turn, run: "files-rest:" + n, count: hidden, editAbove: true}) + } + return rows +} diff --git a/native/cmd/lich-native/chat_turn_fold_test.go b/native/cmd/lich-native/chat_turn_fold_test.go new file mode 100644 index 000000000..2c13d2ef0 --- /dev/null +++ b/native/cmd/lich-native/chat_turn_fold_test.go @@ -0,0 +1,292 @@ +package main + +import ( + "fmt" + "slices" + "strconv" + "strings" + "testing" + "time" + + "github.com/lichdotdev/lich/api" + "github.com/lichdotdev/lich/native/backend" + "github.com/lichdotdev/lich/native/i18n" +) + +// endedRows is items as the view draws them once their turns are folded, the +// last one having stopped for stop. +func endedRows(items []backend.ChatItem, running bool, stop string) []chatRow { + rows, _ := turnFold{stop: func(turn int) string { + if turn == items[len(items)-1].Turn { + return stop + } + return "" + }, checkout: "/repo"}.rows(time.Time{}, items, claudeKind, running, time.UnixMilli(1<<40)) + return rows +} + +// drawRows names each row, the ones a shut fold hides in brackets. +func drawRows(rows []chatRow) []string { + var out []string + for _, r := range rows { + s := chatRowKey(r) + if r.kind == chatRowDone { + s += " " + chatDoneLabel(r.reason, r.took) + } + if r.foot { + s += " foot" + } + if r.tucked != "" { + s = "[" + s + "]" + } + out = append(out, s) + } + return out +} + +func turnItem(turn int, id, kind string, sec int64) backend.ChatItem { + return backend.ChatItem{ID: id, Kind: kind, Turn: turn, At: sec * 1000, Text: id} +} + +func turnCall(turn int, id, state string, sec int64) backend.ChatItem { + it := turnItem(turn, id, api.ItemTool, sec) + it.Text, it.Tool = "", &backend.ChatToolCall{Name: "Bash", Title: id, State: state, Ended: sec*1000 + 500} + return it +} + +func turnEdit(turn int, id, path, state string, sec int64) backend.ChatItem { + it := turnCall(turn, id, state, sec) + it.Tool.Name, it.Tool.Diff = "Edit", "--- a"+path+"\n+++ b"+path+"\n@@ -1 +1,2 @@\n-a\n+b\n+c\n" + return it +} + +func TestAFinishedTurnFoldsToItsAnswerAndItsFiles(t *testing.T) { + user := turnItem(1, "u", api.ItemUser, 10) + answered := turnItem(1, "q", api.ItemQuestion, 30) + answered.Question = &backend.ChatQuestion{Reply: &api.ChatQReplied{}} + login := turnItem(1, "n", api.ItemNotice, 12) + login.Login = true + for name, c := range map[string]struct { + items []backend.ChatItem + running bool + stop string + want []string + }{ + "the way to the answer": { + items: []backend.ChatItem{user, turnItem(1, "a1", api.ItemAgent, 11), turnCall(1, "k1", api.ToolDone, 12), turnItem(1, "th", api.ItemThought, 13), + turnItem(1, "a2", api.ItemAgent, 14), turnItem(1, "a3", api.ItemAgent, 76)}, + want: []string{"u", "done:1 Worked for 1m 6s", "[a1]", "[work:k1]", "[th]", "a2", "a3 foot"}, + }, + "while it runs nothing folds": { + items: []backend.ChatItem{user, turnItem(1, "a1", api.ItemAgent, 11), turnCall(1, "k1", api.ToolDone, 12), turnItem(1, "a2", api.ItemAgent, 14)}, + running: true, want: []string{"u", "a1", "work:k1", "a2", "live"}, + }, + "an answer alone": {items: []backend.ChatItem{user, turnItem(1, "a", api.ItemAgent, 11)}, want: []string{"u", "a foot"}}, + "each file once, under the answer": { + items: []backend.ChatItem{user, turnEdit(1, "e1", "/x.go", api.ToolDone, 11), turnItem(1, "a1", api.ItemAgent, 12), + turnEdit(1, "e2", "/y.go", api.ToolDone, 13), turnEdit(1, "e3", "/x.go", api.ToolDone, 14), turnEdit(1, "e4", "/z.go", api.ToolFailed, 15), turnItem(1, "a2", api.ItemAgent, 16)}, + want: []string{"u", "done:1 Worked for 6s", "[a1]", "[e4]", "a2 foot", "files:1", "changed:1#x.go", "changed:1#y.go"}, + }, + "one file has no head": {items: []backend.ChatItem{user, turnEdit(1, "e1", "/x.go", api.ToolDone, 11), turnItem(1, "a", api.ItemAgent, 12)}, + want: []string{"u", "a foot", "changed:1#x.go"}}, + "what the person said mid turn stays, and parts the work": { + items: []backend.ChatItem{user, turnCall(1, "k1", api.ToolDone, 11), turnItem(1, "a1", api.ItemAgent, 12), answered, + turnCall(1, "k2", api.ToolDone, 40), turnItem(1, "u2", api.ItemUser, 50), turnCall(1, "k3", api.ToolDone, 55), turnItem(1, "a2", api.ItemAgent, 60)}, + want: []string{"u", "done:1 Worked for 2s", "[work:k1]", "a1 foot", "q", "done:1:1 Worked", "[work:k2]", "u2", "done:1:2 Worked for 10s", "[work:k3]", "a2 foot"}, + }, + "stopped with nothing said": {items: []backend.ChatItem{user, turnCall(1, "k1", api.ToolRunning, 50)}, stop: stopCancelled, + want: []string{"u", "done:1 Stopped after 40s", "[work:k1]"}}, + "stopped with nothing done": {items: []backend.ChatItem{user}, stop: stopCancelled, want: []string{"u", "done:1 Stopped"}}, + "failed": {items: []backend.ChatItem{user, turnItem(1, "n", api.ItemNotice, 22)}, stop: stopError, want: []string{"u", "done:1 Failed after 12s", "n"}}, + "refused for want of a login, whether or not its end was heard": {items: []backend.ChatItem{user, login}, want: []string{"u", "done:1 Failed after 2s", "n"}}, + "the turns before one running": { + items: []backend.ChatItem{user, turnCall(1, "k1", api.ToolDone, 11), turnItem(1, "a1", api.ItemAgent, 12), turnItem(2, "u2", api.ItemUser, 20), turnCall(2, "k2", api.ToolDone, 21), turnItem(2, "a2", api.ItemAgent, 22)}, + running: true, want: []string{"u", "done:1 Worked for 2s", "[work:k1]", "a1 foot", "u2", "work:k2", "a2", "live"}, + }, + "a turn a late item split is left as it came": { + items: []backend.ChatItem{user, turnCall(1, "k1", api.ToolDone, 11), turnItem(1, "a1", api.ItemAgent, 12), turnItem(2, "u2", api.ItemUser, 20), turnItem(1, "late", api.ItemAgent, 21)}, + want: []string{"u", "work:k1", "a1", "u2", "late"}, + }, + "no times read back": {items: []backend.ChatItem{{ID: "u", Kind: api.ItemUser, Turn: 1}, {ID: "k", Kind: api.ItemTool, Turn: 1, Tool: &backend.ChatToolCall{Name: "Bash", State: api.ToolDone}}, {ID: "a", Kind: api.ItemAgent, Turn: 1}}, + want: []string{"u", "done:1 Worked", "[work:k]", "a foot"}}, + } { + if got := drawRows(endedRows(c.items, c.running, c.stop)); !slices.Equal(got, c.want) { + t.Errorf("%s:\n got %q\nwant %q", name, got, c.want) + } + } +} + +// A waiting permission or question holds its turn open. +func TestATurnThatWaitsOnThePersonDoesNotFold(t *testing.T) { + ask := turnItem(1, "p", api.ItemPermission, 12) + ask.Permission = &backend.ChatPermission{} + items := []backend.ChatItem{turnItem(1, "u", api.ItemUser, 10), turnCall(1, "k", api.ToolDone, 11), ask} + if got, want := drawRows(endedRows(items, false, "")), []string{"u", "work:k", "p"}; !slices.Equal(got, want) { + t.Errorf("got %q, want %q", got, want) + } +} + +func TestALongListOfFilesShowsItsFirstOnes(t *testing.T) { + files := func(n int) []string { + items := []backend.ChatItem{turnItem(1, "u", api.ItemUser, 10)} + for i := range n { + items = append(items, turnEdit(1, "e"+strconv.Itoa(i), fmt.Sprintf("/f%d.go", i), api.ToolDone, 11)) + } + return drawRows(endedRows(items, false, ""))[2:] + } + if got := files(chatFilesShown + 1); strings.Contains(strings.Join(got, " "), "rest") || len(got) != chatFilesShown+1 { + t.Errorf("one file past the cap: %q, want it shown, not a line in its place", got) + } + got := files(chatFilesShown + 2) + want := []string{"changed:1#f0.go", "changed:1#f1.go", "changed:1#f2.go", "changed:1#f3.go", "changed:1#f4.go", "[changed:1#f5.go]", "[changed:1#f6.go]", "files-rest:1"} + if !slices.Equal(got, want) { + t.Errorf("got %q, want %q", got, want) + } +} + +// foldFrames is a chat of one turn running, of a text and a call a step and a +// file written. Markdown has no label to find it by: the file's row, which +// stands under the answer once the turn ends, tells the answer is in view. +func foldFrames(t *testing.T, calls int) (*window, *frameRig) { + t.Helper() + items := []backend.ChatItem{ + {ID: "ask", Kind: api.ItemUser, Turn: 1, At: novDay(18, 17, 50), Text: "go"}, + } + for i := range calls { + n := strconv.Itoa(i) + items = append(items, + backend.ChatItem{ID: "m" + n, Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 51), Text: "step " + n}, + backend.ChatItem{ID: "k" + n, Kind: api.ItemTool, Turn: 1, At: novDay(18, 17, 51), Tool: &backend.ChatToolCall{Name: "Bash", Title: "cmd-" + n, State: api.ToolDone}}) + } + write := turnEdit(1, "w", "/out.go", api.ToolDone, 0) + write.At, write.Tool.Ended = novDay(18, 17, 51), novDay(18, 17, 51) + items = append(items, write, backend.ChatItem{ID: "a1", Kind: api.ItemAgent, Turn: 1, At: novDay(18, 17, 52), Text: "the answer"}) + return lifeFrames(t, items, true) +} + +// The turn ending folds its work away and leaves the answer; a click on the +// line shows it, in order and over the answer, and another hides it. +func TestTheTurnEndingFoldsItsWorkAndAClickShowsIt(t *testing.T) { + u, r := foldFrames(t, 2) + r.play(20) + if !r.shows("cmd-0") || !r.shows("cmd-1") || r.shows("Worked for 2m 0s") { + t.Fatalf("the work of a turn running is not in view:\n%s", r.drawn()) + } + u.model.chat.turn(api.ChatTurn{SessionID: "s1", StopReason: "end_turn"}) + r.frame() + r.play(3) + if !r.shows("cmd-0") { + t.Error("the work left at once: it does not fold") + } + r.settle(t) + if r.shows("cmd-0") || r.shows("cmd-1") || !r.shows("out.go") || !r.shows("Worked for 2m 0s") { + t.Fatalf("a finished turn is not its line and its answer:\n%s", r.drawn()) + } + r.clickLabel(t, "Worked for 2m 0s") + r.settle(t) + line, step, call, answer := labelTop(t, r, "Worked for 2m 0s"), labelTop(t, r, "cmd-0"), labelTop(t, r, "cmd-1"), labelTop(t, r, "out.go") + if !(line < step && step < call && call < answer) { + t.Errorf("line at y=%d, first call %d, second %d, answer's file %d: want them in order", line, step, call, answer) + } + r.clickLabel(t, "Worked for 2m 0s") + r.settle(t) + if r.shows("cmd-0") || !r.shows("out.go") { + t.Errorf("a second click left the work open:\n%s", r.drawn()) + } +} + +// Work taller than the view opens under its line: at the end of the +// conversation the list would otherwise push the line it was clicked on away. +func TestOpenedWorkTallerThanTheViewKeepsItsLineInView(t *testing.T) { + for name, turns := range map[string]int{"a conversation that fit the view": 0, "one already past it": 30} { + for _, steps := range []int{chatMoved / 4, chatMoved} { + u, r := foldFrames(t, steps) + items := userTurns(turns) + for i := range items { + items[i].Turn -= turns + } + u.model.chat.history("s1", append(items, u.model.chat.of("s1")...)) + u.model.chat.turn(api.ChatTurn{SessionID: "s1", StopReason: "end_turn"}) + r.settle(t) + was := labelTop(t, r, "Worked for 2m 0s") + r.clickLabel(t, "Worked for 2m 0s") + r.settle(t) + if !r.shows("Worked for 2m 0s") || !r.shows("cmd-0") || r.shows("out.go") { + t.Fatalf("%s, %d steps: the opened work does not stand under its line:\n%s", name, steps, r.drawn()) + } + if at := labelTop(t, r, "Worked for 2m 0s"); turns > 0 && abs(at-was) > 2 { + t.Errorf("%s, %d steps: the line moved from y=%d to %d when clicked", name, steps, was, at) + } + r.clickLabel(t, "Worked for 2m 0s") + r.settle(t) + if !r.shows("out.go") { + t.Errorf("%s, %d steps: shut again, the answer is not in view:\n%s", name, steps, r.drawn()) + } + } + } +} + +// A person scrolled up in the turn's work when it ends keeps reading it. +func TestATurnThatEndsWhileReadStaysOpenWhereItWas(t *testing.T) { + u, r := foldFrames(t, 30) + r.play(20) + p := u.chats.pane("s1") + p.list.Position.First, p.list.Position.Offset, p.list.Position.BeforeEnd = 21, 0, true + r.play(3) + was := labelTop(t, r, "cmd-12") + u.model.chat.turn(api.ChatTurn{SessionID: "s1", StopReason: "end_turn"}) + r.settle(t) + if at := labelTop(t, r, "cmd-12"); !r.shows("cmd-12") || abs(at-was) > 24 { + t.Errorf("the step being read went from y=%d to %d:\n%s", was, at, r.drawn()) + } + if !p.fold("done:1").open { + t.Error("the turn folded under the person's eyes") + } +} + +// The way to the answer reads muted, and the answer's foot is its own: the +// texts over it keep no empty line for one. +func TestOnlyTheAnswerKeepsAFoot(t *testing.T) { + u, r := foldFrames(t, 1) + u.model.chat.turn(api.ChatTurn{SessionID: "s1", StopReason: "end_turn"}) + u.chats.pane("s1").fold("done:1").open = true + r.settle(t) + overAnswer(r, t, clockFor(r, novDay(18, 17, 52))) + if !r.shows(clockFor(r, novDay(18, 17, 52))) { + t.Errorf("no time under the answer the pointer is over:\n%s", r.drawn()) + } + if h := u.chats.pane("s1").heights; h["m0"] >= h["a1"] { + t.Errorf("a step is %dpx tall and the answer %d: the step keeps room for a foot", h["m0"], h["a1"]) + } +} + +func TestEveryLanguageSaysHowATurnEnded(t *testing.T) { + defer i18n.SetCurrent(i18n.EN) + for _, l := range i18n.Locales { + i18n.SetCurrent(l) + seen := map[string]bool{} + for _, reason := range []string{"end_turn", stopCancelled, stopError} { + for _, took := range []time.Duration{0, 48 * time.Second} { + s := chatDoneLabel(reason, took) + if s == "" || seen[s] || strings.Contains(s, "{") { + t.Errorf("%s: a turn that stopped for %q after %v reads %q", l, reason, took, s) + } + seen[s] = true + } + } + } +} + +// A file edited by a tool and by a shell command opens on both edits: git's +// diff and a provider's, which has no line of git's, one after the other. +func TestAFilesEditsOpenTogether(t *testing.T) { + tool := turnEdit(1, "e1", "/x.go", api.ToolDone, 11) + shell := turnEdit(1, "e2", "/x.go", api.ToolDone, 12) + shell.Tool.Diff = gitPatch(shell.Tool.Diff) + for _, edits := range [][]backend.ChatItem{{tool, shell}, {shell, tool}} { + files, err := parsePatchFiles(gitPatch(joinDiffs(edits))) + if err != nil || len(files) != 2 { + t.Errorf("%d diffs read of two edits, %v", len(files), err) + } + } +} diff --git a/native/cmd/lich-native/chat_veto_test.go b/native/cmd/lich-native/chat_veto_test.go index 23f43643e..368b27a44 100644 --- a/native/cmd/lich-native/chat_veto_test.go +++ b/native/cmd/lich-native/chat_veto_test.go @@ -20,8 +20,10 @@ func TestAVetoedCallIsDrawnAsOpened(t *testing.T) { } u, r := envelopeRig(t, items) u.model.vetoes.add(api.SubagentVeto{SessionID: "s1", ToolUseID: "toolu_1", Sessions: []api.SubagentOpened{{ID: "s2", Label: "Fix #412", Ticket: "4b9bc94e"}}}) - r.frame() - if r.shows("· 2 failed") || !r.shows("· 1 failed") { + p := u.chats.pane("s1") + p.fold("done:1").open, p.refold = true, true + r.frames(3) + if r.shows("2 failed") || !r.shows("1 failed") { t.Errorf("the group counts the vetoed call as failed:\n%s", r.drawn()) } r.clickLabel(t, "Read 1 file, used 1 other tool") diff --git a/native/cmd/lich-native/chat_view.go b/native/cmd/lich-native/chat_view.go index 2c9d83710..0198d6da9 100644 --- a/native/cmd/lich-native/chat_view.go +++ b/native/cmd/lich-native/chat_view.go @@ -35,6 +35,9 @@ var ( // edges, so its text lines up inside the box rather than with its border. chatTextInset = ui.Space(4) chatRowGap = ui.Space(3.5) + // chatPartGap is the room over a finished turn's answer when its work is + // open above it, and over the files it changed. + chatPartGap = ui.Space(5) // The room before an answer's first row, under the person's message, and // before a turn starts, in the person's message or the day line over it: // the turn's rhythm approved in review (2026-11), max(32, 1.8×B) and @@ -82,17 +85,17 @@ type chatView struct { // last was, for one that is playing its exit. rows ui.Presence seen map[string]chatRow - // drawn are this frame's rows, which a message's menu copies up to it. - drawn []chatRow // folded keeps the rows, and shown the keys enter answered for them, nil // to work them out again. folded chatRowCache shown []string - // keys are the rows of the frame before, swap the live line turning into - // the closing line, run the list's way back to its end, and anchored the - // message that started the turn, held near the top of the view. + // refold says a fold of the list's own rows was turned, and held that the + // list stays on the line that opened one while its rows come in. + refold, held bool + // keys are the rows of the frame before, run the list's way back to its + // end, and anchored the message that started the turn, held near the top + // of the view. keys []string - swap chatSwap run chatToEnd anchored chatAnchor // jump is the pill that runs the list back to its end. @@ -260,7 +263,7 @@ func (v *chatView) stamp(id string) *ui.Tooltip { // // changed is the first row that may be another than the last call's. func (v *chatView) enter(now time.Time, rows []chatRow, read bool, changed int) []string { - if read && v.shown != nil && v.keepsKeys(rows, changed) && !v.rows.Moving() { + if read && v.shown != nil && !v.refold && v.keepsKeys(rows, changed) && !v.rows.Moving() { for _, i := range v.folded.ticking { v.seen[v.keys[i]] = rows[i] } @@ -269,7 +272,8 @@ func (v *chatView) enter(now time.Time, rows []chatRow, read bool, changed int) } return v.shown } - v.shown = nil + was := v.shown + v.shown, v.refold = nil, false if v.seen == nil { v.seen = map[string]chatRow{} } @@ -280,29 +284,38 @@ func (v *chatView) enter(now time.Time, rows []chatRow, read bool, changed int) } before := v.keys v.keys = keys + if slices.Contains(before, chatLiveKey) && v.list.ScrollToEnd && v.list.Position.BeforeEnd { + v.leaveOpen(rows, before) + } + drawn := make([]string, 0, len(keys)) + for i, r := range rows { + if r.tucked == "" || v.fold(r.tucked).open { + drawn = append(drawn, keys[i]) + } + } if !read { - return keys + return drawn } // A conversation replaced whole, by /new or a history read again on // another, lands as it is rather than playing every old row out. if len(before) > 0 && !slices.ContainsFunc(keys, func(k string) bool { return slices.Contains(before, k) }) { v.rows = ui.Presence{} } - shown := v.rows.Update(now, keys) - // The turn ending turns the live line into the closing line in its slot: - // neither plays its own motion. - if done := lastKey(keys); strings.HasPrefix(done, "done:") && slices.Contains(before, chatLiveKey) && !slices.Contains(before, done) { - v.rows.Settle(done) - v.swap = chatSwap{key: done, at: now, live: v.seen[chatLiveKey]} - } - // The closing line plays no exit: while it fades, the turn that took it - // away is drawn under it, and it would stand beside that turn's live line. - v.shown = slices.DeleteFunc(shown, func(k string) bool { - return v.rows.Leaving(k) && (strings.HasPrefix(k, "done:") || k == chatLiveKey && v.swap.playing(now)) - }) + v.shown = v.dry(was, v.rows.Update(now, drawn)) + v.keepPlace(was, v.shown) return v.shown } +// leaveOpen opens the folds of the turn that just ended, the ones not among +// before: the person is up reading it, and it would fold under their eyes. +func (v *chatView) leaveOpen(rows []chatRow, before []string) { + for _, r := range rows { + if r.kind == chatRowDone && !slices.Contains(before, r.run) { + v.fold(r.run).open = true + } + } +} + // keepsKeys is whether rows, the same up to changed, go by the keys of the // last call. func (v *chatView) keepsKeys(rows []chatRow, changed int) bool { @@ -317,14 +330,6 @@ func (v *chatView) keepsKeys(rows []chatRow, changed int) bool { return true } -// lastKey is the last of keys, "" for none. -func lastKey(keys []string) string { - if len(keys) == 0 { - return "" - } - return keys[len(keys)-1] -} - // rowTop is where row i of shown sits in the viewport, from the list's // position and the heights its rows last measured. func (v *chatView) rowTop(shown []string, i int) int { @@ -386,8 +391,10 @@ func (u *window) chatScreen(gtx C, sv sessionView, keys bool) { // session reports itself busy while its chat opens, and can stay so. u.backdrops.stirOf(sv.ID).keep(gtx.Now, u.model.chat.isRunning(sv.ID), p.editor.Len(), p.start.empty) u.chatActs(gtx, p, sv, keys, working, permissionWaiting(items), questionWaiting(items)) - rows, changed := p.folded.rowsOf(items, sv.Kind, working, gtx.Now) - p.drawn = rows + rows, changed := p.folded.rowsOf(items, sv.Kind, working, gtx.Now, turnFold{checkout: sv.path, stop: func(turn int) string { + end, _ := u.model.chat.endOf(sv.ID, turn) + return end.StopReason + }}) u.terms.readLinkKey(gtx) p.paths = u.chatPaths(p, sv, len(items)) th := u.theme.On(u.theme.Background) @@ -472,9 +479,10 @@ func (u *window) chatScreen(gtx C, sv sessionView, keys bool) { // Once the conversation outgrows the view, where nobody could have // scrolled it, it goes to its end and stays there until scrolled up. if over := p.list.Position.Length-lead > gtx.Constraints.Max.Y; over != p.list.ScrollToEnd { - p.list.ScrollToEnd, p.list.Position.BeforeEnd = over, false + p.list.ScrollToEnd, p.list.Position.BeforeEnd = over, over && p.held gtx.Execute(op.InvalidateCmd{}) } + p.held = p.held && (p.refold || p.rows.Moving()) return d } composer := func(gtx C) D { @@ -890,8 +898,11 @@ func chatRowTop(gtx C, r, prev chatRow) unit.Dp { switch { case startsTurn(r, prev): return max(chatTurnGapMin, chatTurnGapLines*body) - case r.editAbove: + // The answer's foot, empty at rest, is already the room over the files. + case r.editAbove, prev.foot && (r.kind == chatRowFiles || r.kind == chatRowEdit): return 0 + case r.kind == chatRowFiles, prev.tucked != "" && r.tucked == "": + return chatPartGap case prev.kind == chatRowItem && prev.item.Kind == api.ItemUser && (r.kind != chatRowItem || r.item.Kind != api.ItemUser): return max(chatAnswerGapMin, chatAnswerGapLines*body) } diff --git a/native/cmd/lich-native/chat_view_test.go b/native/cmd/lich-native/chat_view_test.go index effee9522..58633e23a 100644 --- a/native/cmd/lich-native/chat_view_test.go +++ b/native/cmd/lich-native/chat_view_test.go @@ -178,6 +178,7 @@ func TestAToolFoldOpensInTheFrameThatTookTheClick(t *testing.T) { {ID: "t0", Kind: api.ItemTool, Turn: 1, At: 2000, Tool: &backend.ChatToolCall{Name: "Read", Title: "tax.go", State: api.ToolDone}}, {ID: "t1", Kind: api.ItemTool, Turn: 1, At: 3000, Tool: &backend.ChatToolCall{Name: "Grep", Title: "roundTax", State: api.ToolDone, Output: "4 results"}}, }) + u.chats.pane("s1").fold("done:1").open = true r.clickLabel(t, "Read 1 file, searched 1 time") // The fold opens over ui.Collapse's 200ms, from the frame that took the // click: half way through, its call is already drawn. diff --git a/native/cmd/lich-native/login_offer_test.go b/native/cmd/lich-native/login_offer_test.go index 31e519261..227c0a8f3 100644 --- a/native/cmd/lich-native/login_offer_test.go +++ b/native/cmd/lich-native/login_offer_test.go @@ -97,7 +97,7 @@ func TestALoginNoticeLogsTheSessionsProfileIn(t *testing.T) { } // TestATurnRefusedForALoginEndsFailed: the turn a login notice closes ends on -// the failure mark, live and read back with the history once the window +// Failed, live and read back with the history once the window // reopened, which heard no end. func TestATurnRefusedForALoginEndsFailed(t *testing.T) { refused := []backend.ChatItem{ @@ -113,7 +113,7 @@ func TestATurnRefusedForALoginEndsFailed(t *testing.T) { u.model.chat.turn(api.ChatTurn{SessionID: "s1", StopReason: stopError}) } r.settle(t) - if !r.shows(i18n.T("chat.done.failed")) || r.shows(i18n.T("chat.done.done")) { + if !r.shows(i18n.T("chat.done.failed")) { t.Errorf("live %v: the refused turn does not end failed:\n%s", live, r.drawn()) } } diff --git a/native/cmd/lich-native/settings_themes_cover.go b/native/cmd/lich-native/settings_themes_cover.go index 80009d7d5..6944d24d7 100644 --- a/native/cmd/lich-native/settings_themes_cover.go +++ b/native/cmd/lich-native/settings_themes_cover.go @@ -129,8 +129,7 @@ func coverCode(t themeLook) [][]inkSpan { } } -// doneLine is a turn's end as the chat draws it: the check, then the lines it -// added and removed in the theme's tones. +// doneLine shows the theme's tones: a check, then lines added and removed. func doneLine(gtx C, th *ui.Theme, p ui.Palette, size, leading unit.Sp) D { return layout.Flex{Alignment: layout.Middle}.Layout(gtx, layout.Rigid(func(gtx C) D { diff --git a/native/cmd/lich-native/settings_themes_preview.go b/native/cmd/lich-native/settings_themes_preview.go index a963419ca..17010fabf 100644 --- a/native/cmd/lich-native/settings_themes_preview.go +++ b/native/cmd/lich-native/settings_themes_preview.go @@ -151,8 +151,8 @@ func previewRow(gtx C, bg color.NRGBA, w layout.Widget) D { return D{Size: size} } -// previewStage is a session's chat: the person's bubble, the agent's answer -// with its code, the Done line, the terminal's colors and the composer. +// previewStage is a session's chat: the person's bubble, the line of the turn's +// work, the agent's answer with its code, the terminal's colors and the composer. func previewStage(gtx C, th *ui.Theme, t themeLook) D { p := t.palette gap := layout.Rigid(layout.Spacer{Height: previewStageGap}.Layout) @@ -169,6 +169,8 @@ func previewStage(gtx C, th *ui.Theme, t themeLook) D { gap, layout.Rigid(func(gtx C) D { return previewAgentLine(gtx, th, p) }), gap, + layout.Rigid(th.Text(previewText, chatDoneLabel("", previewTook)).In(p.MutedForeground).Layout), + gap, layout.Rigid(text(i18n.T("settings.themesPage.preview.reply")).Wrapped().Layout), gap, layout.Rigid(func(gtx C) D { @@ -178,8 +180,6 @@ func previewStage(gtx C, th *ui.Theme, t themeLook) D { }) }), gap, - layout.Rigid(func(gtx C) D { return previewDone(gtx, th, p) }), - gap, layout.Rigid(func(gtx C) D { return previewTerminal(gtx, th, t) }), layout.Flexed(1, func(gtx C) D { return layout.S.Layout(gtx, func(gtx C) D { return previewComposer(gtx, th, p) }) @@ -211,22 +211,8 @@ func previewCode(t themeLook) [][]inkSpan { } } -// The preview turn's calls and how long it took. -const ( - previewCalls = 14 - previewTook = 6*time.Minute + 4*time.Second -) - -// previewDone is the turn's end as the chat closes it: Done, then its calls -// and time muted. -func previewDone(gtx C, th *ui.Theme, p ui.Palette) D { - work := i18n.T("chat.view.toolCalls", i18n.Args{"count": previewCalls}) + " · " + chatTook(previewTook) - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(th.Text(previewText, i18n.T("chat.done.done")).In(p.Foreground).Weight(font.Medium).Layout), - ui.Gap(2), - layout.Rigid(th.Text(previewText, "· "+work).In(p.MutedForeground).Layout), - ) -} +// previewTook is how long the preview's turn worked. +const previewTook = 6*time.Minute + 4*time.Second // previewTerminal is a test run in the terminal's colors over a swatch of all // sixteen. diff --git a/native/i18n/locales/en/chat.json b/native/i18n/locales/en/chat.json index 8af084b58..520bde6f5 100644 --- a/native/i18n/locales/en/chat.json +++ b/native/i18n/locales/en/chat.json @@ -104,7 +104,6 @@ }, "latest": "Latest", "newActivity": "New activity", - "edited": "Edited", "lich": { "openedSession": "Opened session", "openingSession": "Opening session", @@ -140,7 +139,18 @@ "done": "Done", "stopped": "Stopped", "failed": "Failed", - "noChanges": "no changes" + "workedFor": "Worked for {time}", + "worked": "Worked", + "stoppedAfter": "Stopped after {time}", + "failedAfter": "Failed after {time}", + "changed": { + "one": "Changed {count} file", + "other": "Changed {count} files" + }, + "moreFiles": { + "one": "Show {count} more file", + "other": "Show {count} more files" + } }, "composer": { "placeholder": "Ask {provider} about this project", @@ -225,7 +235,10 @@ }, "queue": { "sendNow": "Send now", - "count": {"one": "{count} queued", "other": "{count} queued"}, + "count": { + "one": "{count} queued", + "other": "{count} queued" + }, "drop": "Remove from the queue", "edit": "edit" }, diff --git a/native/i18n/locales/en/session.json b/native/i18n/locales/en/session.json index 126fe8c1e..d3426d0c7 100644 --- a/native/i18n/locales/en/session.json +++ b/native/i18n/locales/en/session.json @@ -39,7 +39,6 @@ }, "age": { "second": "{count}s", - "millisecond": "{count}ms", "minute": "{count}m", "hour": "{count}h", "day": "{count}d", diff --git a/native/i18n/locales/es/chat.json b/native/i18n/locales/es/chat.json index fcbbec3f1..05d66d77d 100644 --- a/native/i18n/locales/es/chat.json +++ b/native/i18n/locales/es/chat.json @@ -104,7 +104,6 @@ }, "latest": "Lo último", "newActivity": "Novedades", - "edited": "Editados", "lich": { "openedSession": "Abrió sesión", "openingSession": "Abriendo sesión", @@ -140,7 +139,18 @@ "done": "Hecho", "stopped": "Detenido", "failed": "Falló", - "noChanges": "sin cambios" + "workedFor": "Trabajó durante {time}", + "worked": "Trabajo", + "stoppedAfter": "Detenido tras {time}", + "failedAfter": "Falló tras {time}", + "changed": { + "one": "Cambió {count} archivo", + "other": "Cambió {count} archivos" + }, + "moreFiles": { + "one": "Mostrar {count} archivo más", + "other": "Mostrar {count} archivos más" + } }, "composer": { "placeholder": "Pregúntale a {provider} sobre este proyecto", @@ -225,7 +235,10 @@ }, "queue": { "sendNow": "Enviar ahora", - "count": {"one": "{count} en cola", "other": "{count} en cola"}, + "count": { + "one": "{count} en cola", + "other": "{count} en cola" + }, "drop": "Quitar de la cola", "edit": "editar" }, diff --git a/native/i18n/locales/es/session.json b/native/i18n/locales/es/session.json index 44dca6362..aa0b841a3 100644 --- a/native/i18n/locales/es/session.json +++ b/native/i18n/locales/es/session.json @@ -39,7 +39,6 @@ }, "age": { "second": "{count}s", - "millisecond": "{count}ms", "minute": "{count}min", "hour": "{count}h", "day": "{count}d", diff --git a/native/i18n/locales/ja/chat.json b/native/i18n/locales/ja/chat.json index 722611a44..67691d3af 100644 --- a/native/i18n/locales/ja/chat.json +++ b/native/i18n/locales/ja/chat.json @@ -88,7 +88,6 @@ }, "latest": "最新へ", "newActivity": "新しい動き", - "edited": "編集", "lich": { "openedSession": "セッション作成", "openingSession": "セッション作成中", @@ -124,7 +123,16 @@ "done": "完了", "stopped": "停止", "failed": "失敗", - "noChanges": "変更なし" + "workedFor": "作業時間 {time}", + "worked": "作業内容", + "stoppedAfter": "{time}で停止", + "failedAfter": "{time}で失敗", + "changed": { + "other": "{count}件のファイルを変更" + }, + "moreFiles": { + "other": "残り{count}件のファイルを表示" + } }, "composer": { "placeholder": "このプロジェクトについて{provider}に質問", @@ -208,7 +216,9 @@ }, "queue": { "sendNow": "今すぐ送信", - "count": {"other": "{count}件待機中"}, + "count": { + "other": "{count}件待機中" + }, "drop": "キューから外す", "edit": "編集" }, diff --git a/native/i18n/locales/ja/session.json b/native/i18n/locales/ja/session.json index aa159100e..217864eee 100644 --- a/native/i18n/locales/ja/session.json +++ b/native/i18n/locales/ja/session.json @@ -39,7 +39,6 @@ }, "age": { "second": "{count}秒", - "millisecond": "{count}ミリ秒", "minute": "{count}分", "hour": "{count}時間", "day": "{count}日", diff --git a/native/i18n/locales/ko/chat.json b/native/i18n/locales/ko/chat.json index bea03f714..f350c5150 100644 --- a/native/i18n/locales/ko/chat.json +++ b/native/i18n/locales/ko/chat.json @@ -88,7 +88,6 @@ }, "latest": "최신으로", "newActivity": "새 활동", - "edited": "편집함", "lich": { "openedSession": "세션 열기", "openingSession": "세션 여는 중", @@ -124,7 +123,16 @@ "done": "완료", "stopped": "중지됨", "failed": "실패", - "noChanges": "변경 사항 없음" + "workedFor": "{time} 동안 작업함", + "worked": "작업함", + "stoppedAfter": "{time} 후 중지됨", + "failedAfter": "{time} 후 실패", + "changed": { + "other": "파일 {count}개 변경함" + }, + "moreFiles": { + "other": "파일 {count}개 더 보기" + } }, "composer": { "placeholder": "이 프로젝트에 대해 {provider}에게 물어보세요", @@ -208,7 +216,9 @@ }, "queue": { "sendNow": "지금 보내기", - "count": {"other": "대기 중 {count}개"}, + "count": { + "other": "대기 중 {count}개" + }, "drop": "대기열에서 빼기", "edit": "편집" }, diff --git a/native/i18n/locales/ko/session.json b/native/i18n/locales/ko/session.json index 8c9fba6b6..f3d5a4daf 100644 --- a/native/i18n/locales/ko/session.json +++ b/native/i18n/locales/ko/session.json @@ -38,7 +38,6 @@ }, "age": { "second": "{count}초", - "millisecond": "{count}밀리초", "minute": "{count}분", "hour": "{count}시간", "day": "{count}일", diff --git a/native/i18n/locales/pt-br/chat.json b/native/i18n/locales/pt-br/chat.json index b8a20ab19..d07c072b5 100644 --- a/native/i18n/locales/pt-br/chat.json +++ b/native/i18n/locales/pt-br/chat.json @@ -104,7 +104,6 @@ }, "latest": "Mais recente", "newActivity": "Novidades", - "edited": "Editados", "lich": { "openedSession": "Abriu sessão", "openingSession": "Abrindo sessão", @@ -140,7 +139,18 @@ "done": "Concluído", "stopped": "Interrompido", "failed": "Falhou", - "noChanges": "sem alterações" + "workedFor": "Trabalhou por {time}", + "worked": "Trabalho", + "stoppedAfter": "Interrompido após {time}", + "failedAfter": "Falhou após {time}", + "changed": { + "one": "Alterou {count} arquivo", + "other": "Alterou {count} arquivos" + }, + "moreFiles": { + "one": "Mostrar mais {count} arquivo", + "other": "Mostrar mais {count} arquivos" + } }, "composer": { "placeholder": "Pergunte ao {provider} sobre este projeto", @@ -225,7 +235,10 @@ }, "queue": { "sendNow": "Enviar agora", - "count": {"one": "{count} na fila", "other": "{count} na fila"}, + "count": { + "one": "{count} na fila", + "other": "{count} na fila" + }, "drop": "Tirar da fila", "edit": "editar" }, diff --git a/native/i18n/locales/pt-br/session.json b/native/i18n/locales/pt-br/session.json index ac9f9cc0d..bee5b9fed 100644 --- a/native/i18n/locales/pt-br/session.json +++ b/native/i18n/locales/pt-br/session.json @@ -39,7 +39,6 @@ }, "age": { "second": "{count} s", - "millisecond": "{count} ms", "minute": "{count} min", "hour": "{count} h", "day": "{count} d", diff --git a/native/i18n/locales/ru/chat.json b/native/i18n/locales/ru/chat.json index 5cceef6ad..3e789984e 100644 --- a/native/i18n/locales/ru/chat.json +++ b/native/i18n/locales/ru/chat.json @@ -136,7 +136,6 @@ }, "latest": "К последнему", "newActivity": "Новые события", - "edited": "Изменено", "lich": { "openedSession": "Открытие сессии", "openingSession": "Открывается сессия", @@ -172,7 +171,22 @@ "done": "Готово", "stopped": "Остановлено", "failed": "Сбой", - "noChanges": "без изменений" + "workedFor": "Работа заняла {time}", + "worked": "Ход работы", + "stoppedAfter": "Остановлено через {time}", + "failedAfter": "Сбой через {time}", + "changed": { + "one": "Изменён {count} файл", + "few": "Изменено {count} файла", + "many": "Изменено {count} файлов", + "other": "Изменено {count} файла" + }, + "moreFiles": { + "one": "Показать ещё {count} файл", + "few": "Показать ещё {count} файла", + "many": "Показать ещё {count} файлов", + "other": "Показать ещё {count} файла" + } }, "composer": { "placeholder": "Спросите {provider} об этом проекте", @@ -259,7 +273,12 @@ }, "queue": { "sendNow": "Отправить сейчас", - "count": {"one": "{count} в очереди", "few": "{count} в очереди", "many": "{count} в очереди", "other": "{count} в очереди"}, + "count": { + "one": "{count} в очереди", + "few": "{count} в очереди", + "many": "{count} в очереди", + "other": "{count} в очереди" + }, "drop": "Убрать из очереди", "edit": "правка" }, diff --git a/native/i18n/locales/ru/session.json b/native/i18n/locales/ru/session.json index 94294998c..fe57195a8 100644 --- a/native/i18n/locales/ru/session.json +++ b/native/i18n/locales/ru/session.json @@ -41,7 +41,6 @@ }, "age": { "second": "{count} с", - "millisecond": "{count} мс", "minute": "{count} мин", "hour": "{count} ч", "day": "{count} дн.", diff --git a/native/i18n/locales/zh-cn/chat.json b/native/i18n/locales/zh-cn/chat.json index 2a5581f6c..6dd1ec520 100644 --- a/native/i18n/locales/zh-cn/chat.json +++ b/native/i18n/locales/zh-cn/chat.json @@ -88,7 +88,6 @@ }, "latest": "最新", "newActivity": "新动态", - "edited": "已编辑", "lich": { "openedSession": "打开会话", "openingSession": "正在打开会话", @@ -124,7 +123,16 @@ "done": "完成", "stopped": "已停止", "failed": "失败", - "noChanges": "没有更改" + "workedFor": "工作了 {time}", + "worked": "工作过程", + "stoppedAfter": "{time}后停止", + "failedAfter": "{time}后失败", + "changed": { + "other": "更改了 {count} 个文件" + }, + "moreFiles": { + "other": "再显示 {count} 个文件" + } }, "composer": { "placeholder": "向 {provider} 询问有关此项目的问题", @@ -208,7 +216,9 @@ }, "queue": { "sendNow": "立即发送", - "count": {"other": "{count} 条排队中"}, + "count": { + "other": "{count} 条排队中" + }, "drop": "移出队列", "edit": "编辑" }, diff --git a/native/i18n/locales/zh-cn/session.json b/native/i18n/locales/zh-cn/session.json index a06eb350d..89f9b3b62 100644 --- a/native/i18n/locales/zh-cn/session.json +++ b/native/i18n/locales/zh-cn/session.json @@ -39,7 +39,6 @@ }, "age": { "second": "{count}秒", - "millisecond": "{count}毫秒", "minute": "{count}分钟", "hour": "{count}小时", "day": "{count}天",