session autoload mechanism
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user