Documentation
¶
Overview ¶
Package extensions runs what the user installed under lich's extensions directory: separate programs that speak the JSON lines of the extension contract over stdin and stdout. Each is started at boot, restarted when it crashes, and stopped with the backend. An extension is unsandboxed code, but what it writes is input the window draws, so every line is vetted here.
Index ¶
- func Check(path string) (extension.Manifest, error)
- func DataDir(configDir string) string
- func Dir(configDir string) string
- type Lich
- type Service
- func (s *Service) Boot()
- func (s *Service) Catalog(context.Context, api.None) (api.ExtensionCatalog, error)
- func (s *Service) CatalogImage(_ context.Context, opts api.ExtensionCatalogImageOptions) ([]byte, error)
- func (s *Service) CheckUpdates(ctx context.Context, _ api.None) ([]api.Extension, error)
- func (s *Service) CommitInstall(ctx context.Context, opts api.ExtensionInstallTokenOptions) (api.Extension, error)
- func (s *Service) DeleteData(_ context.Context, opts api.ExtensionIDOptions) (api.None, error)
- func (s *Service) DiscardInstall(_ context.Context, opts api.ExtensionInstallTokenOptions) (api.None, error)
- func (s *Service) ExtensionsDir(context.Context, api.None) (string, error)
- func (s *Service) List(_ context.Context, _ api.None) ([]api.Extension, error)
- func (s *Service) Observe(name string, data any)
- func (s *Service) PrepareFromDir(_ context.Context, opts api.ExtensionDirInstallOptions) (api.ExtensionInstallPreview, error)
- func (s *Service) PrepareFromGit(_ context.Context, opts api.ExtensionGitInstallOptions) (api.ExtensionInstallPreview, error)
- func (s *Service) PrepareUpdate(_ context.Context, opts api.ExtensionIDOptions) (api.ExtensionInstallPreview, error)
- func (s *Service) Remove(ctx context.Context, opts api.ExtensionIDOptions) (api.None, error)
- func (s *Service) Restart(ctx context.Context, opts api.ExtensionIDOptions) (api.None, error)
- func (s *Service) Send(_ context.Context, opts api.ExtensionSendOptions) (api.None, error)
- func (s *Service) SetLanguage(language func() string)
- func (s *Service) SetLich(lich Lich)
- func (s *Service) Shutdown()
- func (s *Service) WatchUpdates()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶ added in v0.91.0
Check runs an install's checks on an extension's folder or on a release archive named <id>_<goos>_<goarch>.tar.gz, on a copy it then deletes, and returns the manifest that passed. It needs no lich running and no network. minLichVersion is checked for its form only: the lich that checks is not the one that installs.
Types ¶
type Lich ¶
type Lich struct {
Projects func(context.Context, api.None) ([]api.Project, error)
Peers func(context.Context, api.PeersOptions) ([]api.Peer, error)
Worktrees func(context.Context, api.WorktreesOptions) ([]api.WorktreeCheckout, error)
Open func(context.Context, api.OpenSessionOptions) (api.OpenedSession, error)
Send func(context.Context, api.SendOptions) (api.SendResult, error)
Wait func(context.Context, api.WaitOptions) (api.SendResult, error)
Ask func(context.Context, api.AskSessionOptions) (api.SessionAnswer, error)
Project func(context.Context, api.ProjectRefOptions) (api.ProjectRef, error)
Services func(context.Context, api.None) ([]api.Service, error)
StartService func(context.Context, api.ServiceIDOptions) (api.None, error)
StopService func(context.Context, api.ServiceIDOptions) (api.None, error)
RestartService func(context.Context, api.ServiceIDOptions) (api.None, error)
Output func(context.Context, api.ServiceIDOptions) ([]byte, error)
LiveOutput func(context.Context, api.ServiceIDOptions) ([]byte, error)
Diff func(context.Context, api.PathOptions) (api.DiffStats, error)
BaseStatus func(context.Context, api.PathOptions) (*api.BaseStatus, error)
Upstream func(context.Context, api.PathOptions) (api.BaseFreshness, error)
PullRequest func(context.Context, api.PathOptions) (*api.PullRequest, error)
Notify func(context.Context, api.NotifyOptions) (api.None, error)
ShowCode func(context.Context, api.ShowCodeOptions) (api.ShowCode, error)
OpenURL func(context.Context, api.BrowserOpenOptions) (api.BrowserHandle, error)
// Attached is whether a window is connected to show what ShowCode and
// OpenURL do.
Attached func() bool
// PromptLang is the language an extension's name is worded in for the
// agents it sends to.
PromptLang func() prompt.Lang
}
Lich is what an extension's calls reach: the services lich's MCP tools call, each called as the lich command line outside a session calls it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is every installed extension and its process.
func New ¶
New returns the extensions under dir, none discovered or running until Boot. env is what their processes get, and each one's data directory is under dataDir.
func (*Service) Boot ¶
func (s *Service) Boot()
Boot deletes what earlier runs left staged, then discovers the extensions and starts every valid one.
func (*Service) Catalog ¶ added in v0.91.0
Catalog is the catalog in memory, read now when there is none; the read's error is the answer only when that leaves none.
func (*Service) CatalogImage ¶ added in v0.91.0
func (s *Service) CatalogImage(_ context.Context, opts api.ExtensionCatalogImageOptions) ([]byte, error)
CatalogImage reads an image the catalog in memory names, held to the listing's limit for it: the window draws what the catalog shows through here, and no other address is fetched on its behalf.
func (*Service) CheckUpdates ¶ added in v0.91.0
CheckUpdates looks for a newer release of every extension installed from GitHub, tells the window of each one whose answer changed, and returns the list as it then stands.
func (*Service) CommitInstall ¶
func (s *Service) CommitInstall(ctx context.Context, opts api.ExtensionInstallTokenOptions) (api.Extension, error)
CommitInstall moves the staged copy into the extensions directory and starts it, in place of the installed version when it is an update.
func (*Service) DeleteData ¶
DeleteData deletes the data directory of an extension that is not installed. installMu keeps an install of the same id from starting while it goes.
func (*Service) DiscardInstall ¶
func (s *Service) DiscardInstall(_ context.Context, opts api.ExtensionInstallTokenOptions) (api.None, error)
DiscardInstall deletes the staged copy.
func (*Service) ExtensionsDir ¶
ExtensionsDir is the directory extensions are read from and installed into.
func (*Service) Observe ¶
Observe hands every app event to the extensions subscribed to it. It runs on the emitter's goroutine, so it only queues.
func (*Service) PrepareFromDir ¶
func (s *Service) PrepareFromDir(_ context.Context, opts api.ExtensionDirInstallOptions) (api.ExtensionInstallPreview, error)
PrepareFromDir copies a folder holding manifest.json and the executable at its root into a stage for CommitInstall. The folder is left as it was.
func (*Service) PrepareFromGit ¶
func (s *Service) PrepareFromGit(_ context.Context, opts api.ExtensionGitInstallOptions) (api.ExtensionInstallPreview, error)
PrepareFromGit downloads a GitHub repository's extension for this platform, verifies and unpacks it, and stages it for CommitInstall: the release the catalog lists for a listed repository, the latest for another.
func (*Service) PrepareUpdate ¶ added in v0.91.0
func (s *Service) PrepareUpdate(_ context.Context, opts api.ExtensionIDOptions) (api.ExtensionInstallPreview, error)
PrepareUpdate stages the latest release of the repository an extension was installed from, for CommitInstall to put in its place. The installed version keeps running until then.
func (*Service) Remove ¶
Remove stops an extension and deletes its directory. A directory that is a symlink, an extension developed in place, loses the link and keeps its target. Its data directory stays, for DeleteData or the next install of the same id.
func (*Service) Restart ¶
Restart starts an extension again, which is the only way back from failed, and starts its count of quick crashes over. One that is running or waiting to restart is stopped first, as lich stops it on exit. The directory is read again, so an edited manifest is what runs and one that no longer validates shows invalid with its reason instead of starting. The id is the directory name, so a manifest whose id changed on disk is invalid like any other.
func (*Service) SetLanguage ¶
SetLanguage names where the interface language an extension starts with comes from, before Boot. Without one it starts with English.
func (*Service) Shutdown ¶
func (s *Service) Shutdown()
Shutdown stops every extension: stdin closes, each gets its grace, and what is still up is killed. Bounded, so nothing here can hold up lich's exit.
func (*Service) WatchUpdates ¶ added in v0.91.0
func (s *Service) WatchUpdates()
WatchUpdates reads the catalog and looks for newer releases now and every updateCheckEvery, until Shutdown.