generator

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFS = templateFS

TemplateFS exposes the embedded template tree for callers outside the generator package (e.g. the patch subcommand that renders a subset of templates against already-published CLIs).

Functions

func DetectAsyncJobs

func DetectAsyncJobs(s *spec.APISpec) map[string]AsyncJobInfo

DetectAsyncJobs walks an APISpec and returns one AsyncJobInfo per detected async-job endpoint, keyed by "<resourceName>/<endpointName>".

Detection requires both strong signals:

  1. The endpoint's response payload contains a field whose name matches jobIDFieldPattern (job_id, task_id, operation_id, ...).
  2. A sibling endpoint exists that looks like a status probe for the same resource - either a GET on the same resource (common get/status/show), a same-resource sibling whose name contains "status" or "poll", or an endpoint in a separate jobs/operations/status-flavored resource.

Both signals are load-bearing: the job-id field names what to track and the sibling names where to poll. A plain CRUD POST that happens to have a sibling GET is not marked async - without a job-id-shaped response field, we do not assume the endpoint is long-running.

HTTP status code 202 would be a third signal; the internal spec model does not track per-status-code responses, so we omit it and rely on the two remaining signals.

The function is pure - it does not mutate the spec. The caller decides how to use the detection map (template data, dogfood checks, scorecard).

func FormatWarnings

func FormatWarnings(warnings []AITextWarning) string

FormatWarnings returns a human-readable summary of text filter warnings.

func GenerateFromPlan

func GenerateFromPlan(planSpec *PlanSpec, outputDir string) error

GenerateFromPlan creates a CLI scaffold from a parsed plan spec.

Types

type AITextWarning

type AITextWarning struct {
	Pattern string
	Match   string
	Line    int
	Context string // surrounding text
}

AITextWarning records a single match of AI-characteristic text.

func CheckText

func CheckText(text string) []AITextWarning

CheckText scans text for AI-characteristic patterns and returns warnings. It never modifies text - only reports matches.

type AsyncJobInfo

type AsyncJobInfo struct {
	// ResourceName and EndpointName identify the submitting endpoint
	// (the one that returns a job ID).
	ResourceName string
	EndpointName string

	// JobIDField is the response field name that carries the job identifier
	// (e.g. "job_id", "task_id"). Empty when detection fell back to
	// path-sibling inference.
	JobIDField string

	// StatusResource and StatusEndpoint point at the sibling status
	// endpoint used by the --wait polling loop. Empty only if no sibling
	// was found (in which case the endpoint is not marked async).
	StatusResource string
	StatusEndpoint string

	// StatusPath is the URL path template for the polling endpoint,
	// copied from the sibling endpoint's Path. The runtime substitutes
	// {id} or {job_id} with the actual job ID.
	StatusPath string

	// TerminalField and TerminalValues describe how the polling loop
	// decides the job is done. Defaults to "status" with a common
	// done/complete/completed/failed/errored set when the spec does not
	// declare one explicitly.
	TerminalField  string
	TerminalValues []string
}

AsyncJobInfo describes one async-job endpoint detected from a spec. Populated at generation time and carried into template data so generated commands can expose --wait and a shared jobs store.

type ColumnDef

type ColumnDef struct {
	Name       string
	Type       string
	PrimaryKey bool
	NotNull    bool
}

type DomainContext

type DomainContext struct {
	APIName     string            `json:"api_name"`
	Description string            `json:"description"`
	Archetype   string            `json:"archetype"`
	Resources   []ResourceSummary `json:"resources"`
	QueryTips   []string          `json:"query_tips,omitempty"`
	Playbook    []PlaybookEntry   `json:"playbook,omitempty"`
}

DomainContext holds structured domain knowledge for MCP-connected agents. Front-loaded at session start so agents understand the API without discovery.

type EntityMapping

type EntityMapping struct {
	TableName       string
	HumanSingular   string
	HumanPlural     string
	IdentifierField string
	TitleField      string
	UpdatedAtField  string
	AssigneeField   string
	PriorityField   string
	DueDateField    string
	TeamField       string
	LabelField      string
	EstimateField   string
	StateField      string
}

type Generator

type Generator struct {
	Spec            *spec.APISpec
	OutputDir       string
	VisionSet       VisionTemplateSet
	FixtureSet      *browsersniff.FixtureSet
	TrafficAnalysis *browsersniff.TrafficAnalysis
	Sources         []ReadmeSource          // Ecosystem tools to credit in README
	DiscoveryPages  []string                // Pages visited during browser-sniff discovery
	NovelFeatures   []NovelFeature          // Transcendence features for README/SKILL
	Narrative       *ReadmeNarrative        // LLM-authored prose for README/SKILL; optional
	AsyncJobs       map[string]AsyncJobInfo // Detected async-job endpoints, keyed by "<resource>/<endpoint>"

	// Promoted-command plan, populated by Generate() before any rendering so
	// SKILL/README templates can honor leaf promotion (and not emit phantom paths
	// like `<cli> qr get-qrcode` for a resource the generator collapsed to `qr`).
	PromotedCommands      []PromotedCommand
	PromotedResourceNames map[string]bool
	PromotedEndpointNames map[string]string
	// contains filtered or unexported fields
}

func New

func New(s *spec.APISpec, outputDir string) *Generator

func (*Generator) Generate

func (g *Generator) Generate() error

func (*Generator) Validate

func (g *Generator) Validate() error

type HelperFlags

type HelperFlags struct {
	HasDelete          bool // spec has DELETE endpoints → emit classifyDeleteError
	HasPathParams      bool // spec has path parameters → emit replacePathParam
	HasMultiPositional bool // spec has endpoints with 2+ positional params → emit usageErr
	HasDataLayer       bool // CLI has a local store (sync/search) → emit provenance helpers
	HasClientLimit     bool // at least one endpoint needs client-side limit truncation → emit truncateJSONArray
}

