Help us shape the future of Go! Take the 2026 Go Developer Survey

applets

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package applets holds the on-disk catalog of applets: web pages an agent or a user writes, which Hive opens with full access to the machine through window.hive (ADR applets-are-web-pages-with-full-access-to-the-machine).

This package parses and validates. It never executes a command.

Index

Constants

View Source
const (
	// FileName is the file that makes a directory under the applets root an applet.
	FileName = "applet.yaml"
	// DefaultEntry is the page an applet opens on.
	DefaultEntry = "index.html"
	// DefaultTitlebarWidth matches the bar's square icon buttons.
	DefaultTitlebarWidth = 28
)
View Source
const (
	// ArchiveFormat is the version of the file Pack writes. Unpack refuses any other, so
	// a later format can be told apart rather than misread.
	ArchiveFormat = 1
	// ArchiveExtension names a shared applet: a zip holding ArchiveManifestName and the
	// applet's files under files/.
	ArchiveExtension = ".hiveapplet"
	// ArchiveManifestName is the one entry outside files/.
	ArchiveManifestName = "hive-applet.json"

	MaxArchiveBytes = 32 << 20
	MaxArchiveFiles = 500
	// MaxUnpackedBytes bounds what an archive may expand to, which its own headers
	// cannot be trusted to report.
	MaxUnpackedBytes = 64 << 20
)
View Source
const (
	SurfaceTab      = "tab"
	SurfacePopup    = "popup"
	SurfaceTitlebar = "titlebar"
)

Names of the keys under surfaces: in applet.yaml.

View Source
const BuilderID = "applet-builder"
View Source
const (
	// FormatVersion is the applet.yaml format this Hive reads. It rises only for a change an
	// older Hive would misread, which is what keeps files working across releases.
	FormatVersion = 1
)

Variables

View Source
var ErrAppletExists = errors.New("an applet with that id already exists")

ErrAppletExists reports that an id is taken. Nothing replaces an applet on import.

Functions

func BridgeScript

func BridgeScript() string

func FreeID

func FreeID(root, id string) (string, error)

FreeID returns id if nothing holds it, and otherwise the first free id-2, id-3 and so on.

func IsWatchedFile

func IsWatchedFile(path string) bool

IsWatchedFile matches what can change the catalog or a page on screen. A shell script is read when it runs and needs no reload, and a data file an applet writes for itself must not restart it.

func ReadBuiltin

func ReadBuiltin(id, name string) ([]byte, error)

ReadBuiltin returns one file of a built-in applet.

func SetSurface

func SetSurface(raw []byte, surface string, on bool) ([]byte, error)

SetSurface returns raw with one surface turned on or off, keeping the file's comments. Off is enabled: false rather than a removed key, so a pop-up keeps its size and a title bar keeps its page for when the surface comes back.

func SkipsWatch

func SkipsWatch(dir string) bool

SkipsWatch names a folder that holds no part of a page an edit would change, and can be large enough to run out of file watches.

Types

type Applet

type Applet struct {
	ID string `yaml:"-"`
	// Dir is the applet's directory, exported to its commands as HIVE_APPLET_DIR. A
	// built-in has its page in the binary, and keeps only its saved storage here.
	Dir string `yaml:"-"`
	// Builtin marks an applet Hive ships. A directory of the same name replaces it.
	Builtin bool `yaml:"-"`
	// Warnings names what this Hive skipped in the file, such as a key from a later
	// release. The applet still runs.
	Warnings []string `yaml:"-"`
	// Version is the format of this file, not a release of the applet.
	Version int `yaml:"version"`
	// Hive is the oldest Hive that can run this applet, as ">=0.60".
	Hive  string `yaml:"hive,omitempty"`
	Title string `yaml:"title"`
	Icon  string `yaml:"icon,omitempty"`
	// Cwd pins the applet's commands to one directory. Empty follows the session on
	// screen, and the applet's own directory without one.
	Cwd string `yaml:"cwd,omitempty"`
	// Entry is the page the applet opens on, relative to its directory.
	Entry string `yaml:"entry,omitempty"`
	// Surfaces says where the applet shows. A file that names none is a pop-up.
	Surfaces Surfaces `yaml:"surfaces,omitempty"`
	// Commands are the applet's palette rows that a user can bind to a key, as
	// applet.<id>.<command>. They carry no default chord, so a file cannot claim a key.
	Commands []Command `yaml:"commands,omitempty"`
}

Applet is one applet.yaml. ID is the name of its directory, so an applet can be copied or renamed by moving the directory.

func Parse

func Parse(id string, raw []byte, hostVersion string) (Applet, error)

Parse decodes one applet.yaml for the Hive at hostVersion. It reads forward: a later release's key or icon is a warning, so an applet written there still opens here. A wrong shape under a key this Hive knows stays an error, and so does a file that says this Hive is too old (ADR applets-are-web-pages-with-full-access-to-the-machine).

func (Applet) Validate

func (a Applet) Validate() error

Validate reports the first problem with the file.

type Archive

type Archive struct {
	Applet Applet
	Files  []ArchiveFile
}

Archive is an applet read out of a shared file, checked and still only in memory.

func Unpack

func Unpack(raw []byte, hiveVersion string) (Archive, error)

Unpack reads a shared file, which it treats as hostile. It writes nothing, and every problem refuses the whole file. A zip has no hard links, so the entry type check covers symlinks and every other special file. A warning from Parse carries only names it has already reduced to plain text.

func (Archive) Install

