kernel

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const CoreScope = "surface"

CoreScope is the settings scope of the core's own settings.

View Source
const (
	// MaxCiteBatch is the most ids one resolve takes.
	MaxCiteBatch = 50
)

Variables

View Source
var ErrPaletteProvider = errors.New("unknown palette provider")
View Source
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

func New(ctx context.Context, o Options) (*App, error)

New assembles the app: opens the stores, reads every module's manifest and builds its Host. Start then starts the modules.

func (*App) AddTools

func (a *App) AddTools(tools ...BoundTool) error

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) AppName

func (a *App) AppName() string

AppName is the app's name.

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) Bus

func (a *App) Bus() *events.Bus

Bus is the bus as the core's API uses it.

func (*App) Cards

func (a *App) Cards() module.Cards

Cards are what the app shows the user outside a window.

func (*App) Catalog

func (a *App) Catalog() Catalog

Catalog returns the app's catalog.

func (*App) CommandInfos

func (a *App) CommandInfos() []CommandInfo

CommandInfos lists every command with the module that brought it.

func (*App) Commands

func (a *App) Commands() []module.Command

Commands lists every command in declaration order.

func (*App) Config

func (a *App) Config(scope string) module.Config

Config is one scope's live settings.

func (*App) DB

func (a *App) DB() *sql.DB

DB is the core database.

func (*App) DataDir

func (a *App) DataDir() string

DataDir is the app's data directory.

func (*App) DeclareSettings

func (a *App) DeclareSettings(scope string, s []module.Setting) error

DeclareSettings adds a core service's settings (the agent's, say). Call before serving.

func (*App) Desk

func (a *App) Desk() module.Desk

Desk is the windows and layouts.

func (*App) Events

func (a *App) Events() module.Events

Events is the bus.

func (*App) Log

func (a *App) Log() *slog.Logger

Log is the app's logger.

func (*App) Marks

func (a *App) Marks() module.Marks

Marks are the collaboration marks.

func (*App) ModuleRoutes

func (a *App) ModuleRoutes() http.Handler

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

func (a *App) PublicHostAllowed(hostport string) bool

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

func (a *App) PublicRoute(r *http.Request) bool

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

func (a *App) Ready(ctx context.Context) module.Readiness

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

func (a *App) RecordRef(ctx context.Context, kind, id string) (module.RefEntity, error)

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

func (a *App) RunCommand(ctx context.Context, id string, args map[string]any) (any, error)

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

func (a *App) SetAsker(x Asker)

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

func (a *App) SetGateway(f func(context.Context) (module.Gateway, error))

SetGateway names where the modules' Host.Agent().Gateway reads the app's model gateway.

func (*App) Settings

func (a *App) Settings() *config.Store

Settings is the whole settings store.

func (*App) Situation

func (a *App) Situation(ctx context.Context) module.Situation

Situation is what is happening now.

func (*App) Slots

func (a *App) Slots() []BoundSlot

Slots is every module's slots.

func (*App) Start

func (a *App) Start(ctx context.Context) error

Start starts the modules in order. Routes a module adds in Start are served afterwards.

func (*App) Stop

func (a *App) Stop(ctx context.Context) error

Stop stops the started modules in reverse order and closes the stores.

func (*App) Title

func (a *App) Title() string

Title is the app's name as a person reads it.

func (*App) Tools

func (a *App) Tools() []BoundTool

Tools is every tool in the app.

func (*App) WM

func (a *App) WM() *desk.Desk

WM is the desk with the whole of its state, for the core's own API.

type Asker added in v0.4.0

type Asker interface {
	AskFrom(ctx context.Context, module string, a module.Ask) (string, error)
}

Asker is what takes the modules' errands for the agent (the agent service, once it runs).

type BoundAround added in v0.4.0

type BoundAround struct {
	Module string
	Read   func(ctx context.Context) (string, error)
}

BoundAround is a module's Around bound to its Host.

type BoundProfile added in v0.4.0

type BoundProfile struct {
	Module string
	Title  string
	Files  fs.FS
}

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

type CommandInfo struct {
	module.Command
	Module string `json:"module"`
}

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

type ModuleInfo struct {
	module.Manifest
}

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.

type PaletteInfo added in v0.10.0

type PaletteInfo struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Mode  string `json:"mode"`
}

type RefKindInfo added in v0.4.0

type RefKindInfo struct {
	Kind   string `json:"kind"`
	Label  string `json:"label"`
	Module string `json:"module"`
	// Record: the kind has more to show than its preview.
	Record bool `json:"record,omitempty"`
}

RefKindInfo is a kind as the page is told it.

Jump to

Keyboard shortcuts

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