refactor(commands): tighten runtime contract docs and assertions

This commit is contained in:
mingmxren 2026-03-01 15:06:36 +08:00
parent 1dd5ffcdab
commit 69b95aeb84
2 changed files with 13 additions and 0 deletions

View file

@ -5,17 +5,29 @@ import (
"github.com/sipeed/picoclaw/pkg/session" "github.com/sipeed/picoclaw/pkg/session"
) )
// SessionOps defines the session lifecycle operations command handlers rely on.
// Implementations are expected to be scope-aware and deterministic for a given scopeKey.
type SessionOps interface { type SessionOps interface {
// ResolveActive returns the active session key for scopeKey, creating default scope state if needed.
ResolveActive(scopeKey string) (string, error) ResolveActive(scopeKey string) (string, error)
// StartNew creates and activates a new session for scopeKey and returns its key.
StartNew(scopeKey string) (string, error) StartNew(scopeKey string) (string, error)
// List returns ordered session metadata for scopeKey.
List(scopeKey string) ([]session.SessionMeta, error) List(scopeKey string) ([]session.SessionMeta, error)
// Resume activates the session at a 1-based index within scopeKey and returns its key.
Resume(scopeKey string, index int) (string, error) Resume(scopeKey string, index int) (string, error)
// Prune deletes older sessions for scopeKey according to limit and returns deleted session keys.
Prune(scopeKey string, limit int) ([]string, error) Prune(scopeKey string, limit int) ([]string, error)
} }
// Runtime exposes the minimal agent runtime state needed by command handlers.
type Runtime interface { type Runtime interface {
// Channel returns the inbound channel name (for example: telegram, whatsapp).
Channel() string Channel() string
// ScopeKey returns the resolved scope identifier used for session operations.
ScopeKey() string ScopeKey() string
// SessionOps returns scoped session lifecycle operations.
SessionOps() SessionOps SessionOps() SessionOps
// Config returns process config for read-only access by handlers; callers must not mutate it.
Config() *config.Config Config() *config.Config
} }

View file

@ -49,5 +49,6 @@ func (f *fakeRuntime) Config() *config.Config {
func TestRuntimeContracts_MinimalSessionOps(t *testing.T) { func TestRuntimeContracts_MinimalSessionOps(t *testing.T) {
var _ SessionOps = (*fakeSessionOps)(nil) var _ SessionOps = (*fakeSessionOps)(nil)
var _ SessionOps = (*session.SessionManager)(nil)
var _ Runtime = (*fakeRuntime)(nil) var _ Runtime = (*fakeRuntime)(nil)
} }