session

package
v0.9.3 Latest Latest
Warning

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

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

Documentation

Overview

Package session manages on-disk session entries at `<BaseDir>/sessions/<id>/`. A session is one Slack thread or one UI conversation: routing key, status, agent registry, log files, and an optional reference to a workspace whose folder is the agent cwd.

Sessions own no workspace files of their own — workspace is a shared folder (see internal/agents/workspace) that the pool resolves to a cwd at spawn time. See agents-design.md §0.2 for the refactor that removed the per-session git worktree.

Files in this package:

  • session.go — Meta + lifecycle (Create/Load/Save/Delete/SwitchWorkspace)
  • agents.go — per-session AgentEntry + Add/SetActive

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAgent

func AddAgent(layout config.Layout, id, name, provider string) error

AddAgent appends a new agent entry. Errors on duplicate name within the same session.

func Delete

func Delete(_ context.Context, layout config.Layout, id string) error

Delete removes the session folder. The workspace it points at is left untouched — workspaces are shared, so deleting a session must not delete its files.

func List

func List(layout config.Layout) ([]string, error)

List returns every session ID, sorted.

func SaveAgents

func SaveAgents(layout config.Layout, id string, agents []AgentEntry) error

SaveAgents atomically rewrites sessions/<id>/agents.json. nil becomes an empty array on disk so consumers don't have to handle `null`.

func SaveMeta

func SaveMeta(layout config.Layout, id string, meta Meta) error

SaveMeta atomically rewrites sessions/<id>/meta.json.

func SetActiveAgent

func SetActiveAgent(layout config.Layout, id, name string) error

SetActiveAgent updates meta.json's active_agent field. The named agent must already exist in agents.json.

func SwitchWorkspace

func SwitchWorkspace(_ context.Context, layout config.Layout, id, newWorkspace string) error

SwitchWorkspace changes the workspace a session points at. No filesystem work — the next agent spawn will resolve the new workspace path. Conversation, agent registry, and logs are preserved.

Types

type AgentEntry

type AgentEntry struct {
	Name         string    `json:"name"`
	Provider     string    `json:"provider"`
	CLISessionID string    `json:"cli_session_id,omitempty"`
	Status       string    `json:"status"`
	CreatedAt    time.Time `json:"created_at"`
	LastActive   time.Time `json:"last_active,omitempty"`
}

AgentEntry is one row in sessions/<id>/agents.json. CLISessionID is the resume key — wick captures it from the first stream-json event emitted by the CLI and persists it so subsequent spawns can pass `--resume <id>`. See agents-design.md §5.2.

type CreateOptions

type CreateOptions struct {
	ID        string
	Workspace string
	Origin    Origin
	ChannelID string
	// PresetSnapshot is the preset body copied into the session's
	// agent.md at creation time. Empty = caller will populate later
	// (e.g. when first agent is added). The design says we always
	// snapshot at session creation so re-opening a session never drifts
	// because someone edited the preset since.
	PresetSnapshot string
}

CreateOptions describes a new session. Workspace is optional — a session may be created without one, in which case the pool falls back to the tools-config default workspace (or a per-session temp dir if no default is set).

type Meta

type Meta struct {
	Workspace    string    `json:"workspace,omitempty"`
	Origin       Origin    `json:"origin"`
	ChannelID    string    `json:"channel_id,omitempty"`
	ActiveAgent  string    `json:"active_agent,omitempty"`
	Status       Status    `json:"status"`
	CreatedAt    time.Time `json:"created_at"`
	LastActive   time.Time `json:"last_active"`
	PendingInput []string  `json:"pending_input,omitempty"`
}

Meta is the persisted-on-disk shape of a session. PendingInput is the message buffer that survives wick restart so a session that was queued at shutdown gets its messages drained on next boot.

type Origin

type Origin string

Origin identifies where the session was first created from. Slack threads use thread_ts as the session ID; UI/API sessions use a UUID generated by wick.

const (
	OriginSlack Origin = "slack"
	OriginUI    Origin = "ui"
	OriginAPI   Origin = "api"
)

type Session

type Session struct {
	ID     string       `json:"id"`
	Meta   Meta         `json:"meta"`
	Agents []AgentEntry `json:"agents"`
}

Session is the in-memory view: ID + meta + agent registry. Mirrors the trio of files at sessions/<id>/.

func Create

func Create(_ context.Context, layout config.Layout, opt CreateOptions) (Session, error)

Create materializes sessions/<id>/: meta.json, agents.json (empty array), agent.md snapshot. No filesystem work touches the workspace — workspace folders live under workspaces/<name>/ and are shared across sessions; the session simply stores the workspace name as a reference.

func Load

func Load(layout config.Layout, id string) (Session, error)

Load reads meta.json + agents.json. Missing agents.json is treated as an empty list.

type Status

type Status string

Status is the high-level pool view: idle (no subprocess), queued (waiting for a slot), running (subprocess alive).

const (
	StatusIdle    Status = "idle"
	StatusQueued  Status = "queued"
	StatusRunning Status = "running"
)

Jump to

Keyboard shortcuts

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