plugingen

package
v1.6.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: 13 Imported by: 2 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 plugingen is the AI plugin generator module's domain layer: the brief, project, and validation value types, the generation/store ports, and the envelope parser that validates the model's JSON output. Provider adapters (the OpenAI-compatible client) live in infrastructure; the filesystem store lives in store; neither is imported by the domain.

Index

Constants

View Source
const (
	// FindingSeverityError blocks install.
	FindingSeverityError = "error"
	// FindingSeverityWarning surfaces in the UI without blocking.
	FindingSeverityWarning = "warning"
)

Variables

View Source
var (
	// ErrInvalidBrief reports an empty or over-long generation brief.
	ErrInvalidBrief = errors.New("invalid brief")
	// ErrInvalidProjectName reports a project name outside the slug grammar.
	ErrInvalidProjectName = errors.New("invalid project name")
	// ErrPathNotAllowed reports a project file path outside the allowlist.
	ErrPathNotAllowed = errors.New("path not allowed")
	// ErrSizeLimitExceeded reports a project file or total exceeding the caps.
	ErrSizeLimitExceeded = errors.New("size limit exceeded")
	// ErrGenerationFailed reports an AI generation or repair failure.
	ErrGenerationFailed = errors.New("generation failed")
	// ErrProjectExists reports an install colliding with an existing project dir.
	ErrProjectExists = errors.New("project exists")
	// ErrProjectNotFound reports a lookup for a missing project.
	ErrProjectNotFound = errors.New("project not found")
	// ErrGenerationUnavailable reports generation without an AI key.
	ErrGenerationUnavailable = errors.New("generation unavailable")
	// ErrInvalidHooks reports an empty or unknown hook list.
	ErrInvalidHooks = errors.New("invalid hooks")
	// ErrInvalidCapabilities reports an unknown capability declaration.
	ErrInvalidCapabilities = errors.New("invalid capabilities")
	// ErrInvalidHTTPPatterns reports a malformed HTTP URL grant.
	ErrInvalidHTTPPatterns = errors.New("invalid http patterns")
	// ErrInvalidDBPermissions reports an unknown database permission.
	ErrInvalidDBPermissions = errors.New("invalid db permissions")
	// ErrBuildUnavailable reports a build without a configured toolchain.
	ErrBuildUnavailable = errors.New("build unavailable")
	// ErrBuildFailed reports a TinyGo compile, load-check, or install failure.
	ErrBuildFailed = errors.New("build failed")
	// ErrPluginInstalled reports a build colliding with an installed plugin.
	ErrPluginInstalled = errors.New("plugin installed")
	// ErrInvalidManifest reports a project that cannot render a manifest.
	ErrInvalidManifest = errors.New("invalid manifest")
)

Functions

func IsKnownCapability

func IsKnownCapability(capability string) bool

IsKnownCapability reports whether capability names a known host function.

func IsKnownDBPermission

func IsKnownDBPermission(permission string) bool

IsKnownDBPermission reports whether permission is a grantable database permission from the capability manifest vocabulary.

func IsKnownHook

func IsKnownHook(hook string) bool

IsKnownHook reports whether hook is a known WASM export suffix.

func IsValidHTTPPattern

func IsValidHTTPPattern(pattern string) bool

IsValidHTTPPattern reports whether pattern is a well-formed capability manifest grant: an https URL on a host without userinfo, optionally ending in a path-scoped trailing wildcard. The rule mirrors the host's matchPattern: only a trailing "/..." carries wildcard meaning, so a grant like "https://a*" — which would authorize every host starting with "a" — is rejected, as is cleartext http.

func KnownCapabilities

func KnownCapabilities() []string

KnownCapabilities returns the canonical host-function list.

func KnownDBPermissions

func KnownDBPermissions() []string

KnownDBPermissions returns the canonical database permission list.

func KnownHooks

func KnownHooks() []string

KnownHooks returns the canonical hook suffix list.

func SynthesizeManifest

func SynthesizeManifest(project Project) (string, error)

SynthesizeManifest renders the host capability TOML sidecar for a validated project: name, version, advisory memory ceiling, and the [capabilities] http/database grants the build step installs next to the .wasm. It is the single renderer — server, CLI, and docs all describe this shape.

func ValidateBrief

