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
- Variables
- func IsKnownCapability(capability string) bool
- func IsKnownDBPermission(permission string) bool
- func IsKnownHook(hook string) bool
- func IsValidHTTPPattern(pattern string) bool
- func KnownCapabilities() []string
- func KnownDBPermissions() []string
- func KnownHooks() []string
- func SynthesizeManifest(project Project) (string, error)
- func ValidateBrief(brief Brief) error
- func ValidateProjectFiles(files map[string]string) error
- func ValidateProjectName(name string) error
- type Brief
- type BuildResult
- type Builder
- type Finding
- type InstalledProject
- type PluginGenerationService
- type PluginSources
- type Project
- type ProjectManifest
- type ProjectStore
- type ProjectValidator
- type Service
- func (s *Service) Build(ctx context.Context, name string) (BuildResult, error)
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Generate(ctx context.Context, brief Brief) (Project, ValidationReport, error)
- func (s *Service) Get(ctx context.Context, name string) (Project, error)
- func (s *Service) List(ctx context.Context) ([]InstalledProject, error)
- func (s *Service) Validate(ctx context.Context, project Project) ValidationReport
- func (s *Service) Zip(ctx context.Context, name string) ([]byte, error)
- type ValidationReport
Constants ¶
const ( // FindingSeverityError blocks install. FindingSeverityError = "error" // FindingSeverityWarning surfaces in the UI without blocking. FindingSeverityWarning = "warning" )
Variables ¶
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 = 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 = 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 ¶
IsKnownCapability reports whether capability names a known host function.
func IsKnownDBPermission ¶
IsKnownDBPermission reports whether permission is a grantable database permission from the capability manifest vocabulary.
func IsKnownHook ¶
IsKnownHook reports whether hook is a known WASM export suffix.
func IsValidHTTPPattern ¶
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 SynthesizeManifest ¶
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 ¶
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 ¶
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 ¶
ValidateProjectName reports whether name is an installable project slug: lowercase alphanumerics and dashes, 2–50 runes, not reserved.
Types ¶
type BuildResult ¶
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 ¶
Finding is one validation result: a rule hit with severity and detail. Errors block install; warnings surface in the UI only.
func NewFinding ¶
NewFinding assembles a validation finding.
func ScanGeneratedProjectFiles ¶
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 ¶
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 ¶
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.
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 ¶
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) Generate ¶
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) List ¶
func (s *Service) List(ctx context.Context) ([]InstalledProject, error)
List returns the installed-project projections.
type ValidationReport ¶
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.