Documentation
¶
Index ¶
- Constants
- func AppendErrorLog(home, sessionID, component string, err error) error
- func FormatRelativeAge(now, t time.Time) string
- func IdleLogPath(home, sessionID string) string
- func IdlePolicyPath(home, sessionID string) string
- func IsCodexRunner(runner string) bool
- func IsGrokRunner(runner string) bool
- func LogsPath(home, sessionID string) string
- func RunnerFamily(runner string) string
- func SameRunnerFamily(a, b string) bool
- func WriteIdlePolicy(home, sessionID string, p IdlePolicy) error
- type Config
- type IdlePolicy
- type LogRecord
- type Message
- type Session
- type SessionMeta
- type Store
Constants ¶
const ( RunnerFamilyCodex = "codex" RunnerFamilyGrok = "grok" )
Provider family keys stored in SessionMeta.RunnerSessions.
const DefaultIdleTimeout = 10 * time.Minute
DefaultIdleTimeout is the compact 10m default when exit-on-idle is on and the stored duration is zero. Matches agentrunapi.DefaultIdleTimeout.
Variables ¶
This section is empty.
Functions ¶
func AppendErrorLog ¶ added in v0.0.145
AppendErrorLog records a runtime error without ever using an attached TTY as a diagnostic sink. The session must already exist.
func FormatRelativeAge ¶ added in v0.0.57
FormatRelativeAge formats the age of t relative to now for human session lists. Zero t → "-"; age < 1s (after clamping future to 0) → "just now"; otherwise short units (s/m/h/d), max 2 non-zero units, zero stops chain, " ago".
func IdleLogPath ¶ added in v0.0.195
IdleLogPath is $home/sessions/<sessionID>/idle.jsonl (idle watchdog decision log).
func IdlePolicyPath ¶ added in v0.0.135
IdlePolicyPath is $home/sessions/<sessionID>/idle-policy.json.
func IsCodexRunner ¶ added in v0.0.180
IsCodexRunner reports whether runner is exactly trimmed "codex" or "codex-tty".
func IsGrokRunner ¶ added in v0.0.136
IsGrokRunner reports whether runner is exactly trimmed "grok" or "grok-tty".
func RunnerFamily ¶ added in v0.0.197
RunnerFamily returns the provider family for a runner name. Codex aliases (codex, codex-tty) → "codex"; grok aliases → "grok"; anything else → the trimmed runner string.
func SameRunnerFamily ¶ added in v0.0.197
SameRunnerFamily reports whether a and b are the same provider family. Empty names are not the same family as anything (including each other).
func WriteIdlePolicy ¶ added in v0.0.135
func WriteIdlePolicy(home, sessionID string, p IdlePolicy) error
WriteIdlePolicy writes compact JSON. Zero timeout + ExitOnIdle → 10m.
Types ¶
type Config ¶
type Config struct {
DefaultAgentRunner string `json:"default_agent_runner"`
DefaultModel string `json:"default_model"`
LastSession string `json:"last_session"`
// SelectedWorkspace is the active workspace path for status + new sessions.
SelectedWorkspace string `json:"selected_workspace,omitempty"`
// RecentWorkspaces is an MRU list of workspace paths (newest first, max ~12).
RecentWorkspaces []string `json:"recent_workspaces,omitempty"`
}
Config persisted at config.json under the store home.
type IdlePolicy ¶ added in v0.0.135
type IdlePolicy struct {
ExitOnIdle bool `json:"exit_on_idle"`
IdleTimeout time.Duration `json:"-"`
}
IdlePolicy is the session-dir idle-exit file (not meta.json).
func ReadIdlePolicy ¶ added in v0.0.135
func ReadIdlePolicy(home, sessionID string) (p IdlePolicy, found bool, err error)
ReadIdlePolicy loads idle-policy.json. Missing file → found=false, err=nil.
type LogRecord ¶ added in v0.0.145
type LogRecord struct {
Timestamp string `json:"timestamp"`
Level string `json:"level"`
Component string `json:"component"`
Message string `json:"message"`
}
LogRecord is one durable, session-scoped runtime diagnostic. Logs are kept separate from session state so normal progress never pollutes meta.json.
type Message ¶
type Message struct {
ID string `json:"id"`
Text string `json:"text"`
SessionID string `json:"session_id"`
CreatedAt string `json:"created_at"`
}
Message is a queued user follow-up in messages.jsonl.
type Session ¶
type Session struct {
Meta SessionMeta
}
Session wraps session metadata for API consumers.
type SessionMeta ¶
type SessionMeta struct {
Runner string `json:"runner"`
SessionID string `json:"session_id"`
InitialPrompt string `json:"initial_prompt,omitempty"`
RunnerSessionID string `json:"runner_session_id,omitempty"`
// RunnerSessions maps provider family (codex, grok, or exact runner name)
// to that family's last bound runner_session_id. RunnerSessionID is the
// active family's id; this map keeps inactive families so a later runner
// switch can resume instead of starting over.
RunnerSessions map[string]string `json:"runner_sessions,omitempty"`
TerminalSessionID string `json:"terminal_session_id,omitempty"`
Status string `json:"status"`
Workspace string `json:"workspace,omitempty"`
Model string `json:"model,omitempty"`
// PrependPaths are absolute directories prepended to the TTY child PATH (ordered, no dedup).
PrependPaths []string `json:"prepend_paths,omitempty"`
// Env is ordered KEY=VALUE entries applied to the TTY child (last-win per key).
Env []string `json:"env,omitempty"`
// AgentRunnerConfigHome is the agent data dir (grok: GROK_HOME, codex: CODEX_HOME).
AgentRunnerConfigHome string `json:"agent_runner_config_home,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
SessionMeta is stored in sessions/<session_id>/meta.json.
func FindByCodexSessionID ¶ added in v0.0.180
func FindByCodexSessionID(store Store, id string) (SessionMeta, error)
FindByCodexSessionID finds the unique codex/codex-tty session for runner_session_id. Cardinality: 0 → not found; 1 → that meta; 2+ → ambiguous (session ids ascending).
func FindByGrokSessionID ¶ added in v0.0.136
func FindByGrokSessionID(store Store, id string) (SessionMeta, error)
FindByGrokSessionID finds the unique grok/grok-tty session for runner_session_id. Cardinality: 0 → not found; 1 → that meta; 2+ → ambiguous (session ids ascending).
func ListByRunnerSessionID ¶ added in v0.0.136
func ListByRunnerSessionID(store Store, id string, runners ...string) ([]SessionMeta, error)
ListByRunnerSessionID returns all session metas whose trimmed runner_session_id equals trimmed id. When runners is non-empty, meta.runner must be one of those exact trimmed names. Empty/whitespace id returns errEmptyGrokSessionID.
func (*SessionMeta) ClearCurrentFamilyBind ¶ added in v0.0.197
func (m *SessionMeta) ClearCurrentFamilyBind()
ClearCurrentFamilyBind clears the live slot and RunnerSessions[family(runner)]. Other families are left intact.
func (*SessionMeta) HydrateRunnerSessions ¶ added in v0.0.197
func (m *SessionMeta) HydrateRunnerSessions()
HydrateRunnerSessions fills RunnerSessions[family(runner)] from the live RunnerSessionID when that map slot is empty. In-memory only; does not persist.
func (SessionMeta) RunnerSessionIDForFamily ¶ added in v0.0.197
func (m SessionMeta) RunnerSessionIDForFamily(family string) string
RunnerSessionIDForFamily returns the bound provider id for family, using the map first and the live slot when the current runner is that family.
func (*SessionMeta) SetRunnerSessionBind ¶ added in v0.0.197
func (m *SessionMeta) SetRunnerSessionBind(id string)
SetRunnerSessionBind sets the live runner_session_id and the map slot for the current runner's family. Empty id only updates the live slot.
func (*SessionMeta) UnmarshalJSON ¶ added in v0.0.43
func (m *SessionMeta) UnmarshalJSON(data []byte) error
type Store ¶
type Store interface {
Home() string
Config() (Config, error)
SaveConfig(Config) error
ListSessions() ([]SessionMeta, error)
ClearAllSessions() error
GetSession(sessionID string) (*Session, error)
CreateSession(sessionID string, meta SessionMeta) error
UpdateSessionStatus(sessionID, status string) error
UpdateSessionRunnerSessionID(sessionID, runnerSessionID string) error
// ClearSessionRunnerSessionID removes the live runner_session_id and the
// current family's RunnerSessions slot so the next AutoSendOrResume can
// ModeRun that family (orphan/missing provider sessions). Other families
// in the map are kept. No-op when the current family is already unbound.
ClearSessionRunnerSessionID(sessionID string) error
// ActivateSessionRunner sets meta.runner to runner and restores the live
// runner_session_id from RunnerSessions[family] when present (else clears
// the live slot). Other families in the map are kept.
ActivateSessionRunner(sessionID, runner string) error
UpdateSessionTerminalSessionID(sessionID, terminalSessionID string) error
// UpdateSessionWorkspace sets meta.workspace (e.g. after Grok session relocate).
UpdateSessionWorkspace(sessionID, workspace string) error
// UpdateSessionEnvConfig writes session-scoped TTY child env fields.
// prependPaths/env replace the stored lists; configHome replaces when non-empty.
UpdateSessionEnvConfig(sessionID string, prependPaths, env []string, configHome string) error
AppendEvent(sessionID string, ev types.AgentEvent) error
ReadEvents(sessionID string, afterOffset int64) ([]types.AgentEvent, int64, error)
AppendMessage(sessionID, text string) (Message, error)
PopMessages(sessionID string) ([]Message, error)
ListMessages(sessionID string) ([]Message, error)
}
Store is the durable agent-run storage contract. Session identity is bare sessionID; runner is metadata on SessionMeta only.
func NewFileStore ¶
NewFileStore opens the file-backed store at home. Non-empty home wins; empty home falls back to AGENT_RUN_HOME or ~/.agent-run.