kernel

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 20 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.

Variables

This section is empty.

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

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

RunCommand runs a command by id.

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 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
	// 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
}

Options are what an app gives the kernel.

Jump to

Keyboard shortcuts

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