pagehost

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 26 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 pagehost answers the desktop page's calls to the program that serves it: the Electron app's sidecar (blitz-tray --serve), and the tray's page in a browser on Windows. It holds what those calls do (the window's preferences, the service, the blitz command's installation, the OS sandbox, updates), so every host answers alike.

Index

Constants

View Source
const CheckEvery = 5 * 24 * time.Hour

CheckEvery is how long a check's answer stands: the app asks for the latest release when it opens only if the last check is older.

View Source
const KeepDownloads = 3

KeepDownloads is how many downloaded releases Dir keeps (EL-90a): the newest, the one staged to install always among them.

Variables

View Source
var ErrNotReady = errors.New("no update has been downloaded")

ErrNotReady is applying an update that hasn't been downloaded.

Functions

func License

func License(which string) (string, error)

License is one of the license texts the desktop app shows: "notice" (the NOTICE), "full" (the Apache License) or "third-party" (the notices of the software the app includes).

func ProgramExists

func ProgramExists(path string) bool

ProgramExists reports whether path is a file: the program a running service started from may have been removed since (DSK-51a).

func RemoveFromUserPath added in v0.7.1

func RemoveFromUserPath(dir string) error

RemoveFromUserPath takes dir out of the user's PATH on Windows: the uninstaller's (apps/electron/winsetup), for the folder Install put there (WIN-14). Nothing is written when it isn't there.

func SandboxStatus

func SandboxStatus(ctx context.Context) sandboxsetup.Status

SandboxStatus is whether the OS sandbox for the agent's commands works here (Linux: bubblewrap; "unsupported" elsewhere, where the page hides the setting).

Types

type CLIInstall

type CLIInstall struct {
	Link    string `json:"link"`
	Profile string `json:"profile"`
	// Removed lists the dead blitz links a reinstall took off PATH.
	Removed []string `json:"removed,omitempty"`
}

CLIInstall is what InstallCLI did: the link it made, and the shell startup file it added the link's directory to PATH in ("" if the directory was on PATH already).

func InstallCLI

func InstallCLI() (CLIInstall, error)

InstallCLI puts this app's blitz on the user's PATH: a link in a directory on it, else in ~/.local/bin, added to PATH in the shell's startup file. It does nothing when a blitz is on PATH already.

func ReinstallCLI

func ReinstallCLI() (CLIInstall, error)

ReinstallCLI links this app's blitz again, for when the one on PATH is another build's or a dead link (a developer's old bazel-bin, an app since moved): it removes the dead blitz links on PATH, points the blitz link the shell finds at this app's, and links it as InstallCLI does when there's none. A blitz on PATH that's a file, not a link, is the user's and is left alone.

type CLIStatus

type CLIStatus struct {
	// CLI is the blitz beside this app ("" if none was found).
	CLI string `json:"cli"`
	// OnPath is the blitz on the user's PATH, as their shell sets it (""
	// if none), and Installed whether it's this app's.
	OnPath    string `json:"on_path"`
	Installed bool   `json:"installed"`
	// Method is how it goes on PATH: "link" (a link in a folder on PATH,
	// macOS and Linux) or "path" (its folder added to the user's PATH,
	// Windows).
	Method string `json:"method"`
}

CLIStatus says where the blitz command is: the one that comes with this app, and the one a new terminal would run.

func CurrentCLIStatus

func CurrentCLIStatus() CLIStatus

CurrentCLIStatus reports where this app's blitz is and whether a terminal finds it (it asks the login shell, since the app's own PATH isn't the terminal's, on macOS especially).

type Downloads added in v0.9.12

type Downloads struct {
	Releases []string `json:"releases"`
	Bytes    int64    `json:"bytes"`
}

Downloads is what Dir holds of the releases downloaded: their tags, newest first, and their size in bytes.

type Host

type Host struct {
	Service Service
	// Beside is the directory blitzd is looked for in before PATH (the
	// host's own).
	Beside string
	// Version is the host's, which the page shows as the app's.
	Version string
	// Socket is the service's.
	Socket string
	// Tray is the tray's own program, which starts at login.
	Tray string
	// StartTray starts the tray in this session, where launchd doesn't
	// (Linux and Windows; nil: it isn't started).
	StartTray func() error
	// Prefs keeps the window's preferences (nil: the page keeps its own).
	Prefs *PrefsStore
	// Updates updates the desktop app the host runs in (nil: no updates).
	Updates *Updater
	// Use counts the desktop app's use, once a day (spec_054_active_installs
	// AI-01): the page says when its window opens or comes forward; nil,
	// not counted.
	Use *activity.Recorder
}

Host answers the page it serves (pageserver.HostPrefix) with what the desktop app's bindings do and a browser can't: the service's status and controls, starting at login, showing files, the licenses, the window's preferences, the blitz command and the OS sandbox. The page calls POST /host/<Method> with its arguments as a JSON array and gets the result as JSON, or {"error": "…"} with status 500, the method names being the desktop app's (window.go.main.App); GET /host/info lists them.

func (Host) Handler

func (h Host) Handler() http.Handler

Handler serves the page's calls under pageserver.HostPrefix.

