appsession

package
v1.5.46 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 37 Imported by: 1 module, 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 appsession is the UI-neutral controller behind the Golder desktop app. It owns one conversation at a time: the session file, the live run configuration, the agent loop, the approval channel and the transcript the view renders.

Nothing in this package imports a GUI toolkit. The MyGo view under gui/mygoui consumes the Controller through Snapshot, Commands and Events, which keeps the orchestration testable without a window and lets the CLI/TUI keep their own front-ends unchanged.

Index

Constants

View Source
const (
	ActionNewSession = "gui:new-session"
	ActionCompact    = "gui:compact"
	ActionCopyLast   = "gui:copy-last"
)

GUI-only action IDs. They are not slash commands: they exist because a window can do something a terminal cannot.

Variables

View Source
var ErrBusy = errors.New("a turn is already running")

ErrBusy is returned by commands that cannot run while an agent turn is in flight.

View Source
var ErrClosed = errors.New("controller is closed")

ErrClosed is returned once Close has been called.

View Source
var ErrNotPending = errors.New("approval is no longer pending")

ErrNotPending is returned when an approval id is unknown: it was answered already, withdrawn when the run ended, or never issued.

Functions

func ModelForProvider

func ModelForProvider(providerName string) string

ModelForProvider returns the model a switch to providerName would start with.

func ParseDiffStat

func ParseDiffStat(patch string) (files, added, deleted int)

ParseDiffStat reads the summary line git prints after a diff, if present.

func PermissionModes

func PermissionModes() []string

PermissionModes lists the selectable modes in display order.

func ThinkingLevels

func ThinkingLevels() []string

ThinkingLevels lists the selectable reasoning levels.

Types

type Action

type Action struct {
	ID           string
	Label        string
	Category     string
	Description  string
	ArgumentHint string
	Source       string
}

Action is one runnable command surfaced by the command palette: a slash command, a GUI action, or a skill.

type ActionResult

type ActionResult struct {
	// Message is text to show in the transcript.
	Message string
	// Prompt, when non-empty, is a turn to run after Message.
	Prompt string
}

ActionResult is what running an action produced.

type Answer

type Answer int

Answer is the view's decision for one approval.

const (
	// AnswerDeny blocks the call.
	AnswerDeny Answer = iota
	// AnswerOnce approves this call only.
	AnswerOnce
	// AnswerSession approves this shape of call for the rest of the session.
	AnswerSession
)

type ApprovalView

type ApprovalView struct {
	ID string
	// Kind is "consent" or "trust".
	Kind string
	Tool string
	// Summary is the call's one-line preview.
	Summary string
	// Rationale is the reviewer's explanation, already in the user's language.
	Rationale string
	// Source names the deciding layer (jev, local, llm, static).
	Source string
	// Level is the gate's grade (allow, confirm, contain, deny).
	Level string
	// Mode is the approval mode in force.
	Mode string
	// Needs lists the capabilities the call requires.
	Needs []string
	// TrustDir names the folder a trust question is about.
	TrustDir string
	// Origin names a sub-agent that asked, when it is not this conversation.
	Origin string
}

ApprovalView is one pending human decision. The controller owns the reply channel; the view only renders Require and answers with an Answer.

type BrowserPreview

type BrowserPreview struct {
	Socket  string
	Browser string
	URL     string
	Title   string
}

BrowserPreview is one live browser page the GUI can show read-only.

type Changes

type Changes struct {
	Files      []FileStatus
	Patch      string
	Added      int
	Deleted    int
	Truncated  bool
	NotGitRepo bool
}

Changes is the project's uncommitted work, for the changes drawer.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller owns one conversation and the run in flight, if any.

func New

func New(opts Options) *Controller

New creates a controller. Open must be called before any other command.

func (*Controller) BrowserScreenshot

func (c *Controller) BrowserScreenshot(ctx context.Context, socket string, fullPage bool) ([]byte, error)

BrowserScreenshot returns the active tab's viewport as PNG. The caller draws it; nothing here needs a terminal graphics protocol.

func (*Controller) Browsers

func (c *Controller) Browsers(ctx context.Context) []BrowserPreview

Browsers discovers Golder browser panes under the project's .golder directory. Discovery is shallow and bounded: profile directories are never walked.

func (*Controller) Cancel

func (c *Controller) Cancel()

Cancel interrupts the run in flight. It is a no-op when nothing runs.

func (*Controller) CapturePane

func (c *Controller) CapturePane(ctx context.Context, session, pane string, lines int) (string, error)

CapturePane returns a pane's screen as text, bounded to lines rows.

func (*Controller) ChangedFiles

func (c *Controller) ChangedFiles(ctx context.Context) ([]FileStatus, error)

ChangedFiles returns just the file list, for a cheap status refresh.

func (*Controller) Changes

func (c *Controller) Changes(ctx context.Context) (Changes, error)

Changes returns the project's uncommitted work: a status list and a unified patch. A directory that is not a Git repository reports so instead of an error, because the drawer is always available.

func (*Controller) Close

