sessions

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sessions finds the conversations agents saved for a directory, so conch can list and resume them. Each agent keeps its own store; this package only reads them:

  • Claude Code: ~/.claude/projects/<encoded dir>/<session id>.jsonl
  • Codex: ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl (session_meta first)
  • Gemini CLI: ~/.gemini/tmp/<project>/chats/session-*.json
  • OpenCode: ~/.local/share/opencode/opencode.db (sqlite), or the older storage/session/*/*.json files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentName

func AgentName(agent string) string

AgentName is an agent's display name.

func Delete

func Delete(ctx context.Context, e Env, s Session, trashDir string) error

Delete removes a saved session: files move to trashDir (so a mistake can be undone), OpenCode's database entries are deleted through its CLI.

func Handoff

func Handoff(s Session, turns []Turn) string

Handoff renders a conversation as a Markdown document another agent can read to continue the work. Very long messages are cut, and when the whole conversation is too long the oldest messages are left out (the first request is always kept).

func Key

func Key(s Session) string

Key identifies a session among all agents' sessions.

func Match

func Match(ctx context.Context, e Env, list []Session, query string) map[string]string

Match finds the sessions whose title, branch, agent, ID or conversation contains every word of query (case-insensitive). For conversation matches the result has a snippet around the first word; metadata matches have an empty snippet. The map is keyed by Key(session).

Types

type ChatTurn added in v0.2.0

type ChatTurn struct {
	Seq       int    // its place in the whole conversation, from 0; stable as turns are added
	Role      string // "user", "assistant", "tool" or "note"
	Text      string // for a tool, its name
	Detail    string // for a tool, what it was used on, on one line: a file, a command
	Input     string // for a tool, what it was given, as a chat shows it
	InputKind string // "diff" (lines marked - and +), "code", or "" for text
	Output    string // for a tool, what came back
	Error     bool   // the tool failed
	Done      bool   // the tool's result has come
	Time      time.Time
	// contains filtered or unexported fields
}

ChatTurn is one entry of a conversation as a chat draws it: something the user typed, something the agent said, a tool it used — with what it was given and what came back — or a note (an interruption).

func Chat added in v0.2.0

func Chat(ctx context.Context, e Env, s Session) ([]ChatTurn, error)

Chat reads a session's conversation, oldest first: the newest turns.

type ChatUpdate added in v0.2.0

type ChatUpdate struct {
	Epoch string
	Ver   int64
	Reset bool
	Turns []ChatTurn
}

ChatUpdate is what a chat is sent: the turns that are new or changed since the version it has, or — Reset — the newest turns to start again from, when it has none, or another log's (a new conversation, a file rewritten, a server restarted).

func ChatSince added in v0.2.0

func ChatSince(ctx context.Context, e Env, s Session, epoch string, ver int64) (ChatUpdate, error)

ChatSince brings a session's chat up to date and says what a chat that has version ver of log epoch is missing.

type Env

type Env struct {
	Home   string
	Getenv func(string) string
}

Env is where agents keep their data.

func CurrentEnv

func CurrentEnv() Env

CurrentEnv is this process's environment.

type Session

type Session struct {
	Agent   string
	ID      string
	Dir     string // where it ran
	Branch  string // when the agent recorded it
	Title   string
	Started time.Time
	Updated time.Time
	// Path is the agent's session file, or its database (OpenCode).
	Path string
	// Cost is what the agent said the conversation cost, and Output the
	// tokens it generated; both 0 when the store doesn't say. Read from
	// the tail of the store, so listing stays cheap.
	Cost   float64
	Output int
}

Session is one saved agent conversation.

func List

func List(e Env, dirs []string, limit int) []Session

List returns the sessions that ran in any of dirs (or below them), newest first, at most limit. It asks every store itself and waits for the answer: callers of this one — search, sharing, usage — want what is there now, not what a store said a moment ago.

func ListStatus added in v0.1.3

func ListStatus(e Env, dirs []string, limit int) (list []Session, complete bool)

ListStatus is List, and whether every store answered. complete is false when an agent that keeps its sessions behind another program (see slow.go) was too slow: that agent's sessions are missing from the list, which is worth asking for again in a moment.

type Turn

type Turn struct {
	Role string // "user" or "assistant"
	Text string
	Time time.Time
}

Turn is one message of a saved conversation: what the user typed or what the agent answered. Tool calls, their output and reasoning are left out.

func Transcript

func Transcript(ctx context.Context, e Env, s Session) ([]Turn, error)

Transcript reads a session's conversation, oldest first.

Jump to

Keyboard shortcuts

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