session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSessionInCwd = errors.New("no saved session in this directory")

ErrNoSessionInCwd is returned by LatestInCwd when no saved session has a Cwd field matching the requested directory. Sentinel so callers can present a friendly "no prior session in this directory" error without string matching.

Functions

func ExportMarkdown

func ExportMarkdown(s *Session) string

ExportMarkdown serializes a Session into a human-readable markdown document — useful for sharing a working session in a PR description, an issue, or just archiving. We deliberately omit the system message (boilerplate plus injected memory, not interesting to a reader) and fence tool output for clarity.

Living in the session package (rather than internal/tui) lets the non-interactive cobra subcommands call it without dragging the bubbletea/lipgloss dependency tree into the CLI binary's non-interactive paths.

Types

type Session

type Session struct {
	ID       string            `json:"id"`
	Name     string            `json:"name,omitempty"`
	Model    string            `json:"model"`
	Created  time.Time         `json:"created"`
	Cwd      string            `json:"cwd"`
	Messages []adapter.Message `json:"messages"`
	// Todos is the working plan written by the todo_write tool. Omitted
	// from JSON when empty so older session files load unchanged.
	Todos []agent.Todo `json:"todos,omitempty"`
	// contains filtered or unexported fields
}

Session is one resumable conversation persisted as JSON in ~/.yottacode/sessions/<id>.json.

Name is an optional human-readable label set via the /sessions picker's Rename action. It's a soft alias: Load will fall back to a Name match if the requested id doesn't resolve to a file.

func LatestInCwd added in v0.2.0

func LatestInCwd(cwd string) (*Session, error)

LatestInCwd returns the most recent saved session whose Cwd matches the given directory. Used by `yottacode --continue` (mirroring Claude Code's --continue) to skip the picker and resume the directory's last session directly. Returns an error wrapping errNoSessionInCwd when no saved session matches.

"Most recent" is determined by sorting all matches descending by Session.Created, falling back to the timestamp-prefixed ID when two sessions share an identical Created (test fixtures). The Cwd comparison is exact-string match — symlinked or differently-resolved paths won't unify; users hit by that should pass the matching path explicitly.

func Load

func Load(id string) (*Session, error)

Load reads a stored session by id (filename match) or name (Name field match). The legacy "last" keyword shortcut was retired alongside the /resume slash command — the /sessions picker (and the `yottacode sessions resume <id|name>` cobra subcommand) is the canonical path for "load the most recent" now, with the picker defaulting the cursor to the newest entry.

func New

func New(model, cwd string) (*Session, error)

New starts a fresh session and reserves its file path.

func (*Session) Save

func (s *Session) Save() error

Save atomically writes the session to disk.

type SessionInfo

type SessionInfo struct {
	ID       string
	Name     string
	Model    string
	Created  time.Time
	Messages int
}

SessionInfo is a metadata-only view returned by List.

func List

func List() ([]SessionInfo, error)

List returns every saved session's metadata, newest first. Doesn't load the full message log to keep this cheap for the /sessions slash command.

Jump to

Keyboard shortcuts

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