From b77664426113364fa8a0ec22824a29657831991a Mon Sep 17 00:00:00 2001 From: Luxferre Date: Fri, 11 Sep 2026 17:43:45 +0300 Subject: [PATCH] session autoload mechanism --- main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/main.go b/main.go index 018dde7..6497ec8 100644 --- a/main.go +++ b/main.go @@ -1665,6 +1665,17 @@ func loadSession(sid string) ([]Message, error) { return nil, fmt.Errorf("session not found: %s", sid) } +// findProjectSession returns the saved session for the current working +// directory (if any), or nil when none exists yet. +func findProjectSession() *Session { + pid := projectID() + ss := sessions() + for i := range ss { + if ss[i].ID == pid { return &ss[i] } + } + return nil +} + func autosave(msgs []Message) { saveSession(msgs, projectID()) } @@ -2156,6 +2167,22 @@ func main() { return } loadHistory() + // Interactive startup: if a session already exists for this directory, offer + // to autoload it so the user can seamlessly resume prior work. + if sess := findProjectSession(); sess != nil && len(sess.Messages) > 1 { + fmt.Println(c("[session found for this directory]", 33) + " " + c(sess.ID, 32)) + fmt.Println(" " + c(sess.Summary, 2)) + fmt.Println(c(fmt.Sprintf(" created %s [%d messages]", sess.Created, len(sess.Messages)), 2)) + fmt.Print(c("Resume this session? [Y/n]: ", 33)) + if ans, ok := readPlain(""); ok { + ans = strings.TrimSpace(strings.ToLower(ans)) + if ans == "" || ans == "y" || ans == "yes" { + msgs = sess.Messages + autosave(msgs) + fmt.Println(c("[session resumed: "+sess.ID+"]", 32) + " " + c(summary(msgs), 2)) + } + } + } re := cfg.Raw["reasoning_effort"] if re == "" { re = "high" } fmt.Println(c("Bantam Agent ready", 1, 32) + c(" (Ctrl+J = new line)", 2))