agentstorage

package
v0.0.135 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 9 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 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 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 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 (*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