Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions internal/commands/prime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package commands

import (
_ "embed"
"os"
"text/template"

"github.com/spf13/cobra"
"github.com/hmans/beans/pkg/config"
"github.com/spf13/cobra"
)

//go:embed prompt.tmpl
Expand All @@ -26,20 +25,6 @@ var primeCmd = &cobra.Command{
Long: `Outputs a prompt that primes AI coding agents on how to use the beans CLI to manage project issues.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// If no explicit path given, check if a beans project exists by searching
// upward for a .beans.yml config file
if beansPath == "" && configPath == "" {
cwd, err := os.Getwd()
if err != nil {
return nil // Silently exit on error
}
configFile, err := config.FindConfig(cwd)
if err != nil || configFile == "" {
// No config file found - silently exit
return nil
}
}

tmpl, err := template.New("prompt").Parse(agentPromptTemplate)
if err != nil {
return err
Expand All @@ -52,7 +37,7 @@ var primeCmd = &cobra.Command{
Priorities: config.DefaultPriorities,
}

return tmpl.Execute(os.Stdout, data)
return tmpl.Execute(cmd.OutOrStdout(), data)
},
}

Expand Down
45 changes: 45 additions & 0 deletions internal/commands/prime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package commands

import (
"bytes"
"os"
"strings"
"testing"
)

func TestPrimeOutputsPromptWithoutBeansProject(t *testing.T) {
oldBeansPath, oldConfigPath := beansPath, configPath
beansPath, configPath = "", ""
t.Cleanup(func() {
beansPath, configPath = oldBeansPath, oldConfigPath
})

oldCwd, err := os.Getwd()
if err != nil {
t.Fatalf("Getwd() error = %v", err)
}

tmpDir := t.TempDir()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Chdir(%q) error = %v", tmpDir, err)
}
t.Cleanup(func() {
_ = os.Chdir(oldCwd)
})

cmd := *primeCmd
var stdout bytes.Buffer
cmd.SetOut(&stdout)

if err := cmd.RunE(&cmd, nil); err != nil {
t.Fatalf("prime RunE() error = %v", err)
}

if stdout.Len() == 0 {
t.Fatal("expected prime to write prompt output, got empty output")
}

if !strings.Contains(stdout.String(), "# Beans Usage Guide for Agents") {
t.Fatalf("expected prompt heading in output, got %q", stdout.String())
}
}