diff --git a/CHANGELOG.md b/CHANGELOG.md index ff23be0c..c0773123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ takes `--dry-run`. ## Unreleased +- Closing the window no longer loads every chat's log. Since v0.3.5 the daemon read each chat's transcript from disk when a window went, only to drop the window from that chat's subscribers, so 200 restored chats meant 200 logs read and held open until shutdown. A chat that shuts down no longer reopens its log either. - The chat's / menu opens for a /word anywhere in the draft, not only at its start. Mid-draft it lists skills and custom commands for Claude chats; a pick replaces only that word. - A message's pictures show above its text, as thumbnails lined up with the text's left edge, in Ledger and Column alike. In a Claude Code pane, a pasted picture no longer turns into a grey `image-1.png` chip for good once the transcript grows: after the pane chat re-read its transcript's tail, the daemon had forgotten where older messages were and answered "gone" when the window asked for the picture. While a picture loads, its thumbnail shows an empty frame with its number. The chip now shows only when the picture really is gone, and its tooltip says why. diff --git a/internal/daemon/chatresume_test.go b/internal/daemon/chatresume_test.go index 42304f35..7242e05e 100644 --- a/internal/daemon/chatresume_test.go +++ b/internal/daemon/chatresume_test.go @@ -242,10 +242,11 @@ func TestChatBootLoadsNothing(t *testing.T) { os.WriteFile(filepath.Join(dir, "config.json"), b, 0o600) } spy := &spyProvider{} - sock, stop := runWith(t, f, func(o *Options) { + d, sock, stopNow := runDaemon(t, f, func(o *Options) { o.Chats = root o.Providers = map[model.Provider]session.Provider{model.ProviderClaude: spy} }) + stop := sync.OnceFunc(stopNow) defer stop() gui := dialHello(t, sock, proto.Hello{Version: proto.Version, Level: proto.Level, Kind: "gui", Cwd: t.TempDir()}) st := waitChat(gui, "chats back", func(s model.State) bool { return len(s.Chats) == n }) @@ -275,6 +276,16 @@ func TestChatBootLoadsNothing(t *testing.T) { _, err := eventlog.ReadConfig(filepath.Join(root, "archive", "chat-7")) return err == nil }) + // A window going, and an unsubscribe, load no chat either. + d.dropSubs(&client{}) + d.chatUnsubscribe("chat-9", guiSink{&client{}}) + if got := opened(); len(got) != 0 { + t.Fatalf("dropping subscribers opened the logs of %v", got) + } + stop() + if got := opened(); len(got) != 0 { + t.Fatalf("shutdown opened the logs of %v", got) + } } func TestRecap(t *testing.T) { diff --git a/internal/daemon/chats.go b/internal/daemon/chats.go index 87cbb354..32a4b697 100644 --- a/internal/daemon/chats.go +++ b/internal/daemon/chats.go @@ -983,6 +983,7 @@ func (c *chat) close() { c.log.Close() c.log = nil } + c.loaded = true // why: a do queued behind this cleanup must not reopen the log for s := range c.subs { s.Removed(c.id) } diff --git a/internal/daemon/panestream.go b/internal/daemon/panestream.go index 474bf746..bd30f07d 100644 --- a/internal/daemon/panestream.go +++ b/internal/daemon/panestream.go @@ -391,7 +391,7 @@ func (d *Daemon) chatSubscribe(ctx context.Context, c *client, m proto.ChatSubsc // pane chat's. func (d *Daemon) chatUnsubscribe(id string, sink web.Sink) { if ch, err := d.chat(id); err == nil { - ch.do(func() { delete(ch.subs, sink) }) + ch.run(func() { delete(ch.subs, sink) }) // run, not do: an unsubscribe loads no log return } d.paneUnsubscribe(id, sink) @@ -467,6 +467,6 @@ func (d *Daemon) dropSubs(c *client) { d.paneUnsubscribe(id, sink) } for _, ch := range chats { - ch.do(func() { delete(ch.subs, sink) }) + ch.run(func() { delete(ch.subs, sink) }) // run, not do: an unsubscribe loads no log } }