rdev/internal/handlers/sdlc_orchestrator.go
jordan f22b220c6d feat: add SDLC branch management, merge, archive, and orchestrator APIs
Add branch lifecycle commands (branch, merge, archive) to the SDLC CLI.
Introduce orchestrator handler and service for multi-step SDLC workflows.
Expand skeleton template with 15 Claude commands covering the full feature
lifecycle. Extend classifier rules, error types, and executor port for
branch operations. Split rules.go and classifier_test.go to stay within
500-line limit.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 12:30:03 -07:00

122 lines
3.0 KiB
Go

package handlers
import (
"context"
"log/slog"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/orchard9/rdev/internal/service"
"github.com/orchard9/rdev/pkg/api"
)
// SDLCOrchestratorHandler handles SDLC orchestration endpoints.
type SDLCOrchestratorHandler struct {
orchestrator *service.SDLCOrchestratorService
logger *slog.Logger
}
// NewSDLCOrchestratorHandler creates a new orchestrator handler.
func NewSDLCOrchestratorHandler(orchestrator *service.SDLCOrchestratorService, logger *slog.Logger) *SDLCOrchestratorHandler {
if logger == nil {
logger = slog.Default()
}
return &SDLCOrchestratorHandler{
orchestrator: orchestrator,
logger: logger,
}
}
// Mount registers orchestration routes under /projects/{id}/sdlc/.
func (h *SDLCOrchestratorHandler) Mount(r api.Router) {
r.Route("/projects/{id}/sdlc", func(r chi.Router) {
r.Post("/execute", h.Execute)
r.Post("/resolve", h.Resolve)
r.Post("/commit", h.Commit)
})
}
// Execute runs the next classifier-recommended action.
// POST /projects/{id}/sdlc/execute
func (h *SDLCOrchestratorHandler) Execute(w http.ResponseWriter, r *http.Request) {
projectID := chi.URLParam(r, "id")
var req service.ExecuteRequest
if err := api.DecodeJSON(r, &req); err != nil {
api.WriteBadRequest(w, r, "invalid request body")
return
}
if req.Feature == "" {
api.WriteBadRequest(w, r, "feature is required")
return
}
ctx, cancel := context.WithTimeout(r.Context(), TimeoutLongRunning)
defer cancel()
result, err := h.orchestrator.ExecuteAction(ctx, projectID, &req)
if err != nil {
writeSDLCError(w, r, err)
return
}
api.WriteSuccess(w, r, result)
}
// Resolve unblocks a feature and re-classifies.
// POST /projects/{id}/sdlc/resolve
func (h *SDLCOrchestratorHandler) Resolve(w http.ResponseWriter, r *http.Request) {
projectID := chi.URLParam(r, "id")
var req service.ResolveRequest
if err := api.DecodeJSON(r, &req); err != nil {
api.WriteBadRequest(w, r, "invalid request body")
return
}
if req.Feature == "" {
api.WriteBadRequest(w, r, "feature is required")
return
}
ctx, cancel := context.WithTimeout(r.Context(), TimeoutStandard)
defer cancel()
result, err := h.orchestrator.ResolveBlocker(ctx, projectID, &req)
if err != nil {
writeSDLCError(w, r, err)
return
}
api.WriteSuccess(w, r, result)
}
// Commit commits changes in the project pod.
// POST /projects/{id}/sdlc/commit
func (h *SDLCOrchestratorHandler) Commit(w http.ResponseWriter, r *http.Request) {
projectID := chi.URLParam(r, "id")
var req service.CommitRequest
if err := api.DecodeJSON(r, &req); err != nil {
api.WriteBadRequest(w, r, "invalid request body")
return
}
if req.Message == "" {
api.WriteBadRequest(w, r, "message is required")
return
}
ctx, cancel := context.WithTimeout(r.Context(), TimeoutHeavyWrite)
defer cancel()
result, err := h.orchestrator.CommitChanges(ctx, projectID, &req)
if err != nil {
writeSDLCError(w, r, err)
return
}
api.WriteSuccess(w, r, result)
}