desktop

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package desktop implements the BuildMax desktop app (Wails) and is used by cmd/buildmax-desktop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(assets fs.FS) error

Run starts the Wails desktop application. assets is the embedded frontend filesystem (e.g. from //go:embed all:frontend in the main package). It creates an App, wires lifecycle hooks, and calls wails.Run.

Types

type App

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

App holds desktop application state and implements Wails lifecycle hooks. Each project gets its own AgentApp and ApprovalHandler instance, created lazily on first use.

func NewApp

func NewApp() *App

NewApp returns a new App instance.

func (*App) CancelRun

func (a *App) CancelRun(projectID string) error

CancelRun cancels the in-flight run for the given project, if any. Cancellation is cooperative: the agent loop returns the partial assistant reply produced so far and emits desktop/stream-done as a normal completion. Calling CancelRun when no run is in flight is a no-op.

func (*App) ClearProjectSessions

func (a *App) ClearProjectSessions(projectID string) ([]string, error)

func (*App) CreateProject

func (a *App) CreateProject(name, folderPath string) (*Project, error)

CreateProject creates a new project with the given name and folder.

func (*App) DeleteProject

func (a *App) DeleteProject(id string) error

DeleteProject removes a project and closes its AgentApp if one was running.

func (*App) DeleteSession

func (a *App) DeleteSession(sessionID string) error

func (*App) DoLogin

func (a *App) DoLogin(serverURL, email, otp string) (*auth.AuthInfo, error)

DoLogin authenticates with a single-use login code and saves credentials on success. It is the recovery path: claiming a new account, or getting back in after a forgotten password.

func (*App) DoLoginWithPassword

func (a *App) DoLoginWithPassword(serverURL, email, password string) (*auth.AuthInfo, error)

DoLoginWithPassword authenticates with a password and saves credentials on success. This is the everyday path.

func (*App) GetAuthStatus

func (a *App) GetAuthStatus() (*auth.AuthInfo, error)

GetAuthStatus returns the current authentication state for the frontend.

func (*App) GetGitBranch

func (a *App) GetGitBranch(projectID string) (string, error)

GetGitBranch returns the current git branch for the given project's folder, or an empty string if the folder is not a git repository.

func (*App) GetRunStatus

func (a *App) GetRunStatus(projectID, sessionID string) (RunStatusPayload, error)

func (*App) GetSession

func (a *App) GetSession(sessionID string) (SessionDetail, error)

GetSession loads one session by ID and returns it for display.

func (*App) GetSlashAgents

func (a *App) GetSlashAgents(projectID string) (SlashAgentsResult, error)

GetSlashAgents returns all agent types (builtin + user-defined) for the project.

func (*App) GetSlashMCP

func (a *App) GetSlashMCP(projectID string) (SlashMCPResult, error)

GetSlashMCP returns the MCP server status for the given project.

func (*App) GetSlashModels

func (a *App) GetSlashModels(projectID string) (SlashModelsResult, error)

GetSlashModels returns configured models and the active model for a project.

func (*App) GetSlashSkills

func (a *App) GetSlashSkills(projectID string) (SlashSkillsResult, error)

GetSlashSkills returns all skills discovered for the given project.

func (*App) GetWorkspaceDiff

func (a *App) GetWorkspaceDiff(projectID string) (git.WorkspaceDiff, error)

GetWorkspaceDiff returns the current git-backed changed-file view for a project.

func (*App) ListProjects

func (a *App) ListProjects() ([]Project, error)

ListProjects returns all saved projects.

func (*App) ListSessions

func (a *App) ListSessions() ([]session.SessionItem, error)

ListSessions returns all sessions across all projects.

func (*App) Logout

func (a *App) Logout() error

Logout clears stored credentials and revokes the session on the server.

A server that cannot be reached is not a failed logout: the credentials are gone from this machine either way, and returning an error would leave the UI showing someone as signed in when they are not.

func (*App) OpenFolderDialog

func (a *App) OpenFolderDialog() (string, error)

OpenFolderDialog opens a native directory picker and returns the selected path.

func (*App) RenameProject

func (a *App) RenameProject(id, newName string) error

RenameProject updates the name of a project.

func (*App) RenameSession

func (a *App) RenameSession(sessionID, title string) error

func (*App) RequestOTP

func (a *App) RequestOTP(serverURL, email, intent string) error

RequestOTP calls the server's OTP endpoint.

func (*App) RespondApproval

func (a *App) RespondApproval(projectID string, approved bool)

RespondApproval is called by the frontend when the user approves or denies a tool call. projectID must match the project that triggered the desktop/approval-request event.

func (*App) SendMessageStream

func (a *App) SendMessageStream(projectID, sessionID, prompt string) error

SendMessageStream runs a prompt in the given project and session with streaming. It returns immediately and emits desktop/stream-delta, then desktop/stream-done or desktop/stream-error. sessionID may be empty to start a new session.

At most one run per project may be in flight; a second call while a run is active returns an error so the frontend can surface it.

func (*App) SetProjectModel

func (a *App) SetProjectModel(projectID, modelName string) error

SetProjectModel switches the active model for a project's agent.

func (*App) SetSessionPinned

func (a *App) SetSessionPinned(sessionID string, pinned bool) error

func (*App) Shutdown

func (a *App) Shutdown(_ context.Context)

Shutdown closes all per-project AgentApp instances and cancels any in-flight runs.

func (*App) Startup

func (a *App) Startup(ctx context.Context)

Startup is called by Wails when the app is starting. AgentApp instances are created lazily on first use per project.

type ApprovalRequestPayload

type ApprovalRequestPayload struct {
	ProjectID string         `json:"project_id"`
	ToolName  string         `json:"tool_name"`
	Args      map[string]any `json:"args"`
}

ApprovalRequestPayload is emitted to the frontend when a tool call needs approval.

type DesktopApprovalHandler

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

DesktopApprovalHandler implements agent.ApprovalHandler for the Wails desktop app. It emits a Wails event to the frontend and blocks until RespondApproval is called.

func (*DesktopApprovalHandler) RequestApproval

func (h *DesktopApprovalHandler) RequestApproval(name string, args map[string]any) bool

RequestApproval emits an approval-request event to the frontend and blocks until the user responds via RespondApproval. Returns false if the app context is not ready.

type Project

type Project struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	FolderPath string `json:"folder_path"`
	CreatedAt  string `json:"created_at"`
	LastUsedAt string `json:"last_used_at"`
}

