inspect

package
v0.1.124 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package inspect reads a Līdza project's source and produces the context an agent needs: the API routes with their handler signatures, the Rust exports, and the configuration. `lidza context` writes it to .lidza/context.json; `lidza mcp` and the /llms.txt endpoints serve it.

Index

Constants

View Source
const (
	LLMSFile     = ".lidza/llms.txt"
	LLMSFullFile = ".lidza/llms-full.txt"
	OpenAPIFile  = ".lidza/openapi.json"
)

Files under .lidza that Refresh writes and the dev server serves.

View Source
const FileName = ".lidza/context.json"

FileName is the context dump, relative to the project root.

View Source
const GuideFile = "docs/lidza-guide.md"

GuideFile is the app's guide, written by `lidza new`, relative to the project root. It opens /llms-full.txt.

Variables

This section is empty.

Functions

func LLMS

func LLMS(c *Context, cfg *config.Config, guide string) (short, full string)

LLMS renders /llms.txt (short: what the app is, its routes, its commands) and /llms-full.txt (the guide, every handler signature, the Rust exports and the configuration). guide is the app's docs/lidza-guide.md, may be empty.

func LLMSFor

func LLMSFor(dir string, cfg *config.Config) (short, full string, err error)

LLMSFor inspects the project and renders both llms documents.

func ModulePath

func ModulePath(root string) string

ModulePath reads the module path from root/go.mod, or "".

func OpenAPI

func OpenAPI(c *Context) map[string]any

OpenAPI renders the OpenAPI 3.1 document for the project: one operation per typed route with its schemas, and a bare entry for each untyped route. Path parameters are strings.

Types

type App

type App struct {
	Name     string `json:"name"`
	Module   string `json:"module"`
	Template string `json:"template"`
	// Dir is the absolute project root.
	Dir string `json:"dir"`
}

App identifies the project.

type Context

type Context struct {
	Generated time.Time `json:"generated"`
	// Lidza is the framework version that produced the dump.
	Lidza string `json:"lidza"`
	App   App    `json:"app"`
	// Routes lists every registration found in the source, typed or not.
	Routes []Route `json:"routes"`
	// Operations are the typed routes with their schemas; Schemas holds the
	// JSON Schema components they reference.
	Operations []Operation    `json:"operations"`
	Schemas    map[string]any `json:"schemas"`
	Rust       *Rust          `json:"rust,omitempty"`
	// Warnings are type-check errors: the operations may be incomplete
	// until they are fixed.
	Warnings []string `json:"warnings,omitempty"`
}

Context is the machine-readable description of a project.

func Project

func Project(dir string, cfg *config.Config) (*Context, error)

Project reads everything in dir. cfg may be nil for a plain Go module.

func Refresh

func Refresh(dir string, cfg *config.Config) (*Context, error)

Refresh writes .lidza/context.json, .lidza/openapi.json, .lidza/llms.txt and .lidza/llms-full.txt, and returns the context so callers can generate clients from it. `lidza dev` calls it after every successful build.

func Write

func Write(dir string, cfg *config.Config) (*Context, error)

Write dumps the context to dir/.lidza/context.json and returns it.

type Export

type Export struct {
	Name      string `json:"name"`
	File      string `json:"file"`
	Line      int    `json:"line"`
	Signature string `json:"signature"`
}

Export is a `#[no_mangle] pub extern "C" fn`: what the Go side can call.

type Handler

type Handler struct {
	// Name is the function name, "pkg.Func" for one from another package,
	// or "func literal" for an inline handler.
	Name string `json:"name"`
	// File and Line point at the registration for literals and at the
	// declaration for named functions. File is relative to the project root.
	File      string `json:"file,omitempty"`
	Line      int    `json:"line,omitempty"`
	Signature string `json:"signature,omitempty"`
}

Handler describes the function behind a route.

type Operation

type Operation struct {
	// ID is the operationId and the client method name: the handler's name
	// in lowerCamel, or method plus path for a func literal.
	ID     string `json:"id"`
	Method string `json:"method"`
	Path   string `json:"path"`
	// Params are the path parameters, in order.
	Params []string `json:"params"`
	// Input and Output name the component schema (empty for router.None).
	// For a stream, Output is the schema of one event.
	Input  string `json:"input,omitempty"`
	Output string `json:"output,omitempty"`
	// Stream marks a router.Stream operation: the reply is server-sent
	// events, each one Output as JSON.
	Stream bool `json:"stream,omitempty"`
	// Upload marks a router.Route whose In is router.File: the request
	// body is a file sent raw, not JSON, and Input is empty.
	Upload  bool    `json:"upload,omitempty"`
	Handler Handler `json:"handler"`
	// Builtin marks operations the framework registers in every app.
	Builtin bool `json:"builtin,omitempty"`
	// Pack names the framework pack whose Mount registered the operation
	// (auth for the sign-in routes); empty for the app's own.
	Pack string `json:"pack,omitempty"`
}

Operation is a typed route (router.Route[In, Out] or router.Stream[In, Event]) with the JSON Schemas of its input and output, the basis of the OpenAPI document and the generated client.

type Route

type Route struct {
	// Method is empty when the pattern matches every method.
	Method string `json:"method,omitempty"`
	Path   string `json:"path"`
	// Pattern is the net/http ServeMux pattern as written.
	Pattern string  `json:"pattern"`
	Handler Handler `json:"handler"`
	// Builtin marks routes the framework registers in every app.
	Builtin bool `json:"builtin,omitempty"`
	// Typed marks routes registered with router.Route or router.Stream;
	// their schemas are in Context.Operations.
	Typed bool `json:"typed,omitempty"`
	// Pack names the framework pack whose Mount registered the route.
	Pack string `json:"pack,omitempty"`
}

Route is one registered API route.

type Rust

type Rust struct {
	Crate string `json:"crate"`
	// Dir is the crate directory relative to the project root.
	Dir     string   `json:"dir"`
	Exports []Export `json:"exports"`
}

Rust describes the project's Rust crate.

Jump to

Keyboard shortcuts

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