diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-10 09:09:32 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-10 09:29:02 +0000 |
| commit | 63ccc3380df10cab066e08b40ea41ee1b51bb651 (patch) | |
| tree | 1cab595d980ead075bd79bc10789be423f132088 /internal/api/elaborate.go | |
| parent | 0676f0f2e6d1ba371806ca4b808a4993027d86ea (diff) | |
feat: include project context in elaborator prompt
The elaborator now reads CLAUDE.md and SESSION_STATE.md from the project directory (if they exist) and prepends their content to the user prompt. This allows the AI to generate tasks that are more context-aware.
Diffstat (limited to 'internal/api/elaborate.go')
| -rw-r--r-- | internal/api/elaborate.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/internal/api/elaborate.go b/internal/api/elaborate.go index 2f6c707..5954e29 100644 --- a/internal/api/elaborate.go +++ b/internal/api/elaborate.go @@ -6,7 +6,9 @@ import ( "encoding/json" "fmt" "net/http" + "os" "os/exec" + "path/filepath" "strings" "time" ) @@ -86,6 +88,23 @@ func (s *Server) claudeBinaryPath() string { return "claude" } +func readProjectContext(workDir string) string { + if workDir == "" { + return "" + } + var sb strings.Builder + for _, filename := range []string{"CLAUDE.md", "SESSION_STATE.md"} { + path := filepath.Join(workDir, filename) + if data, err := os.ReadFile(path); err == nil { + if sb.Len() > 0 { + sb.WriteString("\n\n") + } + sb.WriteString(fmt.Sprintf("--- %s ---\n%s", filename, string(data))) + } + } + return sb.String() +} + func (s *Server) handleElaborateTask(w http.ResponseWriter, r *http.Request) { if s.elaborateLimiter != nil && !s.elaborateLimiter.allow(realIP(r)) { writeJSON(w, http.StatusTooManyRequests, map[string]string{"error": "rate limit exceeded"}) @@ -110,16 +129,23 @@ func (s *Server) handleElaborateTask(w http.ResponseWriter, r *http.Request) { workDir = input.ProjectDir } + projectContext := readProjectContext(workDir) + fullPrompt := input.Prompt + if projectContext != "" { + fullPrompt = fmt.Sprintf("Project context from %s:\n%s\n\nUser request: %s", workDir, projectContext, input.Prompt) + } + ctx, cancel := context.WithTimeout(r.Context(), elaborateTimeout) defer cancel() cmd := exec.CommandContext(ctx, s.claudeBinaryPath(), - "-p", input.Prompt, + "-p", fullPrompt, "--system-prompt", buildElaboratePrompt(workDir), "--output-format", "json", "--model", "haiku", ) + var stdout, stderr bytes.Buffer cmd.Stdout = &stdout cmd.Stderr = &stderr |
