diff --git a/main.go b/main.go index e00dbf2..af00c52 100644 --- a/main.go +++ b/main.go @@ -33,14 +33,16 @@ const ( // managedSession wraps a Core with its context and metadata. type managedSession struct { - core agent.Core - ctx context.Context - cancel context.CancelFunc - id string - agent string - log []byte - logMu sync.Mutex - peers map[string]bool + core agent.Core + ctx context.Context + cancel context.CancelFunc + id string + agent string + log []byte + logMu sync.Mutex + peers map[string]bool + plan string + prevPrompt string } // chatEmitter batches ChatUpdated D-Bus signals to avoid flooding the bus. @@ -369,6 +371,7 @@ func (m *SessionManager) Submit(sessionID, prompt string) (bool, *dbus.Error) { return false, nil } + sess.prevPrompt = prompt go sess.core.Submit(sess.ctx, prompt) return true, nil } @@ -519,6 +522,85 @@ func (m *SessionManager) GetContext(sessionID string) (string, *dbus.Error) { return result, nil } +// --- Plan/scratchpad --- + +func (m *SessionManager) GetPlan(sessionID string) (string, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return "", nil + } + return sess.plan, nil +} + +func (m *SessionManager) SetPlan(sessionID, plan string) (bool, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return false, nil + } + sess.plan = plan + return true, nil +} + +// --- System prompt / context size / previous prompt --- + +func (m *SessionManager) GetSystemPrompt(sessionID string) (string, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return "", nil + } + return sess.core.SystemPrompt(), nil +} + +func (m *SessionManager) GetContextSize(sessionID string) (string, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return "", nil + } + return sess.core.CtxSz(), nil +} + +func (m *SessionManager) GetPreviousPrompt(sessionID string) (string, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return "", nil + } + return sess.prevPrompt, nil +} + +// --- Compact / Clear --- + +func (m *SessionManager) Compact(sessionID string) (bool, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return false, nil + } + sess.core.Submit(sess.ctx, "/compact") + return true, nil +} + +func (m *SessionManager) ClearContext(sessionID string) (bool, *dbus.Error) { + m.mu.RLock() + sess, ok := m.sessions[sessionID] + m.mu.RUnlock() + if !ok { + return false, nil + } + sess.core.Submit(sess.ctx, "/clear") + return true, nil +} + // --- Backends/models/agents --- func (m *SessionManager) ListBackends() ([]string, *dbus.Error) { @@ -1356,6 +1438,35 @@ const introspectXML = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + +