Documentation
¶
Overview ¶
Package kernel is what the core's own services (the agent, slots, the router) are given: the app's shared state, already assembled. It is an interface so those services can be built and tested without the whole app.
Index ¶
- Constants
- Variables
- type App
- func (a *App) AddTools(tools ...BoundTool) error
- func (a *App) AppName() string
- func (a *App) Arounds() []BoundAround
- func (a *App) Bus() *events.Bus
- func (a *App) Cards() module.Cards
- func (a *App) Catalog() Catalog
- func (a *App) CommandInfos() []CommandInfo
- func (a *App) Commands() []module.Command
- func (a *App) Config(scope string) module.Config
- func (a *App) DB() *sql.DB
- func (a *App) DataDir() string
- func (a *App) DeclareSettings(scope string, s []module.Setting) error
- func (a *App) Desk() module.Desk
- func (a *App) Events() module.Events
- func (a *App) Log() *slog.Logger
- func (a *App) Marks() module.Marks
- func (a *App) ModuleRoutes() http.Handler
- func (a *App) Modules() []ModuleInfo
- func (a *App) PaletteProviders() []PaletteInfo
- func (a *App) Profiles() []BoundProfile
- func (a *App) PublicHostAllowed(hostport string) bool
- func (a *App) PublicRoute(r *http.Request) bool
- func (a *App) Ready(ctx context.Context) module.Readiness
- func (a *App) RecordRef(ctx context.Context, kind, id string) (module.RefEntity, error)
- func (a *App) RefKinds(ctx context.Context) []RefKindInfo
- func (a *App) ResolveRefs(ctx context.Context, kind string, ids []string) (map[string]*module.RefEntity, error)
- func (a *App) RunCommand(ctx context.Context, id string, args map[string]any) (any, error)
- func (a *App) SearchPalette(ctx context.Context, id string, q module.PaletteQuery) ([]module.PaletteResult, error)
- func (a *App) SetAsker(x Asker)
- func (a *App) SetGateway(f func(context.Context) (module.Gateway, error))
- func (a *App) Settings() *config.Store
- func (a *App) Situation(ctx context.Context) module.Situation
- func (a *App) Slots() []BoundSlot
- func (a *App) Start(ctx context.Context) error
- func (a *App) Stop(ctx context.Context) error
- func (a *App) Title() string
- func (a *App) Tools() []BoundTool
- func (a *App) WM() *desk.Desk
- type Asker
- type BoundAround
- type BoundProfile
- type BoundSlot
- type BoundTool
- type Catalog
- type CatalogItem
- type CatalogModule
- type CommandInfo
- type Kernel
- type ModuleInfo
- type Options
- type PaletteInfo
- type RefKindInfo
Constants ¶
const CoreScope = "surface"
CoreScope is the settings scope of the core's own settings.
const (
// MaxCiteBatch is the most ids one resolve takes.
MaxCiteBatch = 50
)
Variables ¶
var ErrPaletteProvider = errors.New("unknown palette provider")
var ErrUnknownRefKind = errors.New("no module resolves that kind of reference here")
ErrUnknownRefKind means no module resolves the kind (or it cannot now).
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the assembled app: the Kernel the core's services are given.
func New ¶
New assembles the app: opens the stores, reads every module's manifest and builds its Host. Start then starts the modules.
func (*App) AddTools ¶
AddTools adds a core service's own tools (the agent's: slots, reflexes, rules), so they are offered at /api/tools and /mcp like every other. Call before serving. A name already taken is an error.
func (*App) Arounds ¶ added in v0.4.0
func (a *App) Arounds() []BoundAround
Arounds is every module's Around, bound to its Host.
func (*App) CommandInfos ¶
func (a *App) CommandInfos() []CommandInfo
CommandInfos lists every command with the module that brought it.
func (*App) DeclareSettings ¶
DeclareSettings adds a core service's settings (the agent's, say). Call before serving.
func (*App) ModuleRoutes ¶
ModuleRoutes serves the modules' own routes (/api/m/<id>/...).
func (*App) Modules ¶
func (a *App) Modules() []ModuleInfo
Modules lists the started modules' manifests.
func (*App) PaletteProviders ¶ added in v0.10.0
func (a *App) PaletteProviders() []PaletteInfo
func (*App) Profiles ¶ added in v0.4.0
func (a *App) Profiles() []BoundProfile
Profiles is every module's agent profile.
func (*App) PublicHostAllowed ¶ added in v0.18.0
PublicHostAllowed reports whether a module added the request's host name (hostport, as in r.Host) through module.PublicHosts. The caller checks the route is public (PublicRoute).
func (*App) PublicRoute ¶ added in v0.17.0
PublicRoute reports whether r is for a module route marked module.Public: one an app with sign-in serves without a signed-in caller.
func (*App) Ready ¶ added in v0.20.0
Ready is the app's readiness: the worst of its modules' (module.Readier), each asked with a deadline; a module not started yet is down. Reasons are "<module>: <reason>".
func (*App) RecordRef ¶ added in v0.4.0
RecordRef reads one reference whole, for the record window. Never cached: the owner opened it to read it as it is now.
func (*App) RefKinds ¶ added in v0.4.0
func (a *App) RefKinds(ctx context.Context) []RefKindInfo
RefKinds lists the kinds the app can resolve now, by kind.
func (*App) ResolveRefs ¶ added in v0.4.0
func (a *App) ResolveRefs(ctx context.Context, kind string, ids []string) (map[string]*module.RefEntity, error)
ResolveRefs looks up ids of one kind: what each stands for, nil for one not found. Answers are cached briefly (found 45 s, not found 15 s); the rest go to the module in one batch. An error is returned only when the module failed and nothing could be answered.
func (*App) RunCommand ¶
RunCommand runs a command by id.
func (*App) SearchPalette ¶ added in v0.10.0
func (a *App) SearchPalette(ctx context.Context, id string, q module.PaletteQuery) ([]module.PaletteResult, error)
SearchPalette isolates each provider: the page queries them independently, so a slow source never holds up commands or other providers. Six searches may execute at once.
func (*App) SetAsker ¶ added in v0.4.0
SetAsker names what takes the modules' errands for the agent. Until it is set (the agent service starts after the modules), and when it is nil, an errand gets module.ErrNoAgent.
func (*App) SetGateway ¶ added in v0.4.0
SetGateway names where the modules' Host.Agent().Gateway reads the app's model gateway.
func (*App) Start ¶
Start starts the modules in order. Routes a module adds in Start are served afterwards.
type Asker ¶ added in v0.4.0
Asker is what takes the modules' errands for the agent (the agent service, once it runs).
type BoundAround ¶ added in v0.4.0
BoundAround is a module's Around bound to its Host.
type BoundProfile ¶ added in v0.4.0
BoundProfile is a module's agent profile: the module and its title, and the profile's files (a Nanite agent directory without host.yaml or .mcp.json).
type BoundSlot ¶
type BoundSlot struct {
module.Slot
Module string
Knowledge func(ctx context.Context, s module.Situation) (string, error)
}
BoundSlot is a slot with the module that brought it and its Knowledge bound to that module's Host. Knowledge is nil when the slot has none.
type BoundTool ¶
type BoundTool struct {
module.Tool
Module string
Call func(ctx context.Context, input json.RawMessage) (any, error)
}
BoundTool is a tool with the module that brought it and a call already bound to that module's Host.
type Catalog ¶
type Catalog struct {
App string `json:"app"`
Title string `json:"title"`
Modules []CatalogModule `json:"modules"`
}
Catalog is what the app is made of, as data: its modules with their views, commands, tools and slots. It is what a module that composes setups (the Interaction Builder) and the agent read to know what there is to arrange.
type CatalogItem ¶
type CatalogItem struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
About string `json:"about,omitempty"`
Level string `json:"level,omitempty"`
}
CatalogItem is a view, a command or a tool, by id and what it is for.
type CatalogModule ¶
type CatalogModule struct {
ID string `json:"id"`
Title string `json:"title"`
About string `json:"about,omitempty"`
Views []CatalogItem `json:"views,omitempty"`
Commands []CatalogItem `json:"commands,omitempty"`
Tools []CatalogItem `json:"tools,omitempty"`
Slots []module.Slot `json:"slots,omitempty"`
Settings []module.Setting `json:"settings,omitempty"`
}
CatalogModule is one module of the catalog. The core's own entries are under "surface".
type CommandInfo ¶
CommandInfo is a command as the page and the agent are told it.
type Kernel ¶
type Kernel interface {
AppName() string
// DataDir is the app's data directory. It exists.
DataDir() string
// DB is the core database. A service adds its own tables with storage.Migrate under
// its own migration set.
DB() *sql.DB
Log() *slog.Logger
Desk() module.Desk
Events() module.Events
Marks() module.Marks
Cards() module.Cards
// Config is the live settings of one scope ("agent", or a module id).
Config(scope string) module.Config
// Tools is every tool in the app, bound to the Host of the module that brought it:
// each module's own, and the desk's (desk_*, window_context, marks_*, card_*).
Tools() []BoundTool
// Slots is every module's context slots, bound likewise.
Slots() []BoundSlot
// Arounds is every module's Around, bound likewise, in module order.
Arounds() []BoundAround
// Profiles is every module's agent profile (Manifest.Profile), in module order.
Profiles() []BoundProfile
// Situation is what is happening now: the window in front, the open windows, the
// user's mode and the layout in use.
Situation(ctx context.Context) module.Situation
RunCommand(ctx context.Context, id string, args map[string]any) (any, error)
Commands() []module.Command
}
Kernel is the assembled app, as a core service sees it.
type ModuleInfo ¶
ModuleInfo is one started module, for the app's manifest.
type Options ¶
type Options struct {
// Name is the app's name ("desk"); Title is how a person reads it.
Name string
Title string
// DataDir is the app's data directory. It is created, private.
DataDir string
// DB is the core database. When nil the kernel opens <DataDir>/surface.db itself.
DB *sql.DB
Log *slog.Logger
// Modules are the ids to start, in order. Nil starts every registered module.
Modules []string
// Keys mints identity API keys for modules (module.KeysOf); nil without sign-in.
Keys module.Keys
}
Options are what an app gives the kernel.