Documentation
¶
Index ¶
- func DeleteSession(project, uuid string) error
- func GetLastEnvironment(entries []Entry) string
- func ListAllSessions() (map[string][]SessionMeta, error)
- func ReconstructHistory(entries []Entry) []adk.Message
- func ValidateSessionID(id string) error
- type Entry
- type EntryType
- type PlanSnapshot
- type Recorder
- func (r *Recorder) Close()
- func (r *Recorder) HasRecording() bool
- func (r *Recorder) RecordAssistant(content string)
- func (r *Recorder) RecordCompact(summary string, compactedN int)
- func (r *Recorder) RecordModeChange(mode string)
- func (r *Recorder) RecordPlanUpdate(status, title, content, feedback string)
- func (r *Recorder) RecordSubagentAsync(name, taskID, agentType string)
- func (r *Recorder) RecordSubagentResult(name, output string, err error)
- func (r *Recorder) RecordSubagentStart(name, agentType string)
- func (r *Recorder) RecordTodoSnapshot(todos []TodoSnapshotItem)
- func (r *Recorder) RecordToolCall(name, args, toolCallID string)
- func (r *Recorder) RecordToolResult(name, output, toolCallID string, err error)
- func (r *Recorder) RecordUser(content string)
- func (r *Recorder) SetUUID(id string)
- func (r *Recorder) UUID() string
- type SessionMeta
- type SessionState
- type TodoSnapshotItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteSession ¶
DeleteSession removes a session file and its index entry.
func GetLastEnvironment ¶
GetLastEnvironment scans the session entries to find the last successful switch_env call, and returns the target environment alias. If none is found, it returns "local".
func ListAllSessions ¶ added in v0.3.4
func ListAllSessions() (map[string][]SessionMeta, error)
ListAllSessions returns all sessions across all projects, keyed by project path.
func ReconstructHistory ¶
ReconstructHistory converts a slice of recorded session entries back into LLM history messages suitable for resuming a conversation. It reconstructs tool call and tool result messages so that resumed sessions retain full context.
func ValidateSessionID ¶ added in v0.3.3
ValidateSessionID checks that a session ID is safe for use as a filename. It rejects empty IDs, path traversal sequences, and path separators.
Types ¶
type Entry ¶
type Entry struct {
Type EntryType `json:"type"`
UUID string `json:"uuid,omitempty"`
Project string `json:"project,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Content string `json:"content,omitempty"`
Name string `json:"name,omitempty"` // tool name
Args string `json:"args,omitempty"` // tool args JSON
Output string `json:"output,omitempty"` // tool output
Error string `json:"error,omitempty"` // tool error
ToolCallID string `json:"tool_call_id,omitempty"` // links tool_call ↔ tool_result
Timestamp string `json:"timestamp"`
// plan_update fields
PlanStatus string `json:"plan_status,omitempty"`
PlanTitle string `json:"plan_title,omitempty"`
PlanContent string `json:"plan_content,omitempty"`
Feedback string `json:"feedback,omitempty"`
// todo_snapshot fields
Todos []TodoSnapshotItem `json:"todos,omitempty"`
// subagent_start / subagent_result fields
SubagentName string `json:"subagent_name,omitempty"`
SubagentType string `json:"subagent_type,omitempty"`
// mode_change field
Mode string `json:"mode,omitempty"`
// compact fields
Summary string `json:"summary,omitempty"`
CompactedN int `json:"compacted_n,omitempty"`
}
Entry is one line of the JSONL session file.
func LoadSession ¶
LoadSession reads all entries from a session JSONL file identified by uuid.
type EntryType ¶
type EntryType string
EntryType identifies the kind of JSONL record.
const ( EntrySessionStart EntryType = "session_start" EntryUser EntryType = "user" EntryAssistant EntryType = "assistant" EntryToolCall EntryType = "tool_call" EntryToolResult EntryType = "tool_result" // Extended entry types for structured state tracking. EntryPlanUpdate EntryType = "plan_update" EntryTodoSnapshot EntryType = "todo_snapshot" EntrySubagentStart EntryType = "subagent_start" EntrySubagentResult EntryType = "subagent_result" EntrySubagentAsync EntryType = "subagent_async" EntryModeChange EntryType = "mode_change" EntryCompact EntryType = "compact" EntryBudgetWarning EntryType = "budget_warning" )
type PlanSnapshot ¶
PlanSnapshot holds the last known plan state from a session.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder appends events to a JSONL session file synchronously. The file and index entry are created lazily on the first real message so that sessions with no conversation are never persisted. Call Close() (or defer it) to finalize.
func NewRecorder ¶
NewRecorder returns a Recorder that will create the session file only when the first message is recorded. Never returns an error — recording is best-effort and must not break normal operation.
func NewTeammateRecorder ¶
NewTeammateRecorder creates a Recorder that stores its JSONL transcript under the leader session's subagents directory:
~/.jcode/sessions/{leaderUUID}/subagents/agent-{agentID}.jsonl
This mirrors Claude Code's per-agent transcript pattern.
func (*Recorder) Close ¶
func (r *Recorder) Close()
Close flushes and closes the underlying file. Safe to call multiple times. If no messages were ever recorded the file is never created.
func (*Recorder) HasRecording ¶ added in v0.0.4
HasRecording reports whether any message has been recorded (i.e. the session file has been created). Returns false for sessions where the user quit without any conversation.
func (*Recorder) RecordAssistant ¶
RecordAssistant appends an assistant message entry.
func (*Recorder) RecordCompact ¶
RecordCompact appends a compact/summarization event entry.
func (*Recorder) RecordModeChange ¶
RecordModeChange appends a mode transition entry.
func (*Recorder) RecordPlanUpdate ¶
RecordPlanUpdate appends a plan state change entry.
func (*Recorder) RecordSubagentAsync ¶
RecordSubagentAsync appends an async subagent launch entry with the task ID.
func (*Recorder) RecordSubagentResult ¶
RecordSubagentResult appends a subagent completion entry.
func (*Recorder) RecordSubagentStart ¶
RecordSubagentStart appends a subagent launch entry.
func (*Recorder) RecordTodoSnapshot ¶
func (r *Recorder) RecordTodoSnapshot(todos []TodoSnapshotItem)
RecordTodoSnapshot appends a full todo list snapshot entry.
func (*Recorder) RecordToolCall ¶
RecordToolCall appends a tool-call entry.
func (*Recorder) RecordToolResult ¶
RecordToolResult appends a tool-result entry.
func (*Recorder) RecordUser ¶
RecordUser appends a user message entry. On the first user message, the title is auto-generated from the content.
type SessionMeta ¶
type SessionMeta struct {
UUID string `json:"uuid"`
Project string `json:"project"`
Provider string `json:"provider"`
Model string `json:"model"`
StartTime string `json:"start_time"` // RFC3339
Title string `json:"title,omitempty"`
}
SessionMeta is stored in the index for fast listing.
func ListSessions ¶
func ListSessions(project string) ([]SessionMeta, error)
ListSessions returns all sessions recorded for a given project path, newest last.
type SessionState ¶
type SessionState struct {
History []adk.Message
Plan *PlanSnapshot // nil if no plan events found
Todos []TodoSnapshotItem // last todo snapshot, nil if none
Mode string // last mode (normal/planning/executing), empty = normal
EnvTarget string // last environment (local/ssh alias)
}
SessionState is the full recoverable state from a session file, including conversation history, plan, todos, mode, and environment.
func ReconstructState ¶
func ReconstructState(entries []Entry) *SessionState
ReconstructState rebuilds the full session state from recorded entries. It is compact-aware: if a compact entry is found, messages before it are replaced with the compact summary.
type TodoSnapshotItem ¶
type TodoSnapshotItem struct {
ID int `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
}
TodoSnapshotItem is a single todo entry stored in a todo_snapshot event.