Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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"`
// Worktree is the yottacode-managed worktree name this session was
// launched in (via `yottacode --worktree <name>`). Empty for sessions
// running against the main checkout. Stored so `sessions resume`
// lands back in the correct worktree dir even if the user moved or
// renamed the repo. Omitted from JSON when empty so existing session
// files load unchanged.
Worktree string `json:"worktree,omitempty"`
// TotalUsage is the cumulative token tally across every assistant
// turn in this session. Written by AddUsage on each EventDone.
// Omitted from JSON when zero so existing session files load
// byte-identical until the first usage is recorded.
TotalUsage adapter.Usage `json:"total_usage,omitzero"`
// ModelUsage is per-model breakdown — users mix models within a
// session (Anthropic for code review, Gemini for grep, etc.) and
// the cost calculator needs to know which model produced each
// turn. Keyed by model ID exactly as the adapter reported it.
ModelUsage map[string]adapter.Usage `json:"model_usage,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
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 ¶
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 (*Session) AddUsage ¶ added in v0.3.0
AddUsage records the per-turn usage that just landed on an assistant message into the session's running totals. Safe to call with a nil receiver or nil usage — both branches no-op. Caller is responsible for Save() if the new totals should be persisted now; most callers persist on the same cadence as Messages.
func (*Session) Save ¶
Save atomically writes the session to disk.
The temp file gets a unique name (os.CreateTemp) rather than a fixed "<path>.tmp" suffix: two yottacode processes editing the same session (e.g. two terminals, or one `--continue` alongside a `--resume`) would otherwise write to the same temp path and clobber each other's in-flight write, so one process's history would be silently lost on rename. A per-write unique temp name makes concurrent saves last-writer-wins on the final file instead of corrupting it.
type SessionInfo ¶
type SessionInfo struct {
ID string
Name string
Model string
Created time.Time
Messages int
// Worktree is the yottacode worktree name this session ran in, or
// empty for the main checkout. Surfaced in `yottacode sessions list`
// output so users can tell which sessions belong to which worktree.
Worktree string
}
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.
type SessionUsageSummary ¶ added in v0.3.0
type SessionUsageSummary struct {
ID string
Name string
Model string
Created time.Time
TotalUsage adapter.Usage
ModelUsage map[string]adapter.Usage
}
SessionUsageSummary is a stripped per-session view used by the daily-rollup scan. We avoid decoding Messages (the heavy field) so /usage can scan dozens of session files cheaply.
func UsageSince ¶ added in v0.3.0
func UsageSince(t time.Time) ([]SessionUsageSummary, error)
UsageSince scans every saved session newer than t and returns a per-session usage summary. Decodes only the lightweight metadata + usage fields — Messages stay on disk, keeping the scan cheap. Sessions older than t are filtered out by Created; sessions with no usage data still appear so the daily rollup can show "N sessions, no token data yet."