diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-14 00:39:22 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-14 00:39:22 +0000 |
| commit | 2ee988ccc04c09ceb6de7cdb75c94114e85d01b9 (patch) | |
| tree | 29100e3e4b33748c544b9a42cb74e964df49b96e /internal/api | |
| parent | 98ccde12b08ad0b7f53e42de959a72d8382179e3 (diff) | |
feat: add agent selector to UI and support direct agent assignment
- Added an agent selector (Auto, Claude, Gemini) to the Start Next Task button.
- Updated the backend to pass query parameters as environment variables to scripts.
- Modified the executor pool to skip classification when a specific agent is requested.
- Added --agent flag to claudomator start command.
- Updated tests to cover the new functionality.
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/scripts.go | 8 | ||||
| -rw-r--r-- | internal/api/server.go | 7 | ||||
| -rw-r--r-- | internal/api/server_test.go | 17 |
3 files changed, 31 insertions, 1 deletions
diff --git a/internal/api/scripts.go b/internal/api/scripts.go index 822bd32..8db937b 100644 --- a/internal/api/scripts.go +++ b/internal/api/scripts.go @@ -4,7 +4,9 @@ import ( "bytes" "context" "net/http" + "os" "os/exec" + "strings" "time" ) @@ -33,6 +35,12 @@ func (s *Server) handleScript(w http.ResponseWriter, r *http.Request) { defer cancel() cmd := exec.CommandContext(ctx, scriptPath) + cmd.Env = os.Environ() + for k, v := range r.URL.Query() { + if len(v) > 0 { + cmd.Env = append(cmd.Env, "CLAUDOMATOR_"+strings.ToUpper(k)+"="+v[0]) + } + } var stdout, stderr bytes.Buffer cmd.Stdout = &stdout diff --git a/internal/api/server.go b/internal/api/server.go index df35536..163f2b8 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -488,9 +488,10 @@ func (s *Server) handleGetTask(w http.ResponseWriter, r *http.Request) { } writeJSON(w, http.StatusOK, t) } - func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") + agent := r.URL.Query().Get("agent") + t, err := s.store.ResetTaskForRetry(id) if err != nil { if strings.Contains(err.Error(), "not found") { @@ -505,6 +506,10 @@ func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) { return } + if agent != "" && agent != "auto" { + t.Agent.Type = agent + } + if err := s.pool.Submit(context.Background(), t); err != nil { writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": fmt.Sprintf("executor pool: %v", err)}) return diff --git a/internal/api/server_test.go b/internal/api/server_test.go index c90e3b3..2209a69 100644 --- a/internal/api/server_test.go +++ b/internal/api/server_test.go @@ -384,6 +384,23 @@ func TestRunTask_TimedOutTask_Returns202(t *testing.T) { } } +func TestRunTask_WithAgentParam(t *testing.T) { + srv, store := testServer(t) + createTaskWithState(t, store, "run-agent-param", task.StatePending) + + // Request run with agent=gemini. + req := httptest.NewRequest("POST", "/api/tasks/run-agent-param/run?agent=gemini", nil) + w := httptest.NewRecorder() + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusAccepted { + t.Fatalf("status: want 202, got %d; body: %s", w.Code, w.Body.String()) + } + + // Wait for the task to complete via the mock runner. + pollState(t, store, "run-agent-param", task.StateReady, 2*time.Second) +} + func TestRunTask_CompletedTask_Returns409(t *testing.T) { srv, store := testServer(t) createTaskWithState(t, store, "run-completed", task.StateCompleted) |
