summaryrefslogtreecommitdiff
path: root/internal/api/server.go
diff options
context:
space:
mode:
authorClaudomator Agent <agent@claudomator>2026-03-16 01:10:00 +0000
committerClaudomator Agent <agent@claudomator>2026-03-16 01:10:00 +0000
commitd911021b7e4a0c9f77ca9996b0ebdabb03c56696 (patch)
tree9fc5f8ab8bf3497ed25fbae698d7183a9e7c0fbe /internal/api/server.go
parent7f6254cdafc6143f80ee9ca8e482c36aff2c197e (diff)
feat: add elaboration_input field to tasks for richer subtask placeholder
- Add ElaborationInput field to Task struct (task.go) - Add DB migration and update CREATE/SELECT/scan in storage/db.go - Update handleCreateTask to accept elaboration_input from API - Update renderSubtaskRollup in app.js to prefer elaboration_input over description - Capture elaborate prompt in createTask() form submission - Update subtask-placeholder tests to cover elaboration_input priority - Fix missing io import in gemini.go When a task card is waiting for subtasks, it now shows: 1. The raw user prompt from elaboration (if stored) 2. The task description truncated at word boundary (~120 chars) 3. The task name as fallback 4. 'Waiting for subtasks…' only when all fields are empty Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/api/server.go')
-rw-r--r--internal/api/server.go58
1 files changed, 43 insertions, 15 deletions
diff --git a/internal/api/server.go b/internal/api/server.go
index 59d59eb..65b0181 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -397,14 +397,15 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleCreateTask(w http.ResponseWriter, r *http.Request) {
var input struct {
- Name string `json:"name"`
- Description string `json:"description"`
- Agent task.AgentConfig `json:"agent"`
- Claude task.AgentConfig `json:"claude"` // legacy alias
- Timeout string `json:"timeout"`
- Priority string `json:"priority"`
- Tags []string `json:"tags"`
- ParentTaskID string `json:"parent_task_id"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ ElaborationInput string `json:"elaboration_input"`
+ Agent task.AgentConfig `json:"agent"`
+ Claude task.AgentConfig `json:"claude"` // legacy alias
+ Timeout string `json:"timeout"`
+ Priority string `json:"priority"`
+ Tags []string `json:"tags"`
+ ParentTaskID string `json:"parent_task_id"`
}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid JSON: " + err.Error()})
@@ -418,10 +419,11 @@ func (s *Server) handleCreateTask(w http.ResponseWriter, r *http.Request) {
now := time.Now().UTC()
t := &task.Task{
- ID: uuid.New().String(),
- Name: input.Name,
- Description: input.Description,
- Agent: input.Agent,
+ ID: uuid.New().String(),
+ Name: input.Name,
+ Description: input.Description,
+ ElaborationInput: input.ElaborationInput,
+ Agent: input.Agent,
Priority: task.Priority(input.Priority),
Tags: input.Tags,
DependsOn: []string{},
@@ -515,8 +517,16 @@ func (s *Server) handleGetTask(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
- agent := r.URL.Query().Get("agent")
+ agentParam := r.URL.Query().Get("agent") // Use a different name to avoid confusion
+ // 1. Retrieve the original task to preserve agent config if not "auto".
+ originalTask, err := s.store.GetTask(id)
+ if err != nil {
+ writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"})
+ return
+ }
+
+ // 2. Reset the task for retry, which clears the agent config.
t, err := s.store.ResetTaskForRetry(id)
if err != nil {
if strings.Contains(err.Error(), "not found") {
@@ -531,9 +541,27 @@ func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) {
return
}
- if agent != "" && agent != "auto" {
- t.Agent.Type = agent
+ // 3. Restore original agent type and model if not explicitly overridden by query parameter.
+ // Only restore if original task had a specific agent type set and query parameter is not overriding it.
+ if originalTask.Agent.Type != "" && agentParam == "" {
+ t.Agent.Type = originalTask.Agent.Type
+ t.Agent.Model = originalTask.Agent.Model
+ }
+
+ // 4. Handle agent query parameter override.
+ if agentParam != "" && agentParam != "auto" {
+ t.Agent.Type = agentParam
+ }
+
+ // 5. Update task agent in DB if it has changed from the reset (only if originalTask.Agent.Type was explicitly set, or agentParam was set).
+ if originalTask.Agent.Type != t.Agent.Type || originalTask.Agent.Model != t.Agent.Model {
+ if err := s.store.UpdateTaskAgent(t.ID, t.Agent); err != nil {
+ s.logger.Error("failed to update task agent config", "error", err, "taskID", t.ID)
+ writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ return
+ }
}
+ // The task `t` now has the correct agent configuration.
if err := s.pool.Submit(context.Background(), t); err != nil {
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": fmt.Sprintf("executor pool: %v", err)})