func (c *Controller) Close() error

Close ends the controller: a run in flight is cancelled and every pending approval is answered as unanswered, which the gates treat as fail-closed.

func (*Controller) Compact

func (c *Controller) Compact(ctx context.Context) (string, error)

Compact replaces the context with a fresh summary plus the recent tail.

func (*Controller) Events

func (c *Controller) Events() <-chan Event

Events returns the ordered event stream. The channel is never closed; Close ends delivery and unblocks the producer.

func (*Controller) Export

func (c *Controller) Export(format, path string) error

Export writes the session as JSONL or Markdown.

func (*Controller) IsRunning

func (c *Controller) IsRunning() bool

IsRunning reports whether a turn is in flight.

func (*Controller) ListActions

func (c *Controller) ListActions(ctx context.Context) []Action

ListActions returns every action the command palette can run: the session's slash commands plus the window-only actions.

func (*Controller) ListModels

func (c *Controller) ListModels(ctx context.Context) ([]ModelOption, error)

ListModels returns the models the live provider serves, newest families first. A failed catalog fetch falls back to the bundled floor for the provider, never to an empty picker.

func (*Controller) ListSessions

func (c *Controller) ListSessions(ctx context.Context) ([]SessionSummary, error)

ListSessions returns the stored sessions, newest first, marking the current.

func (*Controller) NewSession

func (c *Controller) NewSession(ctx context.Context) error

NewSession starts a fresh conversation in the same project.

func (*Controller) Open

func (c *Controller) Open(ctx context.Context) error

Open resolves the session (resume or fresh), assembles the live configuration and wires the slash commands and hooks. It is idempotent only in the sense that a second call reports an error instead of replacing a live session.

func (*Controller) OpenProject

func (c *Controller) OpenProject(path string)

OpenProject notes the project directory for display. The process never chdir's: tools stay rooted where the app started, matching the CLI.

func (*Controller) PendingApprovals

func (c *Controller) PendingApprovals() []ApprovalView

PendingApprovals returns the approvals waiting for an answer.

func (*Controller) Project

func (c *Controller) Project() string

Project returns the project directory.

func (*Controller) Providers

func (c *Controller) Providers() []string

Providers lists the conversation providers, ready ones first.

func (*Controller) RespondApproval

func (c *Controller) RespondApproval(id string, a Answer) error

RespondApproval answers one pending approval.

func (*Controller) Resume

func (c *Controller) Resume(ctx context.Context, id string) error

Resume switches to a stored session after saving the current one.

func (*Controller) RunAction

func (c *Controller) RunAction(ctx context.Context, id, args string) (ActionResult, error)

RunAction runs one action by ID. A prompt-producing command is submitted as the next turn; an action command's status line is returned as Message.

func (*Controller) SelectModel

func (c *Controller) SelectModel(ctx context.Context, providerName, model string, thinking agentcore.ThinkingLevel) error

SelectModel switches the live model (and provider, when the id belongs to another gateway).

func (*Controller) SessionID

func (c *Controller) SessionID() string

SessionID returns the active session id.

func (*Controller) SetPermissionMode

func (c *Controller) SetPermissionMode(ctx context.Context, name string) error

SetPermissionMode switches the live approval mode.

func (*Controller) SetThinking

func (c *Controller) SetThinking(level agentcore.ThinkingLevel) error

SetThinking changes the reasoning level for the next turn.

func (*Controller) Snapshot

func (c *Controller) Snapshot() Snapshot

Snapshot returns the complete current state.

func (*Controller) Submit

func (c *Controller) Submit(ctx context.Context, text string) error

Submit sends one prompt as a new turn.

func (*Controller) WorkspacePanes

func (c *Controller) WorkspacePanes(ctx context.Context, session string) ([]PaneInfo, error)

WorkspacePanes lists one workspace's panes.

func (*Controller) Workspaces

func (c *Controller) Workspaces(ctx context.Context) ([]WorkspaceInfo, error)

Workspaces discovers the named sessions under the golder state root and probes each endpoint. Discovery never starts a daemon.

type Event

type Event struct {
	Seq      uint64
	Session  string
	Kind     EventKind
	Item     *Item
	ID       string
	Approval *ApprovalView
	Status   *Status
	Error    string
}

Event is one ordered controller notification. Seq increases monotonically for the controller's lifetime, so a view can detect a missed event and re-read Snapshot.

type EventKind

type EventKind string

EventKind classifies a controller event.

const (
	// EventItemAddressed means Item was appended.
	EventItemAdded EventKind = "item_added"
	// EventItemUpdated means the item of Item.ID changed.
	EventItemUpdated EventKind = "item_updated"
	// EventApproval means a new approval is pending.
	EventApproval EventKind = "approval_requested"
	// EventApprovalDone means the approval of ID was answered or withdrawn.
	EventApprovalDone EventKind = "approval_resolved"
	// EventStatus means the live configuration or run state changed.
	EventStatus EventKind = "status"
	// EventRunEnd means the run ended; Error carries a failure.
	EventRunEnd EventKind = "run_end"
)