func (a Archive) Install(root, id string, beforeRename func() error) (err error)

Install writes the archive as a new applet under root. The directory appears whole or not at all: it is written beside root, where the catalog does not look, and renamed in. Files get plain permissions, so the archive cannot mark anything executable. A failure from beforeRename, which may be nil, leaves nothing behind.

type ArchiveFile

type ArchiveFile struct {
	Path string
	Data []byte
}

ArchiveFile is one file of an applet, by its slash-separated path in the directory.

type Command

type Command struct {
	// ID is permanent once a user has bound it: it is what settings.yaml names.
	ID       string   `yaml:"id"`
	Title    string   `yaml:"title"`
	Icon     string   `yaml:"icon,omitempty"`
	Keywords []string `yaml:"keywords,omitempty"`
}

Command is one thing an applet offers the palette. Running it reaches the page through hive.on('command').

type Entry

type Entry struct {
	Applet Applet
	Err    error
	// Revision is the newest change among the applet's watched files, in Unix
	// milliseconds. It is what tells a page on screen to load again after an edit,
	// without a change to another applet restarting this one.
	Revision int64
}

Entry is one directory under the root. A broken file keeps the Applet that last loaded from it, with the problem in Err, so an edit in progress neither removes the applet from the palette nor hides why the edit did not take.

func (Entry) Usable

func (e Entry) Usable() bool

Usable reports that a file has loaded, so there is a page to open.

type PackList

type PackList struct {
	Files   []PackedFile
	LeftOut []string
}

PackList is what an export of a directory contains and what it leaves out.

func ListPack

func ListPack(dir string) (PackList, error)

ListPack walks an applet's directory for what Pack would write. It follows no symlink, since one could carry a file from anywhere on the machine into the export.

type PackedApplet

type PackedApplet struct {
	Data []byte
	List PackList
}

PackedApplet is an export, whole in memory, with what it holds.

func Pack

func Pack(applet Applet, hiveVersion string) (PackedApplet, error)

Pack reads one applet's directory into an archive. It records no timestamp, owner or path from this machine: the entries are the relative paths and their contents. It runs the checks an import would, so what cannot be imported fails here, for the person who can fix it. The result is held in memory, so what the user reviews is what gets written.

type PackedFile

type PackedFile struct {
	Path  string
	Bytes int64
}

PackedFile is one file an export includes.

type PopupSurface

type PopupSurface struct {
	Enabled *bool `yaml:"enabled,omitempty"`
	Width   int   `yaml:"width,omitempty"`
	Height  int   `yaml:"height,omitempty"`
}

PopupSurface sizes the pop-up in pixels. Zero fills the window.

type Store

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

Store is the catalog. It reads the disk only in Reload, so opening the palette costs no I/O.

func NewStore

func NewStore(root, hostVersion string) *Store

func (*Store) Get

func (s *Store) Get(id string) (Applet, bool)

Get returns the applet with that id, if a file for it has loaded.

func (*Store) List

func (s *Store) List() []Entry

List returns every entry ordered by title.

func (*Store) Reload

func (s *Store) Reload() error

Reload rereads every applet. A directory with no applet.yaml is not an applet yet, which is the normal state of one an agent is halfway through writing. A built-in fills in wherever the disk has no applet of its name.

func (*Store) Root

func (s *Store) Root() string

type Surfaces

type Surfaces struct {
	// Tab puts the applet in a session's + menu.
	Tab *TabSurface `yaml:"tab,omitempty"`
	// Popup opens the applet over the app, from the palette or a chord.
	Popup *PopupSurface `yaml:"popup,omitempty"`
	// Titlebar runs a page in the title bar from the moment the file loads.
	Titlebar *TitlebarSurface `yaml:"titlebar,omitempty"`
}

Surfaces is the registration: an applet shows where its file says, and nowhere else. A surface takes a map so a later release can add to it without moving a key.

func (Surfaces) ShowsPopup

func (s Surfaces) ShowsPopup() bool

func (Surfaces) ShowsTab

func (s Surfaces) ShowsTab() bool

ShowsTab, ShowsPopup and ShowsTitlebar say whether the surface is listed and not turned off.

func (Surfaces) ShowsTitlebar

func (s Surfaces) ShowsTitlebar() bool

func (*Surfaces) UnmarshalYAML

func (s *Surfaces) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML reads a bare "tab:" as asking for the surface. The decoder leaves a pointer nil for a null value, which would drop the surface with no warning.

type TabSurface

type TabSurface struct {
	// Enabled false turns the surface off and keeps its settings. Unset is on.
	Enabled *bool `yaml:"enabled,omitempty"`
}

TabSurface takes its size from its panel.

type TitlebarSurface

type TitlebarSurface struct {
	Enabled *bool `yaml:"enabled,omitempty"`
	// Entry is relative to the applet's directory. Empty uses the applet's Entry, and
	// the page tells the two apart with hive.surface.
	Entry string `yaml:"entry,omitempty"`
	// Width is the slot's width in pixels until the page asks for another. Zero is
	// DefaultTitlebarWidth, one icon button.
	Width int `yaml:"width,omitempty"`
}

TitlebarSurface is the page an applet shows in the title bar.

type UpdateHiveError

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

UpdateHiveError reports a file this Hive is too old for. It stands on its own, so an import shows it as is rather than calling the file invalid.

func (*UpdateHiveError) Error

func (e *UpdateHiveError) Error() string

Jump to

Keyboard shortcuts

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