codex

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codex provides an adapter for Codex CLI that reads session files with two-pass parsing optimization for large conversation files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatcher

func NewWatcher(root string, resolve sessionIDResolver) (<-chan adapter.Event, io.Closer, error)

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 New

func New() *Adapter

New creates a new Codex adapter.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() adapter.CapabilitySet

Capabilities returns the supported features.

func (*Adapter) Detect

func (a *Adapter) Detect(projectRoot string) (bool, error)

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) ID

func (a *Adapter) ID() string

ID returns the adapter identifier.

func (*Adapter) Icon

func (a *Adapter) Icon() string

Icon returns the adapter icon for badge display.

func (*Adapter) Messages

func (a *Adapter) Messages(sessionID string) ([]adapter.Message, error)

Messages returns all messages for the given session. Uses caching with incremental parsing for append-only growth optimization.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the human-readable adapter name.

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

func (a *Adapter) SessionByID(sessionID string) (*adapter.Session, error)

SessionByID implements adapter.TargetedRefresher without scanning all rollout files on each active-session update.

func (*Adapter) SessionIDFromPath added in v0.94.0

func (a *Adapter) SessionIDFromPath(path string) (string, error)

SessionIDFromPath resolves fsnotify paths to stable Codex thread IDs. Codex rollout basenames are not session identities on current releases.

func (*Adapter) Sessions

func (a *Adapter) Sessions(projectRoot string) ([]adapter.Session, error)

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) Watch

func (a *Adapter) Watch(projectRoot string) (<-chan adapter.Event, io.Closer, error)

Watch returns a channel that emits events when session data changes.

func (*Adapter) WatchForProjectDiscovery added in v0.94.0

func (a *Adapter) WatchForProjectDiscovery() bool

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

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

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

type ReasoningSummary struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL