scaffold

package
v0.40.7 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package scaffold renders embedded starter templates into a target directory so callers can bootstrap a SpeechKit integration without hand-copying boilerplate. The engine is invoked from speechkitctl init for humans and from speechkit-mcp's read-only scaffold tools for coding agents; both share the same template set.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownTemplate is returned when ScaffoldOptions.Template does
	// not match any embedded template directory.
	ErrUnknownTemplate = errors.New("scaffold: unknown template")

	// ErrMissingRequiredVar is returned when a non-optional VarSpec is
	// neither overridden nor satisfiable from EnvHint and Default and
	// Interactive is false.
	ErrMissingRequiredVar = errors.New("scaffold: missing required variable")
)

Functions

func FS

func FS() fs.FS

FS exposes the embedded template filesystem for callers that want to list or inspect templates without invoking the full Scaffold pipeline (e.g. an MCP "list templates" tool).

func SafeJoin

func SafeJoin(root, rel string) (string, error)

SafeJoin joins root + rel and rejects any path that would escape root. Exposed for the MCP scaffold handler so it can validate output_dir before writing.

Types

type GeneratedFile

type GeneratedFile struct {
	RelPath string
	AbsPath string
	Content []byte
}

GeneratedFile is one file the scaffolder produced. AbsPath is set only when OutputDir was configured.

type HookResult

type HookResult struct {
	Description string
	Cmd         string
	Success     bool
	Output      string
}

HookResult records the outcome of one PostInitHook execution.

type PostInitHook

type PostInitHook struct {
	Description string `toml:"description"`
	Cmd         string `toml:"cmd"`
}

PostInitHook is a command run after files are written. Hooks fire in declaration order; the first non-zero exit aborts the rest.

type Result

type Result struct {
	Template string
	Vars     map[string]string
	Files    []GeneratedFile
	// Hooks reports which post-init hooks were executed (nil unless
	// RunPostInit was set).
	Hooks []HookResult
}

Result is returned by Scaffold and is also the response shape the MCP generate_integration tool serialises to JSON.

func Scaffold

func Scaffold(opts ScaffoldOptions) (*Result, error)

Scaffold renders the named template with the supplied variables. When OutputDir is non-empty, the resulting files are written to disk and the returned GeneratedFile entries carry AbsPath. When OutputDir is empty the engine returns the rendered content in-memory only, used by the MCP scaffold tool to hand files back to the calling agent.

func ScaffoldContext added in v0.31.0

func ScaffoldContext(ctx context.Context, opts ScaffoldOptions) (*Result, error)

ScaffoldContext is Scaffold with caller-controlled cancellation for post-init hooks. ctx must be non-nil.

type ScaffoldOptions

type ScaffoldOptions struct {
	// Template is the directory name under templates/.
	Template string

	// OutputDir is the absolute path to write files into. If empty, the
	// engine returns generated files in Result.Files without touching disk.
	OutputDir string

	// Vars are caller-provided variable overrides. They take precedence
	// over template defaults and EnvHint lookups.
	Vars map[string]string

	// Interactive, when true, prompts on stdin for any required variable
	// not satisfied by Vars / EnvHint / Default.
	Interactive bool

	// In and Out are used for interactive prompting and progress output.
	// When nil they default to os.Stdin and os.Stdout.
	In  io.Reader
	Out io.Writer

	// RunPostInit, when true, executes PostInitHook commands after files
	// are written. Disabled by default; hosts opt in.
	RunPostInit bool
}

ScaffoldOptions configure a Scaffold call.

type TemplateMeta

type TemplateMeta struct {
	Name             string         `toml:"name"`
	Description      string         `toml:"description"`
	MinServerVersion string         `toml:"min_server_version"`
	Vars             []VarSpec      `toml:"vars"`
	PostInit         []PostInitHook `toml:"post_init"`
	NextSteps        []string       `toml:"next_steps"`
}

TemplateMeta is the parsed template.toml.

func ListTemplates

func ListTemplates() ([]TemplateMeta, error)

ListTemplates returns the metadata for every embedded template in alphabetical order by name.

func LookupTemplate

func LookupTemplate(name string) (TemplateMeta, error)

LookupTemplate returns metadata for a single template, or ErrUnknownTemplate if the template is not a complete published template.

type VarSpec

type VarSpec struct {
	Name        string `toml:"name"`
	Description string `toml:"description"`
	Default     string `toml:"default"`
	EnvHint     string `toml:"env_hint"`
	Optional    bool   `toml:"optional"`
}

VarSpec describes one variable a template wants resolved before rendering.

Jump to

Keyboard shortcuts

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