func ValidateBrief(brief Brief) error

ValidateBrief enforces the generation brief contract: non-empty and capped at 5,000 runes; hooks must be non-empty and known; capabilities must be known when present; language is go-only in v1.

func ValidateProjectFiles

func ValidateProjectFiles(files map[string]string) error

ValidateProjectFiles enforces the v1 project contract: main.go plus go.mod required, allowlisted paths only, per-file 512 KiB and 2 MiB total caps.

func ValidateProjectName

func ValidateProjectName(name string) error

ValidateProjectName reports whether name is an installable project slug: lowercase alphanumerics and dashes, 2–50 runes, not reserved.

Types

type Brief

type Brief struct {
	Description  string
	Language     string
	Hooks        []string
	Capabilities []string
}

Brief is the natural-language plugin request from the admin UI.

func NewBrief

func NewBrief(
	description, language string,
	hooks []string,
	capabilities []string,
) Brief

NewBrief assembles a generation brief from its parts.

type BuildResult

type BuildResult struct {
	Installed       bool
	RequiresRestart bool
}

BuildResult is the outcome of a server-side plugin build: whether the .wasm and manifest installed into plugins/, and whether the host needs a restart to load them (production) or hot-reloaded them already (DEV_MODE).

func NewBuildResult

func NewBuildResult(installed, requiresRestart bool) BuildResult

NewBuildResult assembles a build result.

type Builder

type Builder interface {
	Build(ctx context.Context, project Project) (BuildResult, error)
}

Builder compiles a validated project to WASM and installs it into the host's plugins directory.

type Finding

type Finding struct {
	Rule     string
	Severity string
	Message  string
}

Finding is one validation result: a rule hit with severity and detail. Errors block install; warnings surface in the UI only.

func NewFinding

func NewFinding(rule, severity, message string) Finding

NewFinding assembles a validation finding.

func ScanGeneratedProjectFiles

func ScanGeneratedProjectFiles(files map[string]string) []Finding

ScanGeneratedProjectFiles flags content a generated project must not ship: linker directives, wasmexport tricks, and javascript: URLs in Go source. It runs only on the generation path so repair findings stay deterministic.

type InstalledProject

type InstalledProject struct {
	Name      string
	Language  string
	Hooks     []string
	CreatedAt time.Time
	Source    string
}

InstalledProject is the manifest projection the list endpoint serves: identity, language, hooks, creation time, and provenance.

func NewInstalledProject

func NewInstalledProject(
	name, language string,
	hooks []string,
	createdAt time.Time,
	source string,
) InstalledProject

NewInstalledProject assembles an installed-project projection.

type PluginGenerationService

type PluginGenerationService interface {
	GenerateProject(ctx context.Context, brief Brief, sources PluginSources) (Project, error)
	RepairProject(ctx context.Context, brief Brief, sources PluginSources, project Project, problems []string) (Project, error)
}

PluginGenerationService generates plugin projects from a brief. Sources carries the readable SDK contract and hook examples the prompts ground on. RepairProject feeds validation problems back to the model and receives the same brief and sources so the contract stays identical.

type PluginSources

type PluginSources struct {
	Contract string
	Examples string
}

PluginSources is the prompt grounding: the distilled SDK contract plus the hook payload example the generator derives from.

func NewPluginSources

func NewPluginSources(contract, examples string) PluginSources

NewPluginSources assembles the prompt grounding material.

type Project

type Project struct {
	Name          string
	Language      string
	Hooks         []string
	Capabilities  []string
	HTTPPatterns  []string
	DBPermissions []string
	Files         map[string]string
	Rationale     string
}

Project is a validated generated plugin project: an installable slug plus the relative-path → content file map the store persists. HTTPPatterns and DBPermissions carry the capability manifest's URL and database grants; the envelope parser fills them, and the build step synthesizes the TOML sidecar from them.

func NewProject

func NewProject(
	name, language string,
	hooks []string,
	capabilities []string,
	files map[string]string,
	rationale string,
) Project

NewProject assembles a project from its validated parts.

func ParseProjectEnvelope

func ParseProjectEnvelope(responseText string) (Project, error)

ParseProjectEnvelope validates the model's JSON envelope and splits it into a Project. The name and files run the slug and allowlist validators; markdown fences and surrounding commentary are rejected.

