Documentation
¶
Overview ¶
Package codex provides an adapter for Codex CLI that reads session files with two-pass parsing optimization for large conversation files.
Index ¶
- func NewWatcher(root string, resolve sessionIDResolver) (<-chan adapter.Event, io.Closer, error)
- type Adapter
- func (a *Adapter) Capabilities() adapter.CapabilitySet
- func (a *Adapter) Detect(projectRoot string) (bool, error)
- func (a *Adapter) ID() string
- func (a *Adapter) Icon() string
- func (a *Adapter) Messages(sessionID string) ([]adapter.Message, error)
- func (a *Adapter) Name() string
- func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)
- func (a *Adapter) SessionByID(sessionID string) (*adapter.Session, error)
- func (a *Adapter) SessionIDFromPath(path string) (string, error)
- func (a *Adapter) Sessions(projectRoot string) ([]adapter.Session, error)
- func (a *Adapter) Usage(sessionID string) (*adapter.UsageStats, error)
- func (a *Adapter) Watch(projectRoot string) (<-chan adapter.Event, io.Closer, error)
- func (a *Adapter) WatchForProjectDiscovery() bool
- func (a *Adapter) WatchScope() adapter.WatchScope
- type ContentBlock
- type EventMsgPayload
- type RawRecord
- type ReasoningSummary
- type ResponseItemBase
- type ResponseMessagePayload
- type ResponseReasoningPayload
- type ResponseToolCallPayload
- type ResponseToolOutputPayload
- type SessionMetaPayload
- type SessionMetadata
- type TokenCountInfo
- type TokenUsage
- type TurnContextPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWatcher ¶
NewWatcher watches Codex's dated directory tree and resolves rollout paths to stable thread IDs. fsnotify is not recursive, so every existing directory under the current and previous month is registered explicitly and newly created directories are added as they appear.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements the adapter.Adapter interface for Codex CLI sessions.
func (*Adapter) Capabilities ¶
func (a *Adapter) Capabilities() adapter.CapabilitySet
Capabilities returns the supported features.
func (*Adapter) Detect ¶
Detect checks if Codex sessions exist for the given project.
Files are probed newest-first and the scan stops at the first match. Detect runs on every launch with a cold metadata cache, and reading every rollout file in ~/.codex/sessions can take seconds once the history is a few thousand sessions deep — much worse where an endpoint security agent intercepts each open. Newest-first turns the common case (a project worked on recently) into a handful of reads (td-9c7bf2).
func (*Adapter) Messages ¶
Messages returns all messages for the given session. Uses caching with incremental parsing for append-only growth optimization.
func (*Adapter) SearchMessages ¶
func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)
SearchMessages searches message content within a session. Implements adapter.MessageSearcher interface.
func (*Adapter) SessionByID ¶ added in v0.94.0
SessionByID implements adapter.TargetedRefresher without scanning all rollout files on each active-session update.
func (*Adapter) SessionIDFromPath ¶ added in v0.94.0
SessionIDFromPath resolves fsnotify paths to stable Codex thread IDs. Codex rollout basenames are not session identities on current releases.
func (*Adapter) Sessions ¶
Sessions returns all sessions for the given project, sorted by update time.
func (*Adapter) Usage ¶
func (a *Adapter) Usage(sessionID string) (*adapter.UsageStats, error)
Usage returns aggregate usage stats for the given session.
func (*Adapter) WatchForProjectDiscovery ¶ added in v0.94.0
WatchForProjectDiscovery keeps the global Codex watcher alive even when the current project has no prior sessions, so its first rollout can appear.
func (*Adapter) WatchScope ¶
func (a *Adapter) WatchScope() adapter.WatchScope
WatchScope returns Global because codex watches a global sessions directory (td-7a72b6f7).
type ContentBlock ¶
ContentBlock is a content fragment inside a message.
type EventMsgPayload ¶
type EventMsgPayload struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Info *TokenCountInfo `json:"info,omitempty"`
}
EventMsgPayload represents an event message.
type RawRecord ¶
type RawRecord struct {
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
RawRecord represents a single JSONL line in a Codex session file.
type ReasoningSummary ¶
ReasoningSummary holds summarized reasoning text.
type ResponseItemBase ¶
type ResponseItemBase struct {
Type string `json:"type"`
}
ResponseItemBase holds the response item type.
type ResponseMessagePayload ¶
type ResponseMessagePayload struct {
Type string `json:"type"`
ID string `json:"id"`
Role string `json:"role"`
Phase string `json:"phase,omitempty"`
Content []ContentBlock `json:"content"`
}
ResponseMessagePayload represents a user or assistant message.
type ResponseReasoningPayload ¶
type ResponseReasoningPayload struct {
Type string `json:"type"`
ID string `json:"id"`
Summary []ReasoningSummary `json:"summary"`
}
ResponseReasoningPayload represents reasoning metadata.
type ResponseToolCallPayload ¶
type ResponseToolCallPayload struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
CallID string `json:"call_id"`
}
ResponseToolCallPayload represents a tool call request.
type ResponseToolOutputPayload ¶
type ResponseToolOutputPayload struct {
Type string `json:"type"`
ID string `json:"id"`
CallID string `json:"call_id"`
Output json.RawMessage `json:"output,omitempty"`
}
ResponseToolOutputPayload represents a tool call response.
type SessionMetaPayload ¶
type SessionMetaPayload struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Timestamp time.Time `json:"timestamp"`
CWD string `json:"cwd"`
Source json.RawMessage `json:"source"`
ThreadSource string `json:"thread_source"`
}
SessionMetaPayload holds metadata about a Codex session.
type SessionMetadata ¶
type SessionMetadata struct {
Path string
SessionID string
CWD string
FirstMsg time.Time
LastMsg time.Time
MsgCount int
TotalTokens int
FirstUserMessage string // Content of the first user message (for title)
IsSubAgent bool
}
SessionMetadata aggregates metadata extracted from a session file.
type TokenCountInfo ¶
type TokenCountInfo struct {
TotalTokenUsage *TokenUsage `json:"total_token_usage"`
LastTokenUsage *TokenUsage `json:"last_token_usage"`
}
TokenCountInfo contains token usage stats.
type TokenUsage ¶
type TokenUsage struct {
InputTokens int `json:"input_tokens"`
CachedInputTokens int `json:"cached_input_tokens"`
OutputTokens int `json:"output_tokens"`
ReasoningOutputTokens int `json:"reasoning_output_tokens"`
CacheWriteInputTokens int `json:"cache_write_input_tokens"`
TotalTokens int `json:"total_tokens"`
}
TokenUsage represents token usage metrics.
type TurnContextPayload ¶
type TurnContextPayload struct {
Model string `json:"model"`
}
TurnContextPayload carries model context per turn.