From 4e307bd3b7327e7b7ad171afc4a82253028c214a Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Tue, 29 Apr 2025 17:20:35 -0500 Subject: [PATCH] Make sure agent create has a reference to the template so we can reference it in interpolation --- cmd/agent.go | 6 ++++++ internal/templates/template.go | 3 +++ internal/templates/templates.go | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/cmd/agent.go b/cmd/agent.go index 52a8fc4e..38e53395 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -305,6 +305,11 @@ var agentCreateCmd = &cobra.Command{ errsystem.New(errsystem.ErrInvalidConfiguration, err, errsystem.WithAttributes(map[string]any{"identifier": theproject.Project.Bundler.Identifier})).ShowErrorAndExit() } + template, err := templates.LoadTemplateForRuntime(context.Background(), tmpdir, theproject.Project.Bundler.Identifier) + if err != nil { + errsystem.New(errsystem.ErrInvalidConfiguration, err, errsystem.WithAttributes(map[string]any{"identifier": theproject.Project.Bundler.Identifier})).ShowErrorAndExit() + } + if err := rules.NewAgent(templates.TemplateContext{ Logger: logger, AgentName: name, @@ -313,6 +318,7 @@ var agentCreateCmd = &cobra.Command{ AgentDescription: description, ProjectDir: theproject.Dir, TemplateDir: tmpdir, + Template: template, AgentuityCommand: getAgentuityCommand(), }); err != nil { errsystem.New(errsystem.ErrApiRequest, err, errsystem.WithAttributes(map[string]any{"name": name})).ShowErrorAndExit() diff --git a/internal/templates/template.go b/internal/templates/template.go index 9457e66f..1fb51377 100644 --- a/internal/templates/template.go +++ b/internal/templates/template.go @@ -159,6 +159,9 @@ func (t *TemplateRules) NewProject(ctx TemplateContext) error { } func (t *TemplateRules) NewAgent(ctx TemplateContext) error { + if ctx.Template == nil { + return fmt.Errorf("template is nil and is required") + } for _, step := range t.NewAgentSteps.Steps { if command, ok := resolveStep(ctx, step); ok { if err := command.Run(ctx); err != nil { diff --git a/internal/templates/templates.go b/internal/templates/templates.go index aad42efc..43c95527 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -392,6 +392,19 @@ func LoadTemplates(ctx context.Context, dir string, custom bool) (Templates, err return LoadTemplatesFromGithub(ctx, dir) } +func LoadTemplateForRuntime(ctx context.Context, dir string, runtime string) (*Template, error) { + templates, err := LoadTemplates(ctx, dir, false) + if err != nil { + return nil, err + } + for _, template := range templates { + if template.Identifier == runtime { + return &template, nil + } + } + return nil, fmt.Errorf("template for runtime %s not found", runtime) +} + func LoadLanguageTemplates(ctx context.Context, dir string, runtime string) (LanguageTemplates, error) { filename := filepath.Join(dir, runtime, "templates.yaml") reader, err := getEmbeddedFile(filename)