Unify auth middleware and remove X-User-ID trust, add project_members authorization, sandbox workspaces via resolver, and admin-only reconcile by run_id. Introduce goose migrations with startup schema gate, fail closed when DB unavailable outside explicit ALLOW_IN_MEMORY, bundle web/dist in app Dockerfile, and remove frontend pseudo-login fallback.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"chat-agent-system/internal/squad"
|
|
)
|
|
|
|
func (s *Server) handleReconcileWorkspace(w http.ResponseWriter, r *http.Request) {
|
|
if _, ok := s.requireAdmin(w, r); !ok {
|
|
return
|
|
}
|
|
|
|
var body struct {
|
|
RunID string `json:"run_id"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
http.Error(w, "invalid body", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if body.RunID == "" {
|
|
http.Error(w, "run_id required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
rec, err := s.taskRuns.GetRun(body.RunID)
|
|
if err != nil {
|
|
http.Error(w, "run not found", http.StatusNotFound)
|
|
return
|
|
}
|
|
if rec.WorkspaceID == "" {
|
|
http.Error(w, "workspace not available for run", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
workDir, err := s.resolver.ResolveStoredWorkDir(rec.WorkspaceID)
|
|
if err != nil {
|
|
http.Error(w, "invalid workspace path", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
report, err := squad.ReconcileWorkspaceStatus(workDir)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSONResponse(w, http.StatusOK, report)
|
|
}
|