diff --git a/main.go b/main.go index 58e4279..5fbfc04 100644 --- a/main.go +++ b/main.go @@ -166,12 +166,7 @@ func main() { fmt.Println("---") } - // Output all rules - for _, rule := range result.Rules { - fmt.Println(rule.Content) - } - - // Output task - fmt.Println(result.Task.Content) + // Output the combined prompt (rules + task) + fmt.Println(result.Prompt) } } diff --git a/pkg/codingcontext/context.go b/pkg/codingcontext/context.go index 84dd591..46286fb 100644 --- a/pkg/codingcontext/context.go +++ b/pkg/codingcontext/context.go @@ -328,12 +328,21 @@ func (cc *Context) Run(ctx context.Context, taskName string) (*Result, error) { // Estimate tokens for task cc.logger.Info("Total estimated tokens", "tokens", cc.totalTokens) + // Build the combined prompt from all rules and task content + var promptBuilder strings.Builder + for _, rule := range cc.rules { + promptBuilder.WriteString(rule.Content) + promptBuilder.WriteString("\n") + } + promptBuilder.WriteString(cc.task.Content) + // Build and return the result result := &Result{ Rules: cc.rules, Task: cc.task, Tokens: cc.totalTokens, Agent: cc.agent, + Prompt: promptBuilder.String(), } return result, nil diff --git a/pkg/codingcontext/result.go b/pkg/codingcontext/result.go index af5433b..e4bd923 100644 --- a/pkg/codingcontext/result.go +++ b/pkg/codingcontext/result.go @@ -11,6 +11,7 @@ type Result struct { Task markdown.Markdown[markdown.TaskFrontMatter] // Task file with frontmatter and content Tokens int // Total token count Agent Agent // The agent used (from task or -a flag) + Prompt string // Combined prompt: all rules and task content } // MCPServers returns all MCP server configurations from rules. diff --git a/pkg/codingcontext/result_test.go b/pkg/codingcontext/result_test.go index 65a6891..88a0041 100644 --- a/pkg/codingcontext/result_test.go +++ b/pkg/codingcontext/result_test.go @@ -1,12 +1,73 @@ package codingcontext import ( + "context" + "log/slog" + "os" "testing" "github.com/kitproj/coding-context-cli/pkg/codingcontext/markdown" "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" ) +func TestResult_Prompt(t *testing.T) { + tests := []struct { + name string + setup func(t *testing.T, dir string) + taskName string + want string + }{ + { + name: "task only without rules", + setup: func(t *testing.T, dir string) { + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") + }, + taskName: "test-task", + want: "Task content\n", + }, + { + name: "single rule and task", + setup: func(t *testing.T, dir string) { + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") + createRule(t, dir, ".agents/rules/rule1.md", "", "Rule 1 content\n") + }, + taskName: "test-task", + want: "Rule 1 content\n\nTask content\n", + }, + { + name: "multiple rules and task", + setup: func(t *testing.T, dir string) { + createTask(t, dir, "test-task", "task_name: test-task", "Task content\n") + createRule(t, dir, ".agents/rules/rule1.md", "", "Rule 1 content\n") + createRule(t, dir, ".agents/rules/rule2.md", "", "Rule 2 content\n") + }, + taskName: "test-task", + want: "Rule 1 content\n\nRule 2 content\n\nTask content\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tmpDir := t.TempDir() + tt.setup(t, tmpDir) + + ctx := New( + WithSearchPaths("file://"+tmpDir), + WithLogger(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError}))), + ) + + result, err := ctx.Run(context.Background(), tt.taskName) + if err != nil { + t.Fatalf("Run() error = %v", err) + } + + if result.Prompt != tt.want { + t.Errorf("Result.Prompt = %q, want %q", result.Prompt, tt.want) + } + }) + } +} + func TestResult_MCPServers(t *testing.T) { tests := []struct { name string