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 DataDir(configDir string) string
- func Dir(configDir string) string
- type Lich
- type Service
- func (s *Service) Boot()
- func (s *Service) CommitInstall(_ 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) 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()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
}
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) CommitInstall ¶
func (s *Service) CommitInstall(_ context.Context, opts api.ExtensionInstallTokenOptions) (api.Extension, error)
CommitInstall moves the staged copy into the extensions directory and starts it.
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 the latest release of a GitHub repository's extension for this platform, verifies and unpacks it, and stages it for CommitInstall.
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.
func (*Service) SetLanguage ¶
SetLanguage names where the interface language an extension starts with comes from, before Boot. Without one it starts with English.