Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
# gitmoot-dashboard

Read-only web backend for the [gitmoot](https://github.com/jerryfane/gitmoot)
orchestration dashboard. It serves a live orchestration-DAG UI and streams run
state from gitmoot's store.
dashboard. It serves the embedded dashboard UI and a JSON API over gitmoot's
store.

This is a small Go module (stdlib only, no third-party dependencies). The React
UI lives under `web/` and is built into `web/dist`, which is embedded into the
binary; a minimal placeholder ships until the UI lands.
This is a small Go module (stdlib only, no third-party dependencies). The UI
lives in `web/dist` and is embedded into the binary.

## Contract

The package exposes a frozen `DataSource` interface and an HTTP `Serve` entry
point (see `datasource.go`):
The package exposes a `DataSource` interface (plus optional extensions such as
`WorkflowDataSource`, `OverviewDataSource`, `TasksDataSource`,
`OrgDataSource` and `ChangeCursorDataSource`) and an HTTP `Serve` entry point;
see `datasource.go`.

```go
type DataSource interface {
Runs(ctx context.Context) ([]RunSummary, error)
State(ctx context.Context, runID string) (State, error) // runID "" => active/most-recent
Job(ctx context.Context, jobID string) (Node, error)
Subscribe(ctx context.Context, runID string) (<-chan State, func(), error) // for SSE
}

func Serve(ds DataSource) http.Handler
```

HTTP surface:

| Route | Returns |
| ----------------------- | ------------------------------------ |
| `GET /api/runs` | `[]RunSummary` |
| `GET /api/state?run=<id>` | `State` |
| `GET /api/job/{id}` | `Node` |
| `GET /events?run=<id>` | SSE stream of `State` |
| everything else | embedded static UI (SPA fallback) |
| Route | Returns |
| --- | --- |
| `GET /api/overview` | `Overview` |
| `GET /api/tasks` | `[]TaskSummary` |
| `GET /api/workflows`, `GET /api/workflow/{label}` | `[]WorkflowIndexEntry`, `WorkflowView` |
| `GET /api/jobs`, `GET /api/job/{id}` | `[]JobSummary`, `Node` |
| `GET /api/job/{id}/checks` | `JobChecks` |
| `GET /api/agents`, `GET /api/agent/{name}` | `[]AgentSummary`, `AgentDetail` |
| `GET /api/org`, `GET /api/org/role/{name}` | `OrgView`, `OrgRoleView` |
| `GET /api/graph?repo=` | `Graph` (Galaxy) |
| `GET /api/charts?days=` | `Charts` |
| `GET /api/health` | `Health` |
| `GET /api/config` | `ConfigSnapshot` |
| `GET /api/attention` | `Attention` |
| `GET /api/events` | SSE change pings (`event: changed`) |
| other `/api/...` paths and `/events` | 404 |
| everything else | embedded static UI (SPA fallback) |

The server is **read-only** and must never run in the gitmoot daemon path.

Expand Down
67 changes: 6 additions & 61 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func writeJSON(w http.ResponseWriter, code int, v any) {
// statusForError maps a DataSource error to an HTTP status code: not-found
// sentinels become 404, everything else 500.
func statusForError(err error) int {
if errors.Is(err, ErrRunNotFound) || errors.Is(err, ErrJobNotFound) || errors.Is(err, ErrAgentNotFound) || errors.Is(err, ErrOrgRoleNotFound) || errors.Is(err, ErrWorkflowNotFound) {
if errors.Is(err, ErrJobNotFound) || errors.Is(err, ErrAgentNotFound) || errors.Is(err, ErrOrgRoleNotFound) || errors.Is(err, ErrWorkflowNotFound) {
return http.StatusNotFound
}
return http.StatusInternalServerError
Expand Down Expand Up @@ -531,21 +531,8 @@ func (s *server) handleWorkflow(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, view)
}

// handleRuns serves GET /api/runs -> []RunSummary.
func (s *server) handleRuns(w http.ResponseWriter, r *http.Request) {
runs, err := s.ds.Runs(r.Context())
if err != nil {
http.Error(w, err.Error(), statusForError(err))
return
}
if runs == nil {
runs = []RunSummary{}
}
writeJSON(w, http.StatusOK, runs)
}

// handleJobs serves GET /api/jobs -> []JobSummary, every job across all runs
// (the client filters). Mirrors handleRuns.
// (the client filters).
func (s *server) handleJobs(w http.ResponseWriter, r *http.Request) {
jobs, err := s.ds.Jobs(r.Context())
if err != nil {
Expand All @@ -558,7 +545,7 @@ func (s *server) handleJobs(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, jobs)
}

// handleAgents serves GET /api/agents -> []AgentSummary. Mirrors handleRuns.
// handleAgents serves GET /api/agents -> []AgentSummary.
func (s *server) handleAgents(w http.ResponseWriter, r *http.Request) {
agents, err := s.ds.Agents(r.Context())
if err != nil {
Expand All @@ -584,15 +571,11 @@ func (s *server) handleAgent(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), statusForError(err))
return
}
if detail.Versions == nil {
detail.Versions = []TemplateVersionInfo{}
}
writeJSON(w, http.StatusOK, detail)
}

// handleCharts serves GET /api/charts?days=N -> Charts. days accepts only 0
// (all history), 7, 30 or 90; any missing/invalid/other value defaults to 30.
// Mirrors handleRuns.
func (s *server) handleCharts(w http.ResponseWriter, r *http.Request) {
days := 30
switch r.URL.Query().Get("days") {
Expand Down Expand Up @@ -622,16 +605,13 @@ func (s *server) handleCharts(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, charts)
}

// handleHealth serves GET /api/health -> Health. Mirrors handleRuns.
// handleHealth serves GET /api/health -> Health.
func (s *server) handleHealth(w http.ResponseWriter, r *http.Request) {
h, err := s.ds.Health(r.Context())
if err != nil {
http.Error(w, err.Error(), statusForError(err))
return
}
if h.Locks == nil {
h.Locks = []HealthLock{}
}
if h.ResourceLocks == nil {
h.ResourceLocks = []HealthResourceLock{}
}
Expand Down Expand Up @@ -680,32 +660,9 @@ func (s *server) handleConfig(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, c)
}

// handleLearningSkills serves GET /api/learning/skills -> Skills, the SkillOpt
// evolution overview. Mirrors handleRuns; every list is coerced non-nil so the
// client always sees JSON arrays.
func (s *server) handleLearningSkills(w http.ResponseWriter, r *http.Request) {
skills, err := s.ds.Skills(r.Context())
if err != nil {
http.Error(w, err.Error(), statusForError(err))
return
}
if skills.Templates == nil {
skills.Templates = []SkillTemplate{}
}
for i := range skills.Templates {
if skills.Templates[i].Versions == nil {
skills.Templates[i].Versions = []SkillVersion{}
}
if skills.Templates[i].Pending == nil {
skills.Templates[i].Pending = []SkillCandidate{}
}
}
writeJSON(w, http.StatusOK, skills)
}

// handleAttention serves GET /api/attention -> Attention, the "Needs a human"
// view (gitmoot #528). Mirrors handleRuns; Gates is coerced non-nil so the
// client always sees a JSON array.
// view (gitmoot #528). Gates is coerced non-nil so the client always sees a
// JSON array.
func (s *server) handleAttention(w http.ResponseWriter, r *http.Request) {
att, err := s.ds.Attention(r.Context())
if err != nil {
Expand Down Expand Up @@ -738,18 +695,6 @@ func (s *server) handleJobChecks(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, checks)
}

// handleState serves GET /api/state?run=<id> -> State. An empty run resolves to
// the active/most-recent run.
func (s *server) handleState(w http.ResponseWriter, r *http.Request) {
run := r.URL.Query().Get("run")
state, err := s.ds.State(r.Context(), run)
if err != nil {
http.Error(w, err.Error(), statusForError(err))
return
}
writeJSON(w, http.StatusOK, state)
}

// handleJob serves GET /api/job/{id} -> Node.
func (s *server) handleJob(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
Expand Down
Loading
Loading