func (Host) Repair added in v0.7.1

func (h Host) Repair() error

Repair rewrites login entries that name a program no longer there (an install that moved, as the desktop app's did in v0.7.0): the tray's, which it then starts, and the service's. What it can't repair it returns, joined.

type Prefs

type Prefs struct {
	// Theme is "system" (the default), "light" or "dark".
	Theme string `json:"theme"`
	// Workspaces are every workspace the window has opened, open ones in
	// tab order, then closed ones (most recent first) for reopening.
	Workspaces []WorkspacePrefs `json:"workspaces"`
	// Active is the directory of the workspace in view.
	Active string `json:"active,omitempty"`
	// ShowThoughts shows the model's thinking, collapsed.
	ShowThoughts bool `json:"show_thoughts"`
	// Density is "comfortable" (the default) or "compact".
	Density string `json:"density"`
	// Composer is where the chat input sits: "pinned" (the default, across
	// the window's foot) or "panel" (under the conversation).
	Composer string `json:"composer"`
	// Notifications is "on" (the default: when the agent finishes or waits
	// while the window is elsewhere) or "off".
	Notifications string `json:"notifications"`
	// Language is the window's language: "system" (the default) or a
	// catalog's tag such as "fr-CA".
	Language string `json:"language"`
	// Files shows the Files shelf beside the conversation.
	Files bool `json:"files"`
	// ShowHidden lists hidden files in the shelf: dotfiles, files git
	// ignores, and the agent's blocked paths.
	ShowHidden bool `json:"show_hidden"`
	// ChatWidth is the chat panel's width in pixels (0: a third of the
	// window).
	ChatWidth int `json:"chat_width,omitempty"`
	// FilesWidth is the Files shelf's width in pixels (0: its default).
	FilesWidth int `json:"files_width,omitempty"`
	// FilesSort is how the tree orders a folder: "folders" (the default:
	// folders first), "mixed" or "type" (by extension) (FIL-48).
	FilesSort string `json:"files_sort"`
	// FilesNest nests related files (tests, lock files) under the file
	// they belong to (FIL-48).
	FilesNest bool `json:"files_nest"`
	// FilesCompact is "on" (the default: single-child folder chains on one
	// row) or "off" (FIL-47).
	FilesCompact string `json:"files_compact"`
	// FilesFollow is "on" (the default: the tree shows the open tab's
	// file) or "off" (FIL-75).
	FilesFollow string `json:"files_follow"`
	// Width is how wide the conversation runs: "full" (the default, the
	// whole panel) or "readable" (a column of about 860 px).
	Width string `json:"width"`
	// DocWidth is how wide a document (Markdown in Preview and Visual)
	// runs: "full" (the default, the whole editor) or "readable" (a
	// column).
	DocWidth string `json:"doc_width"`
	// EditorZoom is the editor's and documents' zoom, in percent (50–200;
	// 100 by default).
	EditorZoom int `json:"editor_zoom"`
	// TaskContinue means a background task that ends while nothing runs starts
	// a turn about it.
	TaskContinue bool `json:"task_continue"`
	// Advanced shows the advanced settings throughout the window; off (the
	// default) it shows what a newcomer needs.
	Advanced bool `json:"advanced"`
	// Transparency is "on" (the default: glass surfaces, in Blitz's own
	// themes) or "off".
	Transparency string `json:"transparency"`
	// LightTheme and DarkTheme are the colour themes for light and for
	// dark: "blitz" (the default), or "one-light" and "one-dark-pro"
	// (the page's themes.ts).
	LightTheme string `json:"light_theme"`
	DarkTheme  string `json:"dark_theme"`
	// GPU is "on" (the default: on Linux the window draws with the
	// graphics card where it can) or "off" (in software); read as the app
	// starts (gpu.go).
	GPU string `json:"gpu"`
	// Updates is "auto" (the default: the app looks for a release when it
	// opens, every five days at most, and downloads it, ready to restart)
	// or "off".
	Updates string `json:"updates"`
	// MarkdownCSSLight and MarkdownCSSDark are the user's CSS for Markdown
	// previews in each theme, over the defaults (at most maxMarkdownCSS
	// bytes each).
	MarkdownCSSLight string `json:"markdown_css_light,omitempty"`
	MarkdownCSSDark  string `json:"markdown_css_dark,omitempty"`
	// TerminalFont is the terminal's font family ("" for the bundled
	// MesloLGS Nerd Font Mono), and TerminalFontSize its size in pixels
	// (8–32; 13 by default) (spec_062_terminal TRM-25).
	TerminalFont     string `json:"terminal_font,omitempty"`
	TerminalFontSize int    `json:"terminal_font_size"`
	// VoiceMic is the microphone voice uses, by the browser's device ID
	// ("" for the system's): one computer's, so the window's, not the
	// settings file's (spec_063_voice VOX-04).
	VoiceMic string `json:"voice_mic,omitempty"`
}

Prefs are the window's own settings, kept in ~/.blitz/desktop.json: how it looks, and the workspaces it knows with the names and colours the user gave them. Everything else belongs to the service.

func Defaults

func Defaults() Prefs

Defaults are the preferences before any are saved.

type PrefsStore

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

PrefsStore reads and writes the preferences file.

func NewPrefsStore

func NewPrefsStore(path string) *PrefsStore

NewPrefsStore keeps the preferences in the file at path (~/.blitz/desktop.json).

func (*PrefsStore) Load

func (s *PrefsStore) Load() (Prefs, error)

Load returns the saved preferences, or the defaults when there are none. An unreadable file is set aside (desktop.json.damaged) rather than lost.

func (*PrefsStore) Save

func (s *PrefsStore) Save(p Prefs) (Prefs, error)

Save writes the preferences atomically, owner-only, and returns them as saved (normalized).

type SandboxFix

type SandboxFix struct {
	Status   sandboxsetup.Status `json:"status"`
	Error    string              `json:"error,omitempty"`
	Commands string              `json:"commands,omitempty"`
}

SandboxFix is what FixSandbox did: the sandbox's state after it, and if it didn't work, why and the commands to run by hand.

func FixSandbox

func FixSandbox(ctx context.Context) SandboxFix

FixSandbox lets bubblewrap past AppArmor's restriction with a profile for bwrap alone, asking for the password with the system's dialog (pkexec), then checks again.

type Service

type Service interface {
	Start() error
	Stop() error
	Restart() error
	Running() bool
}

Service starts and stops the service for the host (the tray's Actions).

type ServiceStatus

type ServiceStatus struct {
	Running       bool   `json:"running"`
	Installed     bool   `json:"installed"`
	Socket        string `json:"socket"`
	Service       string `json:"service"`
	Tray          string `json:"tray"`
	TrayInstalled bool   `json:"tray_installed"`
}

ServiceStatus says whether the service answers and whether it starts at login, as the page reads it.

type UpdateStatus

type UpdateStatus struct {
	Current   string `json:"current"`
	Latest    string `json:"latest"`
	Available bool   `json:"available"`
	// Can is whether the app updates itself here; Reason says why not (a
	// package manager's copy, a development build).
	Can    bool   `json:"can"`
	Reason string `json:"reason,omitempty"`
	// ReasonKey is Reason's message key, for the page to say it in its
	// language; empty when there's none, and Reason is shown as it is.
	ReasonKey string `json:"reason_key,omitempty"`
	// Downloading, then Ready: downloaded, checked and unpacked.
	Downloading bool   `json:"downloading"`
	Ready       bool   `json:"ready"`
	Error       string `json:"error,omitempty"`
	// Notes is the release's page.
	Notes string `json:"notes,omitempty"`
}

UpdateStatus is the desktop app's update, as the page shows it (spec_038_electron EL-90).

type Updater

type Updater struct {
	Version  string // the app's (the host's)
	HostExe  string // the host's program, in the app (…/resources/app/bin)
	Dir      string // where downloads go (~/.blitz/updates)
	CacheDir string // Sigstore's trust root's cache (~/.blitz)
	Source   func() selfupdate.Source
	// Spawn starts a program that outlives the host.
	Spawn        func(name string, args ...string) error
	GOOS, GOARCH string

	// Now is the time (tests replace it).
	Now func() time.Time
	// contains filtered or unexported fields
}

Updater updates the desktop app the host runs in: it checks the releases (the owner's wish: when the app opens, and then only five days after the last check, unless asked), downloads and checks the new one, and puts it in place through a copy of the host run from outside the app (blitz-tray --apply-update), once the app has quit.

func (*Updater) Apply

func (u *Updater) Apply() error

Apply starts the swap (a copy of the host, from outside the app), which waits for the app (the host's parent) to quit; the page then quits it.

func (*Updater) Check

func (u *Updater) Check(ctx context.Context, force bool) UpdateStatus

Check says where the update is: from the last check while it's less than CheckEvery old, unless force (Check now), else from the latest release, asked for.

func (*Updater) Download

func (u *Updater) Download(ctx context.Context) UpdateStatus

Download downloads, checks and unpacks the latest release (Check first), unless it's downloading or ready already, and says where the update is when it's done: the page waits for it, rather than asking again and again.

func (*Updater) Downloads added in v0.9.12

func (u *Updater) Downloads() Downloads

Downloads is what Dir holds now.

func (*Updater) PruneDownloads added in v0.9.12

func (u *Updater) PruneDownloads(keep int) (Downloads, error)

PruneDownloads removes the downloaded releases but the keep newest, never the one staged to install (EL-90a; Settings › System › About's Clean up keeps none but that), and says what's left. While one downloads, it removes none.

type WorkspacePrefs

type WorkspacePrefs struct {
	Dir         string `json:"dir"`
	Name        string `json:"name,omitempty"` // "" shows the directory's name
	Description string `json:"description,omitempty"`
	Color       string `json:"color,omitempty"` // one of the palette's names
	Open        bool   `json:"open"`
	// WorkersSeen is when (Unix milliseconds) the workspace's Workers view
	// was last shown: failed runs since are badged.
	WorkersSeen int64 `json:"workers_seen,omitempty"`
}

WorkspacePrefs is a workspace as the window shows it.

Jump to

Keyboard shortcuts

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