Help us shape the future of Go! Take the 2026 Go Developer Survey

live

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package live is the runtime that ties the Kiln components together during a session: it owns the current Session (world + chat + plans), the Journal that persists every edit, the framework.App that serves the live preview, and the SSE broadcaster that notifies the panel.

Apply is the single funnel through which the world ever changes. Anything that wants to mutate state — the agent's tool surface, the chat panel's undo button, an external MCP client — converges on this one path so journal, app, and SSE stay consistent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppFactory

type AppFactory func() *framework.App

AppFactory builds a fresh framework.App. Kiln calls it on every rebuild so callers can wire any options they want (DB, custom plugins, …).

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Broadcaster fan-outs Events to subscribed channels. Slow consumers drop events rather than blocking the broadcaster.

func NewBroadcaster

func NewBroadcaster() *Broadcaster

NewBroadcaster returns an empty Broadcaster.

func (*Broadcaster) Send

func (b *Broadcaster) Send(e Event)

Send delivers e to every subscribed channel. Non-blocking: a subscriber whose buffer is full will miss this event.

func (*Broadcaster) Subscribe

func (b *Broadcaster) Subscribe() (<-chan Event, func())

Subscribe registers a channel and returns it along with an unsubscribe function. The channel is closed by unsubscribe; callers must call it.

type Event

type Event struct {
	EntryID string `json:"entry_id"`
	Kind    string `json:"kind"`
	Op      string `json:"op,omitempty"`
	// Summary is a glanceable, human-readable digest of the entry's
	// payload (e.g. "name=posts fields=3" for add_entity). Empty for
	// kinds that don't have a useful one-liner. Computed in Apply.
	Summary string `json:"summary,omitempty"`
}

Event is one notification published when a journal entry is applied. Subscribers learn that something changed; they can pull current state (e.g. the Deferred report or specific entity data) via separate calls.

type Live

type Live struct {
	// contains filtered or unexported fields
}

Live is the runtime coordinator: Session ↔ Journal ↔ App ↔ SSE.

func New

func New(j journal.Journal, factory AppFactory) (*Live, error)

New constructs a Live runtime from an existing journal (which may already contain entries from a previous session). It replays the journal, builds the initial app, and is ready to Apply further entries.

func (*Live) App

func (l *Live) App() *framework.App

App returns the current rebuilt framework.App. Callers can use this to reach app.MCP (per-entity MCP tools auto-registered when an entity has mcp:true) or app.Router() for advanced wiring. Note: the pointer changes on every Apply rebuild — don't cache it.

func (*Live) Apply

func (l *Live) Apply(e journal.Entry) error

Apply is the single funnel. It applies the entry to the in-memory session, validates it by rebuilding the app, and ONLY THEN persists it to the journal — so a poison entry that fails the rebuild never reaches the durable log (which would re-fail on every restart). On any failure the pre-entry state is restored by replaying the (still-unchanged) journal.

func (*Live) Aux

func (l *Live) Aux() *router.Router

Aux returns the auxiliary router, mounted on the same listener as the rebuilt app but stable across rebuilds. Use it to register surfaces that must survive world mutations (e.g. the chat panel).

func (*Live) Deferred

func (l *Live) Deferred() kilnrender.Deferred

Deferred returns the most recent Deferred report from rebuild.

func (*Live) Journal

func (l *Live) Journal() journal.Journal

Journal returns the underlying journal.

func (*Live) Notify

func (l *Live) Notify(kind, summary string)

Notify broadcasts a synthetic SSE Event without journaling. Use for runtime lifecycle signals the panel needs to react to but that are not part of world state — agent_turn_started, agent_turn_ended, session_reset, etc. Safe to call concurrently.

func (*Live) Reload

func (l *Live) Reload() error

Reload discards the in-memory session and rebuilds it from the journal. Useful after out-of-band journal writes or recovery from inconsistency.

func (*Live) ServeHTTP

func (l *Live) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP first tries the auxiliary router (kiln-internal paths), falling through to the current app's router on 404.

func (*Live) ServeSSE

func (l *Live) ServeSSE(w http.ResponseWriter, r *http.Request)

ServeSSE is a stand-alone HTTP handler that streams events as Server-Sent Events. Mount at e.g. "/.kiln/events".

func (*Live) Session

func (l *Live) Session() *journal.Session

Session returns the current session. The caller must not mutate it.

func (*Live) SetFallbackFunc

func (l *Live) SetFallbackFunc(fn func(*http.Request) string)

SetFallbackFunc installs a per-request fallback renderer. Use when the fallback HTML depends on request headers (e.g. host/port for rendering correct curl examples). Mutually exclusive with SetFallbackHTML — the most recent setter wins.

func (*Live) SetFallbackHTML

func (l *Live) SetFallbackHTML(html string)

SetFallbackHTML installs a catch-all HTML response for any request the world doesn't claim. Empty disables the fallback (default). cmd/kiln wires this to chat.HostHTML() so every URL surfaces the floating widget when no page is registered.

func (*Live) Subscribe

func (l *Live) Subscribe() (<-chan Event, func())

Subscribe returns a channel of events and an unsubscribe function.

Jump to

Keyboard shortcuts

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