dabf5bfecc
- Replace fixed 6-message compact retention with ratio-based logic: retain ~20% of compactable estimated tokens, with a 6-message floor and user-turn boundary alignment - Add compactRetainedTokenBudget, compactRecentStart, compactTurnBoundary helpers in internal/agent/agent.go - Add TestAgentCompactKeepsTwentyPercentRecentContext - Move startup/session/repl/bootstrap logic from root into internal/app so main.go is a thin binary entry point (15 lines) - Update /compact docs in README.md
39 lines
791 B
Go
39 lines
791 B
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"agentu/internal/session"
|
|
)
|
|
|
|
func initializeSession(modelManager *session.Manager, resumeID string) error {
|
|
if resumeID != "" {
|
|
if err := modelManager.Resume(resumeID); err != nil {
|
|
return fmt.Errorf("resume session: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
if _, err := modelManager.NewSession(); err != nil {
|
|
return fmt.Errorf("start new session: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func printExitSession(m *session.Manager) {
|
|
if m == nil {
|
|
return
|
|
}
|
|
_ = m.Save()
|
|
id := m.CurrentSessionID()
|
|
name := m.CurrentSessionName()
|
|
if id != "" {
|
|
if name != "" && name != id {
|
|
fmt.Fprintf(os.Stderr, "session: %s (%s)\n", id, name)
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "session: %s\n", id)
|
|
}
|
|
fmt.Fprintf(os.Stderr, "resume: agentu --resume %s\n", id)
|
|
}
|
|
}
|