Documentation
¶
Overview ¶
Package session persists interactive conversations so they can be resumed later from the CLI (/resume).
Storage is append-only JSON Lines: one session is one <id>.jsonl file under ~/.oni3/sessions, and every turn is written as its own line. User and assistant text, model reasoning, tool calls, ask_user exchanges and task-list snapshots are all recorded; nothing is ever rewritten, so an interrupted turn leaves the file intact.
Index ¶
- Constants
- func Dir() string
- type Event
- type Session
- func (s *Session) AddAssistant(text string) error
- func (s *Session) AddQuestion(question, answer string) error
- func (s *Session) AddReasoning(text string) error
- func (s *Session) AddTodos(items []TodoItem) error
- func (s *Session) AddToolEnd(name, result string, failed bool) error
- func (s *Session) AddToolStart(name, arguments string) error
- func (s *Session) AddUser(text string) error
- func (s *Session) Append(ev Event) error
- func (s *Session) Events() []Event
- func (s *Session) LastUserMessage() string
- func (s *Session) SetConfig(agent, model, skill string) error
- func (s *Session) Todos() []TodoItem
- func (s *Session) TurnCount() int
- type TodoItem
Constants ¶
const ( EventSession = "session" // header line: id, kind, agent, model, skill EventConfig = "config" // later agent/model/skill change EventUser = "user" // user turn EventAssistant = "assistant" // assistant turn EventReasoning = "reasoning" // model thinking (may precede a tool call or answer) EventTool = "tool" // tool call start/end EventQuestion = "question" // ask_user question (Content) and answer (Result) EventTodo = "todo" // full task list snapshot )
Event types stored in a session file.
const ( ToolStart = "start" ToolEnd = "end" ToolError = "error" )
Tool statuses for EventTool.
const ( KindAgent = "agent" KindChat = "chat" )
Session kinds. KindChat is kept for reading sessions written by older versions that still had a standalone chat mode; new sessions are agents.
const ( RoleUser = "user" RoleAssistant = "assistant" )
Turn roles used by the recordTurn helpers.
const ( TodoStatusPending = "pending" TodoStatusInProgress = "in_progress" TodoStatusCompleted = "completed" )
Task statuses persisted in todo events.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Type string `json:"type"`
Time time.Time `json:"time"`
ID string `json:"id,omitempty"`
Kind string `json:"kind,omitempty"`
Agent string `json:"agent,omitempty"`
Model string `json:"model,omitempty"`
Skill string `json:"skill,omitempty"`
Content string `json:"content,omitempty"`
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
Result string `json:"result,omitempty"`
Status string `json:"status,omitempty"`
Todos []TodoItem `json:"todos,omitempty"`
}
Event is one line of a session file. Fields are used depending on Type.
type Session ¶
type Session struct {
ID string
Kind string
Agent string
Model string
Skill string
Created time.Time
Updated time.Time
// contains filtered or unexported fields
}
Session is a persisted, append-only conversation.
func List ¶
List returns sessions of the given kind (all kinds when kind is empty), newest first, capped at limit (<= 0 means no cap).
func New ¶
New creates an empty session with a time-ordered, human-readable ID. The file is created lazily on the first append.
func (*Session) AddAssistant ¶
AddAssistant appends an assistant turn.
func (*Session) AddQuestion ¶
AddQuestion records an ask_user question and the user's answer ("" when the user cancelled).
func (*Session) AddReasoning ¶
AddReasoning appends a model thinking block.
func (*Session) AddToolEnd ¶
AddToolEnd appends the completion of a tool call. failed reports an error result, which is preserved as the event status.
func (*Session) AddToolStart ¶
AddToolStart appends the start of a tool call.
func (*Session) Append ¶
Append writes one event as a JSON line. The session header is emitted automatically before the first event.
func (*Session) LastUserMessage ¶
LastUserMessage returns the most recent user turn, or "".
func (*Session) SetConfig ¶
SetConfig records an agent/model/skill change. Replaying the file keeps the values from the last config event.