agentstorage

package
v0.0.147 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

func AppendErrorLog(home, sessionID, component string, err error) error

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

func FormatRelativeAge(now, t time.Time) string

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 IdlePolicyPath added in v0.0.135

func IdlePolicyPath(home, sessionID string) string

IdlePolicyPath is $home/sessions/<sessionID>/idle-policy.json.

func IsGrokRunner added in v0.0.136

func IsGrokRunner(runner string) bool

IsGrokRunner reports whether runner is exactly trimmed "grok" or "grok-tty".

func LogsPath added in v0.0.145

func LogsPath(home, sessionID string) string

LogsPath is the durable JSONL diagnostic path for a session.

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.

func ReadLogs added in v0.0.145

func ReadLogs(home, sessionID string) ([]LogRecord, []byte, error)

ReadLogs returns parsed session logs and the original JSONL bytes. A session with no errors has no log file and returns an empty result.

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"`
	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 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) 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
	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

func NewFileStore(home string) (Store, error)

NewFileStore opens the file-backed store at home. Non-empty home wins; empty home falls back to AGENT_RUN_HOME or ~/.agent-run.

Jump to

Keyboard shortcuts

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