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
- Variables
- func License(which string) (string, error)
- func ProgramExists(path string) bool
- func SafeURL(raw string) bool
- func SandboxStatus(ctx context.Context) sandboxsetup.Status
- type CLIInstall
- type CLIStatus
- type Host
- type Prefs
- type PrefsStore
- type SandboxFix
- type Service
- type ServiceStatus
- type UpdateStatus
- type Updater
- type WorkspacePrefs
Constants ¶
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.
Variables ¶
var ErrNotReady = errors.New("no update has been downloaded")
ErrNotReady is applying an update that hasn't been downloaded.
Functions ¶
func License ¶
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 ¶
ProgramExists reports whether path is a file: the program a running service started from may have been removed since (DSK-51a).
func SafeURL ¶
SafeURL reports whether a link from model output may be opened in the system browser: web and mail links only, never file: or custom schemes.
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 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
// 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
}
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.
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"`
// 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"`
}
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.
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.
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 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"`
// 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_electron_038 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 ¶
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) Status ¶
func (u *Updater) Status() UpdateStatus
Status is where the update is, without asking for the latest release (as Check last found it): for following a download.
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.