HelperFlags controls which helper functions are emitted in helpers.go.

type IndexDef

type IndexDef struct {
	Name      string
	TableName string
	Columns   string
	Unique    bool
}

type NovelFeature

type NovelFeature struct {
	Name         string
	Command      string
	Description  string
	Rationale    string
	Example      string // ready-to-run invocation
	WhyItMatters string // one-sentence agent-facing rationale
	Group        string // theme name for grouped rendering
}

NovelFeature represents a transcendence feature for the README and SKILL.md.

type PlanCommand

type PlanCommand struct {
	Name        string // e.g., "record" or "auth login"
	Description string
}

PlanCommand represents a single command extracted from a plan document.

func (PlanCommand) Leaf

func (c PlanCommand) Leaf() string

Leaf returns the leaf command name (last word).

func (PlanCommand) Parent

func (c PlanCommand) Parent() string

Parent returns the parent command name for subcommands, or empty string for top-level.

type PlanSpec

type PlanSpec struct {
	CLIName     string
	Description string
	Commands    []PlanCommand
}

PlanSpec holds the parsed plan data used to drive generation.

func ParsePlan

func ParsePlan(content string) *PlanSpec

ParsePlan extracts CLI metadata and command definitions from a markdown plan document. It is tolerant of different plan formats: command lists, implementation units, and architecture sections.

type PlaybookEntry

type PlaybookEntry struct {
	Topic   string `json:"topic"`
	Insight string `json:"insight"`
}

PlaybookEntry is a domain-specific insight for agents.

type PromotedCommand

type PromotedCommand struct {
	PromotedName string
	ResourceName string
	Endpoint     spec.Endpoint
	EndpointName string
}

PromotedCommand represents a top-level user-friendly command that wraps a nested API endpoint.

type QuickStartStep

type QuickStartStep struct {
	Command string
	Comment string
}

QuickStartStep mirrors pipeline.QuickStartStep for template rendering.

type ReadmeNarrative

type ReadmeNarrative struct {
	DisplayName    string
	Headline       string
	ValueProp      string
	AuthNarrative  string
	QuickStart     []QuickStartStep
	Troubleshoots  []TroubleshootTip
	WhenToUse      string
	Recipes        []Recipe
	TriggerPhrases []string
}

ReadmeNarrative mirrors pipeline.ReadmeNarrative for template rendering. Holds LLM-authored prose that makes generated docs feel like product documentation rather than scaffolding. All fields are optional.

type ReadmeSource

type ReadmeSource struct {
	Name     string
	URL      string
	Language string
	Stars    int
}

ReadmeSource represents a credited ecosystem tool for the README.

type Recipe

type Recipe struct {
	Title       string
	Command     string
	Explanation string
}

Recipe mirrors pipeline.Recipe for SKILL.md template rendering.

type ResourceSummary

type ResourceSummary struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Endpoints   []string `json:"endpoints"`
	Syncable    bool     `json:"syncable,omitempty"`
	Searchable  bool     `json:"searchable,omitempty"`
}

ResourceSummary describes an API resource and its capabilities for agents.

type TableDef

type TableDef struct {
	Name         string
	Columns      []ColumnDef
	Indexes      []IndexDef
	FTS5         bool
	FTS5Fields   []string
	FTS5Triggers bool
}

func BuildSchema

func BuildSchema(s *spec.APISpec) []TableDef

BuildSchema generates domain-specific table definitions from the API spec. High-gravity entities (many endpoints, text fields, temporal fields) get full column extraction. Low-gravity entities get simple id+data tables.

type TroubleshootTip

type TroubleshootTip struct {
	Symptom string
	Fix     string
}

TroubleshootTip mirrors pipeline.TroubleshootTip for template rendering.

type VisionTemplateSet

type VisionTemplateSet struct {
	Export    bool
	Import    bool
	Store     bool
	Search    bool
	Sync      bool
	Tail      bool
	Analytics bool
	MCP       bool
	Workflows []string
	Insights  []string
}

VisionTemplateSet defines which visionary templates to include in generation.

func SelectVisionTemplates

func SelectVisionTemplates(plan *vision.VisionaryPlan) VisionTemplateSet

SelectVisionTemplates determines which domain-aware templates to include based on the visionary research plan's architecture decisions and feature scores.

func (VisionTemplateSet) CmdNames

func (s VisionTemplateSet) CmdNames() map[string]bool

CmdNames returns a set of command names that the VisionSet registers in root.go. Used to exclude these from the Resources loop to prevent duplicates when an API has an endpoint with the same name (e.g., /analytics).

func (VisionTemplateSet) HasInsights

func (s VisionTemplateSet) HasInsights() bool

func (VisionTemplateSet) HasWorkflows

func (s VisionTemplateSet) HasWorkflows() bool

func (VisionTemplateSet) IsZero

func (s VisionTemplateSet) IsZero() bool

func (VisionTemplateSet) TemplateNames

func (s VisionTemplateSet) TemplateNames() []string

TemplateNames returns the list of template filenames to render.

type WorkflowTemplateContext

type WorkflowTemplateContext struct {
	CLIName       string
	APIName       string
	Domain        string
	PrimaryEntity EntityMapping
	TeamEntity    EntityMapping
	UserEntity    EntityMapping
	StateEntity   EntityMapping
	HasAssignees  bool
	HasDueDates   bool
	HasPriority   bool
	HasTeams      bool
	HasLabels     bool
	HasEstimates  bool
}

Jump to

Keyboard shortcuts

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