summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-13 05:27:58 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-13 05:27:58 +0000
commitc602ddd799d94bf3bbd35a57b98ad09e28df8ee9 (patch)
tree5914af5ce59b677723bf580cc16e879315e6e1d4 /internal/api
parent2c30cd37a1631bea97afa456ba8ed3c8efc16d80 (diff)
fix: only write RAW_NARRATIVE.md when user explicitly provides project_dir
Previously appendRawNarrative was called with the server's default workDir (os.Getwd()) when no project_dir was in the request, causing test runs and any elaboration without a project to pollute the repo's own RAW_NARRATIVE.md. The narrative is per-project human input — only write it when the caller explicitly specifies which project they're working in. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/elaborate.go8
-rw-r--r--internal/api/elaborate_test.go32
2 files changed, 38 insertions, 2 deletions
diff --git a/internal/api/elaborate.go b/internal/api/elaborate.go
index c6d08f4..5df772e 100644
--- a/internal/api/elaborate.go
+++ b/internal/api/elaborate.go
@@ -216,8 +216,12 @@ func (s *Server) handleElaborateTask(w http.ResponseWriter, r *http.Request) {
workDir = input.ProjectDir
}
- // Append verbatim user input to RAW_NARRATIVE.md in the background (best effort).
- go s.appendRawNarrative(workDir, input.Prompt)
+ // Append verbatim user input to RAW_NARRATIVE.md only when the user explicitly
+ // provided a project_dir — the narrative is per-project human input, not a
+ // server-level log.
+ if input.ProjectDir != "" {
+ go s.appendRawNarrative(workDir, input.Prompt)
+ }
projectContext := readProjectContext(workDir)
fullPrompt := input.Prompt
diff --git a/internal/api/elaborate_test.go b/internal/api/elaborate_test.go
index 9ae2e98..0b5c706 100644
--- a/internal/api/elaborate_test.go
+++ b/internal/api/elaborate_test.go
@@ -440,6 +440,38 @@ func TestElaborateTask_WithProjectContext(t *testing.T) {
}
}
+func TestElaborateTask_NoRawNarrativeWithoutExplicitProjectDir(t *testing.T) {
+ srv, _ := testServer(t)
+ // Point workDir at a temp dir so any accidental write is detectable.
+ srv.workDir = t.TempDir()
+
+ task := elaboratedTask{
+ Name: "Task",
+ Agent: elaboratedAgent{Instructions: "Instructions"},
+ }
+ taskJSON, _ := json.Marshal(task)
+ wrapper := map[string]string{"result": string(taskJSON)}
+ wrapperJSON, _ := json.Marshal(wrapper)
+ srv.elaborateCmdPath = createFakeClaude(t, string(wrapperJSON), 0)
+
+ // No project_dir in request body.
+ body := `{"prompt":"do something"}`
+ req := httptest.NewRequest("POST", "/api/tasks/elaborate", bytes.NewBufferString(body))
+ req.Header.Set("Content-Type", "application/json")
+ w := httptest.NewRecorder()
+ srv.Handler().ServeHTTP(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status: want 200, got %d", w.Code)
+ }
+
+ time.Sleep(30 * time.Millisecond) // let goroutine run if it was incorrectly triggered
+ narrativePath := filepath.Join(srv.workDir, "docs", "RAW_NARRATIVE.md")
+ if _, err := os.Stat(narrativePath); err == nil {
+ t.Errorf("RAW_NARRATIVE.md should NOT be written when project_dir is not provided by the user")
+ }
+}
+
func TestElaborateTask_AppendsRawNarrative(t *testing.T) {
srv, _ := testServer(t)