Documentation
¶
Overview ¶
Package infrastructure adapts the modgen domain port onto OpenAI-compatible chat-completion APIs. Prompt construction grounds the model on the distilled module contract; response validation stays in the domain's envelope parser.
Index ¶
- func AppendMakefileSubmodule(content, name string) (string, error)
- func BuildRepairPrompt(brief modgendomain.Brief, moduleFiles map[string]string, problems []string) string
- func BuildSystemPrompt(sources modgendomain.ModuleSources) string
- func BuildUserPrompt(brief modgendomain.Brief) string
- func InsertGoWorkUse(content, name string) (string, error)
- func IsCheckoutDir(root string) bool
- func RemoveGoWorkUse(content, name string) (string, error)
- func RemoveMakefileSubmodule(content, name string) (string, error)
- func RenderCustomEdition(modules []string, moduleGo map[string]string) string
- func RenderCustomMain() string
- func RestoreReplaceBackup(moduleDir, backup string)
- func StageReplaceBackup(moduleDir string) (string, error)
- type CheckoutApplier
- func (a *CheckoutApplier) Applied(_ context.Context) ([]string, error)
- func (a *CheckoutApplier) Apply(ctx context.Context, project modgendomain.Project, replace, confirm bool) (modgendomain.ApplyResult, error)
- func (a *CheckoutApplier) Unapply(ctx context.Context, name string, confirm bool) (modgendomain.UnapplyResult, error)
- type OpenAIModuleService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendMakefileSubmodule ¶
AppendMakefileSubmodule extends the SUBMODULES line idempotently. A missing anchor fails closed.
func BuildRepairPrompt ¶
func BuildRepairPrompt(brief modgendomain.Brief, moduleFiles map[string]string, problems []string) string
BuildRepairPrompt feeds validation findings back to the model.
func BuildSystemPrompt ¶
func BuildSystemPrompt(sources modgendomain.ModuleSources) string
BuildSystemPrompt assembles the module generation system prompt from the distilled contract plus the edition's grounding sources.
func BuildUserPrompt ¶
func BuildUserPrompt(brief modgendomain.Brief) string
BuildUserPrompt assembles the user prompt from the brief.
func InsertGoWorkUse ¶
InsertGoWorkUse inserts ./modules/<name> into the go.work use block. Idempotent: a present entry is a no-op. A missing anchor fails closed.
func IsCheckoutDir ¶
IsCheckoutDir reports whether root is a Lesstruct source checkout: the root go.mod declares the Lesstruct module and a .git entry exists. The edition uses it for the apply readiness flag; Apply itself fails closed with ErrNotCheckout.
func RemoveGoWorkUse ¶
RemoveGoWorkUse removes ./modules/<name> from the go.work use block. Idempotent: a missing entry is a no-op for registry/go.work desyncs. A missing use block fails closed.
func RemoveMakefileSubmodule ¶
RemoveMakefileSubmodule removes the modules/<name> token from the SUBMODULES line. Idempotent for registry/Makefile desyncs; a missing anchor fails closed.
func RenderCustomEdition ¶
RenderCustomEdition generates the machine-owned custom edition package from the applied registry. Every module adopts the shared database, dialect, and logger through its adoption options; the base blog composition wires first (the commerce decoration pattern).
func RenderCustomMain ¶
func RenderCustomMain() string
RenderCustomMain generates the machine-owned thin main for the custom binary, mirroring cmd/lesstruct-ecommerce/main.go.
func RestoreReplaceBackup ¶
func RestoreReplaceBackup(moduleDir, backup string)
RestoreReplaceBackup puts a staged backup back after a failed replace, removing any partial new tree first. An empty backup is a no-op.
func StageReplaceBackup ¶
StageReplaceBackup moves an applied tree aside so a replace starts from a clean directory. It returns the backup path the rollback restores.
Types ¶
type CheckoutApplier ¶
type CheckoutApplier struct {
// contains filtered or unexported fields
}
CheckoutApplier implements modgendomain.Applier by staging generated projects into a Lesstruct source checkout: the module tree, the machine-writable registry edits, the regenerated custom edition, and a compile-and-test verification. Refusals (not a checkout, collisions, dirty shared files, hand-owned machine paths) return sentinel errors before any write; verification failures keep the applied tree and report per-step outcomes.
func NewCheckoutApplier ¶
func NewCheckoutApplier(root, goPath, kernelVersion string, timeout time.Duration, run applyRunFunc) *CheckoutApplier
NewCheckoutApplier builds the checkout applier over root (the Lesstruct source checkout; "" means the server working directory). goPath names the Go toolchain ("" selects PATH lookup at call time); kernelVersion is recorded for future install metadata; timeout bounds verification ("" or non-positive selects the default); run executes verification commands (nil selects the real subprocess runner).
func (*CheckoutApplier) Applied ¶
func (a *CheckoutApplier) Applied(_ context.Context) ([]string, error)
func (*CheckoutApplier) Apply ¶
func (a *CheckoutApplier) Apply(ctx context.Context, project modgendomain.Project, replace, confirm bool) (modgendomain.ApplyResult, error)
Apply stages one generated project into the source checkout: guard, writes with rollback, custom-edition regeneration, and verification. Verification failures keep the tree and report findings; write failures roll back. A colliding tree owned by the registry is replaced only with replace and confirm; hand-placed trees are never touched.
func (*CheckoutApplier) Unapply ¶
func (a *CheckoutApplier) Unapply(ctx context.Context, name string, confirm bool) (modgendomain.UnapplyResult, error)
Unapply removes an applied module from the source checkout: the registry entry, the regenerated custom edition, and the module tree. The membership matrix decides: applied without a tree performs the registry/edition cleanup with ModuleDirRemoved false; anything the registry does not hold refuses with ErrNotApplied — hand-placed trees are never removed. Tracked operator edits inside the tree refuse with ErrTreeDirty. Verification runs the custom-binary build and keeps the removal on failure, reporting per-step outcomes.
type OpenAIModuleService ¶
type OpenAIModuleService struct {
// contains filtered or unexported fields
}
OpenAIModuleService implements modgendomain.ModuleGenerationService over any OpenAI-compatible chat-completion API.
func NewOpenAIModuleService ¶
func NewOpenAIModuleService(apiKey, baseURL, model string) *OpenAIModuleService
NewOpenAIModuleService builds the OpenAI-compatible module generation service. baseURL is optional ("" = provider default); model names the chat model.
func (*OpenAIModuleService) GenerateProject ¶
func (s *OpenAIModuleService) GenerateProject( ctx context.Context, brief modgendomain.Brief, sources modgendomain.ModuleSources, ) (modgendomain.Project, error)
GenerateProject asks the model for the JSON envelope and validates it via the domain parser. Files stay verbatim so validation and the repair loop see the model's original output. A response that is not valid JSON gets one immediate re-ask through the repair prompt — malformed output is the most common real failure mode, and without this the service-level repair loop (which only runs on parsed projects) would never engage.
func (*OpenAIModuleService) RepairProject ¶
func (s *OpenAIModuleService) RepairProject( ctx context.Context, brief modgendomain.Brief, sources modgendomain.ModuleSources, project modgendomain.Project, problems []string, ) (modgendomain.Project, error)
RepairProject feeds validation problems back to the model (the caller bounds the attempts). The system prompt matches the generation one so the contract stays identical across repairs.