Project is a named local folder that groups desktop sessions.

type ReplyPayload

type ReplyPayload struct {
	Reply                 string `json:"reply"`
	SessionID             string `json:"session_id"`
	ContextTokens         int    `json:"context_tokens"`
	ContextWindow         int    `json:"context_window"`
	PromptTokens          int    `json:"prompt_tokens"`
	CompletionTokens      int    `json:"completion_tokens"`
	TotalPromptTokens     int    `json:"total_prompt_tokens"`
	TotalCompletionTokens int    `json:"total_completion_tokens"`
}

ReplyPayload is returned when a desktop prompt completes successfully.

type RunStatusPayload

type RunStatusPayload struct {
	ContextTokens         int `json:"context_tokens"`
	ContextWindow         int `json:"context_window"`
	PromptTokens          int `json:"prompt_tokens"`
	CompletionTokens      int `json:"completion_tokens"`
	TotalPromptTokens     int `json:"total_prompt_tokens"`
	TotalCompletionTokens int `json:"total_completion_tokens"`
}

type SessionDetail

type SessionDetail struct {
	ID        string        `json:"id"`
	Title     string        `json:"title,omitempty"`
	CreatedAt string        `json:"created_at"`
	Messages  []llm.Message `json:"messages,omitempty"`
}

SessionDetail is the session payload returned to the frontend for display.

type SlashAgentEntry

type SlashAgentEntry struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	IsBuiltin   bool   `json:"is_builtin"`
}

type SlashAgentsResult

type SlashAgentsResult struct {
	Agents []SlashAgentEntry `json:"agents"`
}

type SlashMCPResult

type SlashMCPResult struct {
	LoadError string           `json:"load_error,omitempty"`
	Servers   []SlashMCPServer `json:"servers"`
}

type SlashMCPServer

type SlashMCPServer struct {
	ID        string `json:"id"`
	Type      string `json:"type"`
	OK        bool   `json:"ok"`
	ToolCount int    `json:"tool_count"`
	Error     string `json:"error,omitempty"`
}

type SlashModelEntry

type SlashModelEntry struct {
	Name          string `json:"name"`
	ProviderModel string `json:"provider_model,omitempty"`
	IsCurrent     bool   `json:"is_current"`
	// Managed and Destination say where this model sends prompts. Two entries
	// can share a display name and reach different places, so the selector has
	// to be able to tell them apart.
	Managed     bool   `json:"managed"`
	Destination string `json:"destination,omitempty"`
}

type SlashModelsResult

type SlashModelsResult struct {
	Current string            `json:"current"`
	Models  []SlashModelEntry `json:"models"`
}

type SlashSkillEntry

type SlashSkillEntry struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Path        string `json:"path"`
}

type SlashSkillsResult

type SlashSkillsResult struct {
	Skills []SlashSkillEntry `json:"skills"`
}

type StreamErrorPayload

type StreamErrorPayload struct {
	Message string `json:"message"`
}

StreamErrorPayload is emitted when streaming fails (event desktop/stream-error).

type ToolEndPayload

type ToolEndPayload struct {
	ToolCallID string `json:"tool_call_id"`
	ToolName   string `json:"tool_name"`
	DurationMs int64  `json:"duration_ms,omitempty"`
	IsError    bool   `json:"is_error,omitempty"`
	Denied     bool   `json:"denied,omitempty"`
	Reason     string `json:"reason,omitempty"`
}

ToolEndPayload is emitted when a tool call finishes or is denied.

type ToolStartPayload

type ToolStartPayload struct {
	ToolCallID string `json:"tool_call_id"`
	ToolName   string `json:"tool_name"`
	Args       string `json:"args"`
}

ToolStartPayload is emitted when a tool call begins executing.

Jump to

Keyboard shortcuts

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