type ProjectManifest

type ProjectManifest struct {
	Name          string    `json:"name"`
	Language      string    `json:"language"`
	Hooks         []string  `json:"hooks"`
	Capabilities  []string  `json:"capabilities"`
	HTTPPatterns  []string  `json:"httpPatterns,omitempty"`
	DBPermissions []string  `json:"dbPermissions,omitempty"`
	Generator     string    `json:"generator"`
	CreatedAt     time.Time `json:"createdAt"`
	Source        string    `json:"source"`
}

ProjectManifest is the on-disk project.json metadata: identity, provenance, and the capability grants the build step synthesizes the TOML sidecar from.

func NewProjectManifest

func NewProjectManifest(
	name, language string,
	hooks []string,
	capabilities []string,
	httpPatterns []string,
	dbPermissions []string,
	generator string,
	createdAt time.Time,
	source string,
) ProjectManifest

NewProjectManifest assembles a manifest for an installed project.

type ProjectStore

type ProjectStore interface {
	Install(ctx context.Context, project Project) error
	List(ctx context.Context) ([]InstalledProject, error)
	Get(ctx context.Context, name string) (Project, error)
	Delete(ctx context.Context, name string) error
	Zip(ctx context.Context, name string) ([]byte, error)
}

ProjectStore persists generated projects on disk and builds download zips.

type ProjectValidator

type ProjectValidator interface {
	Validate(ctx context.Context, project Project) ValidationReport
}

ProjectValidator checks a generated project before install: size caps, Go parse shape, hook and host-function policy.

func NewValidator

func NewValidator() ProjectValidator

NewValidator builds the default project validator.

type Service

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

Service orchestrates plugin generation: brief validation, AI generation, validation gate with a bounded repair loop, and install as a source project. Build compiles an installed project to WASM through the builder seam (nil builder disables builds).

func NewService

func NewService(
	generation PluginGenerationService,
	validator ProjectValidator,
	store ProjectStore,
	sources func(ctx context.Context) PluginSources,
) *Service

NewService builds the orchestration service. A nil store disables persistence (generation still validates); a nil builder disables builds; a nil sources func generates from the distilled contract alone.

func NewServiceWithBuilder

func NewServiceWithBuilder(
	generation PluginGenerationService,
	validator ProjectValidator,
	store ProjectStore,
	builder Builder,
	sources func(ctx context.Context) PluginSources,
) *Service

NewServiceWithBuilder builds the orchestration service with a WASM build seam. It is the constructor the composition root uses; NewService is the builder-less specialization tests and minimal embeddings use.

func (*Service) Build

func (s *Service) Build(ctx context.Context, name string) (BuildResult, error)

Build compiles one installed project to WASM and installs the .wasm plus the synthesized capability manifest into the host's plugins directory. The resolved name hides nothing: an unknown or malformed name reads as not-found, like Get.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, name string) error

Delete removes an installed project.

func (*Service) Generate

func (s *Service) Generate(
	ctx context.Context,
	brief Brief,
) (Project, ValidationReport, error)

Generate validates the brief, asks the model, validates the result, and installs it as a source project. A failing result is sent back to the model up to maxRepairAttempts times with its findings; a still-failing project is refused. The final report is returned alongside the project even on success so the UI can surface warnings.

func (*Service) Get

func (s *Service) Get(ctx context.Context, name string) (Project, error)

Get returns one installed project by name.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]InstalledProject, error)

List returns the installed-project projections.

func (*Service) Validate

func (s *Service) Validate(ctx context.Context, project Project) ValidationReport

Validate runs the validation gate without persisting.

func (*Service) Zip

func (s *Service) Zip(ctx context.Context, name string) ([]byte, error)

Zip builds the download archive for one installed project.

type ValidationReport

type ValidationReport struct {
	Valid    bool
	Findings []Finding
}

ValidationReport is the outcome of validating a project before install. Valid is false when any error-severity finding exists.

func NewFindingsReport

func NewFindingsReport(findings []Finding) ValidationReport

NewFindingsReport assembles a report whose Valid is derived from the findings: false when any error-severity finding exists.

func NewValidationReport

func NewValidationReport(valid bool, findings []Finding) ValidationReport

NewValidationReport assembles a validation report.

Jump to

Keyboard shortcuts

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