type FileStatus

type FileStatus struct {
	Path   string
	Status string
}

FileStatus is one changed file in the project.

type Item

type Item struct {
	ID   string
	Kind ItemKind
	Text string
	// Done is true once the item can no longer change. Streaming assistant text
	// and a running tool are open.
	Done bool
	// Tool holds the structured call for ItemTool.
	Tool *ToolState
	// Note holds the verdict for ItemNote.
	Note *NoteState
	// Failed marks a tool error, a denied call or a failed run.
	Failed bool
	// Time is when the item first appeared.
	Time time.Time
}

Item is one row of the transcript. The view renders it and never mutates it; a change arrives as an Event that replaces the item of the same ID.

type ItemKind

type ItemKind string

ItemKind classifies one transcript entry.

const (
	// ItemUser is a message the person sent.
	ItemUser ItemKind = "user"
	// ItemAssistant is model text: streaming while Done is false.
	ItemAssistant ItemKind = "assistant"
	// ItemThinking is reasoning text, shown collapsed by the view.
	ItemThinking ItemKind = "thinking"
	// ItemTool is one tool call and its (bounded) result.
	ItemTool ItemKind = "tool"
	// ItemNote is a permission-gate verdict (approval, denial, sandbox routing).
	ItemNote ItemKind = "note"
	// ItemNotice is a controller-level announcement (compaction, provider retry,
	// interrupt, persistence failure).
	ItemNotice ItemKind = "notice"
)

type ModelOption

type ModelOption struct {
	ID       string
	Provider string
	// Current marks the model in use.
	Current bool
	// Default marks the model a new session would start with.
	Default bool
}

ModelOption is one choice in the model picker.

type NoteState

type NoteState struct {
	Tool      string
	Kind      int
	Level     string
	Summary   string
	Source    string
	Rationale string
	Mode      string
	// Granted is true for approvals that let a call proceed.
	Granted bool
	// Failure is true for denials and blocks.
	Failure bool
}

NoteState is one permission-gate announcement.

type Options

type Options struct {
	Model        string
	ProviderName string
	Provider     provider.Provider
	BaseURL      string
	APIKey       string
	Protocol     string
	Version      string

	ThinkingLevel agentcore.ThinkingLevel
	Tools         []agentcore.AgentTool
	SysPrompt     string
	Prompt        runtime.PromptInputs

	// ResumeID loads an existing session instead of creating one.
	ResumeID string
	// Approve grants the launch directory session trust up front.
	Approve bool

	Skills        []*runtime.Skill
	Extensions    *extensions.Manager
	ConfigPrompts []string
	CliPrompts    []string
	// NoPromptTemplates disables prompt-template discovery.
	NoPromptTemplates bool

	Permissions *permissions.State
	ReviewNotes *run.ReviewNotes
	Budget      *contextbudget.State
	MaxContext  config.MaxContext

	// Cwd is the project directory. Empty means the process working directory.
	Cwd string
	// Store overrides the shared session store (tests).
	Store *session.Store
	// Warn receives non-fatal setup warnings; nil discards them.
	Warn io.Writer
}

Options is the assembled run environment the GUI controller starts from. The command builds it with run.SetupEnv, exactly as the CLI/TUI do, so the GUI shares provider resolution, tool construction, skills and the system prompt.

type PaneInfo

type PaneInfo struct {
	ID       string
	Title    string
	Name     string
	Program  string
	Cwd      string
	Focused  bool
	Agent    string
	Revision uint64
}

PaneInfo is one pane of a workspace.

type SessionSummary

type SessionSummary struct {
	ID        string
	Title     string
	Model     string
	Provider  string
	Cwd       string
	UpdatedAt time.Time
	Current   bool
}

SessionSummary is one row of the session sidebar.

type Snapshot

type Snapshot struct {
	Status
	Project string
	// Items is the transcript in display order.
	Items []Item
	// Pending are the approvals waiting for an answer, oldest first.
	Pending []ApprovalView
}

Snapshot is a complete view of the controller, taken at one instant. A view builds from it and then applies Events.

type Status

type Status struct {
	Model        string
	Provider     string
	Thinking     agentcore.ThinkingLevel
	Permission   string
	Running      bool
	RunID        string
	SessionID    string
	Title        string
	ContextUsed  int
	ContextLimit int
	// Error is the last controller error worth showing, "" when none.
	Error string
}

Status is the live state the composer footer shows.

type ToolState

type ToolState struct {
	ID     string
	Name   string
	Input  map[string]any
	Output string
	// Running is true until the executor reports the end.
	Running bool
	// Error is the executor's failure flag, not a parse result.
	Error bool
}

ToolState is one tool invocation, as the view shows it.

type WorkspaceInfo

type WorkspaceInfo struct {
	Session string
	Cwd     string
	Socket  string
	Running bool
	Panes   int
	Error   string
}

WorkspaceInfo is one named terminal workspace, as the GUI lists it.

Jump to

Keyboard shortcuts

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