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
1 change: 1 addition & 0 deletions changelog.d/added-workflow-enabled-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Settings → Workflows → Library gains an owner-only **Derive stages from bound models** switch (`workflow.enabled`, [#17620](https://github.com/hivecommons/hive/issues/17620)) backed by the new `PUT /api/workflows/enabled {enabled}`, so a hosted hive with no `hive.yaml` access can turn model-based stage derivation on or off from the dashboard. Off: a binding only changes the Activity Monitor's columns; on: a bound repository's stages are derived by its model's rules and the model's labels are provisioned in the repository immediately. Persists `hive.yaml`, takes effect on the next derivation pass without a restart, audited as `workflow_enabled` / `workflow_disabled`; the Repos binding row now says *columns only — turn on derivation in Workflows* when a repository is bound while the flag is off.
72 changes: 72 additions & 0 deletions dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -39362,6 +39362,78 @@
}
}
},
"/api/workflows/enabled": {
"put": {
"tags": [
"Workflows"
],
"summary": "Turn model-based stage derivation on or off",
"description": "Owner only. Sets workflow.enabled from the dashboard so a hosted hive with no hive.yaml access can enable it (hivecommons/hive#17620). Body {enabled}. Persists hive.yaml; the stage engine and the tracker read the live flag, so it takes effect on the next derivation pass without a restart. Turning it on also provisions every bound repository's model labels immediately; a repository that could not be provisioned is listed in warnings and the next sweep retries it. Audited as workflow_enabled / workflow_disabled; a no-op is not audited.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"enabled"
],
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Flag after the change",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"changed": {
"type": "boolean"
},
"bindings": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WorkflowBinding"
}
},
"warnings": {
"type": "array",
"items": {
"type": "string"
},
"description": "Bound repositories whose labels could not be provisioned now (only when turning on)"
}
}
}
}
}
},
"400": {
"description": "Body is not {enabled: boolean}"
},
"403": {
"description": "Not an owner"
},
"500": {
"description": "hive.yaml could not be saved; the flag is left unchanged"
},
"503": {
"description": "No config"
}
}
}
},
"/api/workflows/{name}/{version}": {
"get": {
"tags": [
Expand Down
11 changes: 6 additions & 5 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,12 @@ func (b *boot) wireBootClosures() {
WorkflowItemSnapshot: func(ctx context.Context, repo string, number int) (github.WorkflowItemSnapshot, error) {
return b.ghClient.WorkflowItemSnapshot(ctx, repo, number)
},
WorkflowRepoFile: workflowRepoFile(func() *github.Client { return b.ghClient }),
WorkflowClusterRunner: workflowClusterRunner(),
WorkflowSpecLLM: newWorkflowSpecRunner(func() *config.Config { return b.cfg }),
AgentMgr: b.agentMgr,
CruxRuntimeHealth: cruxRuntimeHealthFunc(b.cruxSupervision),
WorkflowRepoFile: workflowRepoFile(func() *github.Client { return b.ghClient }),
WorkflowProvisionLabels: workflowProvisionLabels(b.cfg, func() *github.Client { return b.ghClient }, b.logger),
WorkflowClusterRunner: workflowClusterRunner(),
WorkflowSpecLLM: newWorkflowSpecRunner(func() *config.Config { return b.cfg }),
AgentMgr: b.agentMgr,
CruxRuntimeHealth: cruxRuntimeHealthFunc(b.cruxSupervision),
// Provider gateways (#5565 slice 3): concrete openrouter/watsonx/
// linearagent adapters behind the dashboard's consumer-defined
// interfaces — this composition root is the only non-test place that
Expand Down
42 changes: 42 additions & 0 deletions src/cmd/hive/workflow_labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"
"fmt"
"log/slog"
"strings"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/github/automerge"
)

// workflowProvisionLabels is the dashboard's WorkflowProvisionLabels
// dependency (hivecommons/hive#17620): when an owner turns workflow.enabled
// on from Settings → Workflows, every bound repository's model labels are
// provisioned at once through the sweep's own memoised path
// (automerge.Engine.EnsureStageLabels over the process-shared stage engine
// options and tracker), rather than on the next PR that needs a label.
// Without a GitHub client the call reports an error and the handler
// surfaces it as a warning; the flag itself still flips.
func workflowProvisionLabels(cfg *config.Config, client func() *github.Client, logger *slog.Logger) func(ctx context.Context, repo string) error {
return func(ctx context.Context, repo string) error {
var gh *github.Client
if client != nil {
gh = client()
}
if gh == nil {
return errNoForgeClient
}
owner, name, ok := strings.Cut(config.QualifyRepo(cfg.Project.Org, repo), "/")
if !ok || owner == "" || name == "" {
return fmt.Errorf("repository %q is not owner/name", repo)
}
eng := automerge.New(gh, automerge.Options{
Logger: logger,
StageLabelPolicy: stageLabelPolicyFunc(cfg),
StageEngine: stageEngineOptions(cfg, logger),
})
return eng.EnsureStageLabels(ctx, owner, name)
}
}
28 changes: 28 additions & 0 deletions src/cmd/hive/workflow_labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"context"
"errors"
"strings"
"testing"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/github"
)

func TestWorkflowProvisionLabelsWithoutClient(t *testing.T) {
cfg := &config.Config{Project: config.ProjectConfig{Org: "acme"}}
provision := workflowProvisionLabels(cfg, func() *github.Client { return nil }, nil)
if err := provision(context.Background(), "widgets"); !errors.Is(err, errNoForgeClient) {
t.Fatalf("err = %v", err)
}
}

func TestWorkflowProvisionLabelsRejectsBareRepoWithoutOrg(t *testing.T) {
cfg := &config.Config{}
provision := workflowProvisionLabels(cfg, func() *github.Client { return &github.Client{} }, nil)
err := provision(context.Background(), "widgets")
if err == nil || !strings.Contains(err.Error(), "owner/name") {
t.Fatalf("err = %v", err)
}
}
2 changes: 1 addition & 1 deletion src/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ History point limits, timestamp cutoffs, incremental cost reads and ETag/304 beh
| Health, status, events | [`api-reference/health-status-events.md`](api-reference/health-status-events.md) | 50 |
| Snapshots and style | [`api-reference/snapshots-and-style.md`](api-reference/snapshots-and-style.md) | 5 |
| Auth and external accounts | [`api-reference/auth.md`](api-reference/auth.md) | 22 |
| Configuration | [`api-reference/configuration.md`](api-reference/configuration.md) | 105 |
| Configuration | [`api-reference/configuration.md`](api-reference/configuration.md) | 110 |
| Agents and controls | [`api-reference/agents-and-controls.md`](api-reference/agents-and-controls.md) | 36 |
| Packs and ACMM | [`api-reference/packs-and-acmm.md`](api-reference/packs-and-acmm.md) | 18 |
| Cost, tokens, telemetry | [`api-reference/cost-tokens-telemetry.md`](api-reference/cost-tokens-telemetry.md) | 13 |
Expand Down
14 changes: 14 additions & 0 deletions src/docs/api-reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| `PUT` | `/api/config/governor/project-observability` | Owner only | Governor Project Observability Set | `pkg/dashboard/api.go:300` |
| `GET` | `/api/config/governor/inference-auth` | Owner only | Governor Inference Auth Get | `pkg/dashboard/api.go:315` |
| `PUT` | `/api/config/governor/inference-auth` | Owner only | Governor Inference Auth Set | `pkg/dashboard/api.go:316` |
| `GET` | `/api/config/convergence` | Owner only | Convergence Config Get | `pkg/dashboard/api.go:276` |
| `PUT` | `/api/config/convergence` | Owner only | Convergence Config Set | `pkg/dashboard/api.go:278` |
| `GET` | `/api/config/governor/advisory` | Owner only | Governor Advisory Get | `pkg/dashboard/api.go:282` |
| `PUT` | `/api/config/governor/advisory` | Owner only | Governor Advisory Set | `pkg/dashboard/api.go:283` |
| `GET` | `/api/config/governor/replan` | Owner only | Governor Replan Get | `pkg/dashboard/api.go:284` |
| `PUT` | `/api/config/governor/replan` | Owner only | Governor Replan Set | `pkg/dashboard/api.go:285` |
| `GET` | `/api/config/governor/work-source` | Owner only | Governor Work Source Get (Jira secrets/TLS fields reported as set/unset only) | `pkg/dashboard/api.go:295` |
| `PUT` | `/api/config/governor/work-source` | Owner only | Governor Work Source Set (including Jira Data Center TLS settings) | `pkg/dashboard/api.go:296` |
| `PUT` | `/api/config/governor/security` | Owner only | Governor Security | `pkg/dashboard/api.go:297` |
| `GET` | `/api/config/governor/project-observability` | Owner only | Governor Project Observability Get | `pkg/dashboard/api.go:299` |
| `PUT` | `/api/config/governor/project-observability` | Owner only | Governor Project Observability Set | `pkg/dashboard/api.go:300` |
| `GET` | `/api/config/governor/inference-auth` | Owner only | Governor Inference Auth Get | `pkg/dashboard/api.go:315` |
| `PUT` | `/api/config/governor/inference-auth` | Owner only | Governor Inference Auth Set | `pkg/dashboard/api.go:316` |
| `PUT` | `/api/workflows/enabled` | Owner only | Turn model-based stage derivation (`workflow.enabled`, [#17620](https://github.com/hivecommons/hive/issues/17620)) on or off from the dashboard, for hosted hives with no `hive.yaml` access. Body `{enabled: bool}`; persists `hive.yaml`; the stage engine and tracker read the live flag so it applies on the next derivation pass without a restart. Turning on also provisions every bound repository's model labels now (`warnings[]` lists repositories that could not be provisioned; the next sweep retries). Returns `{enabled, changed, bindings[], warnings?[]}`. Audited `workflow_enabled` / `workflow_disabled`; `400` on a non-boolean body | `pkg/dashboard/api_workflows.go:28` |
16 changes: 16 additions & 0 deletions src/docs/design/workflow-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ and `GET /api/workflows/{name}/{version}`:
Duplicate (saves a copy under a new name at version 1, provenance `local`) and Delete; Delete is
withheld while anything is bound (the API returns 409 anyway) and the row says `bound` instead.
Export shows the model JSON in-app (copy to clipboard) for everyone.
- **Derivation switch** — the Library header carries an owner-only toggle, *Derive stages from
bound models* (`renderWorkflowEnabledToggle`, `PUT /api/workflows/enabled {enabled}`), so a
hosted hive with no `hive.yaml` access can turn `workflow.enabled` on or off. Off: a binding
only changes the Activity Monitor's columns. On: a bound repository's stages are derived by its
model's rules and the model's labels are provisioned. Turning on asks for confirmation (it
changes derivation for every bound repository and creates labels in them); turning off is
immediate. The handler sets `Config.Workflow.Enabled`, saves `hive.yaml`, audits
`workflow_enabled` / `workflow_disabled`, and — on the way on — calls
`Dependencies.WorkflowProvisionLabels` for each binding (cmd/hive wires it to
`automerge.Engine.EnsureStageLabels`, the sweep's memoised `ensureStageLabels` path over the
shared stage-engine options and tracker), so the bound models' labels exist at once rather than
on the next PR that needs a label write; a repository that fails is returned in `warnings[]`
and the next sweep retries. No reload hook is needed: `stageEngineWorkflowFor` and the tracker
read `cfg.Workflow.Enabled` on every call, and the hive.yaml reloader mutates the same
`*Config` in place. The Repos binding row shows *columns only — turn on derivation in
Workflows* when a binding exists while the flag is off.
- **Detail** — facts, the diagram, diagnostics, citations and the raw model/profile JSON.
`workflowDiagramSvg(model, profile)` is a pure function: the compiled profile's columns are lanes
in display order, each state is a chip carrying its padded stage number, transitions are bezier
Expand Down
11 changes: 11 additions & 0 deletions src/hive.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -1511,3 +1511,14 @@ nous:
# role: experimenter
# engine: nous
# interval: 24h

# Workflow models (hivecommons/hive#17620, docs/design/workflow-models.md).
# Repositories are bound to a model on Settings → Repos (project.workflow_bindings).
# A binding always changes the Activity Monitor's columns for that repository;
# `enabled` decides whether the bound model's rules also derive its stages and
# whether the model's labels are provisioned in the repository. Owners can flip
# it from Settings → Workflows → Library (PUT /api/workflows/enabled) without
# editing this file; the change applies on the next derivation pass.
# workflow:
# enabled: false # false (default): bindings are columns only
# label_gc: true # delete labels a previous binding provisioned once nothing wears them
87 changes: 87 additions & 0 deletions src/pkg/dashboard/api_workflows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dashboard

import (
"context"
"errors"
"fmt"
"net/http"
Expand All @@ -24,6 +25,7 @@ func (s *Server) registerWorkflowRoutes() {
s.mux.HandleFunc("POST /api/workflows/ingest", s.handleWorkflowIngest)
s.mux.HandleFunc("GET /api/workflows/bindings", s.handleWorkflowBindingsGet)
s.mux.HandleFunc("PUT /api/workflows/bindings", s.handleWorkflowBindingPut)
s.mux.HandleFunc("PUT /api/workflows/enabled", s.handleWorkflowEnabledPut)
s.mux.HandleFunc("GET /api/workflows/{name}/{version}", s.handleWorkflowGet)
s.mux.HandleFunc("PUT /api/workflows/{name}/{version}", s.handleWorkflowSave)
s.mux.HandleFunc("DELETE /api/workflows/{name}/{version}", s.handleWorkflowDelete)
Expand Down Expand Up @@ -236,3 +238,88 @@ func (s *Server) handleWorkflowBindingPut(w http.ResponseWriter, r *http.Request
}
jsonResponse(w, map[string]interface{}{"changed": changed, "bindings": s.workflowBindings()})
}

// workflowProvisionTimeout bounds the label provisioning PUT
// /api/workflows/enabled runs across every bound repository when it turns
// derivation on: one label list plus a create per missing label per
// repository, all within the request.
const workflowProvisionTimeout = 60 * time.Second

// handleWorkflowEnabledPut flips workflow.enabled (hivecommons/hive#17620)
// from the dashboard so a hosted hive with no hive.yaml access can turn
// model-based stage derivation on or off. The stage engine
// (cmd/hive stageEngineWorkflowFor) and the tracker read the live config
// on every call, so the change takes effect on the next derivation pass
// with no restart or reload. Turning it on also provisions every bound
// repository's model labels now through Dependencies.WorkflowProvisionLabels;
// a provisioning failure is reported in the response as a warning, never as
// a failure of the flip itself, because the sweep retries it on its next
// pass. Audited as workflow_enabled / workflow_disabled; a no-op flip is
// not audited.
func (s *Server) handleWorkflowEnabledPut(w http.ResponseWriter, r *http.Request) {
if !requireOwnerRole(w, r) {
return
}
if s.deps == nil || s.deps.Config == nil {
jsonError(w, "config unavailable", http.StatusServiceUnavailable)
return
}
var body struct {
Enabled *bool `json:"enabled"`
}
if err := decodeBody(r, &body); err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
if body.Enabled == nil {
jsonError(w, "body must be {\"enabled\": true|false}", http.StatusBadRequest)
return
}
changed := s.deps.Config.Workflow.Enabled != *body.Enabled
if changed {
s.deps.Config.Workflow.Enabled = *body.Enabled
if err := s.saveConfig(); err != nil {
s.deps.Config.Workflow.Enabled = !*body.Enabled
jsonError(w, "save config: "+err.Error(), http.StatusInternalServerError)
return
}
action := "workflow_disabled"
if *body.Enabled {
action = "workflow_enabled"
}
s.auditFromRequest(r, action, fmt.Sprintf("%d bound repositories", len(s.workflowBindings())), "")
}
resp := map[string]interface{}{
"enabled": s.deps.Config.Workflow.Enabled,
"changed": changed,
"bindings": s.workflowBindings(),
}
if *body.Enabled {
if warnings := s.provisionBoundWorkflowLabels(r.Context()); len(warnings) > 0 {
resp["warnings"] = warnings
}
}
jsonResponse(w, resp)
}

// provisionBoundWorkflowLabels runs WorkflowProvisionLabels for every bound
// repository and returns one message per repository it could not provision.
func (s *Server) provisionBoundWorkflowLabels(ctx context.Context) []string {
if s.deps.WorkflowProvisionLabels == nil {
return nil
}
bindings := s.workflowBindings()
if len(bindings) == 0 {
return nil
}
ctx, cancel := context.WithTimeout(ctx, workflowProvisionTimeout)
defer cancel()
var warnings []string
for _, b := range bindings {
if err := s.deps.WorkflowProvisionLabels(ctx, b.Repo); err != nil {
s.logger.Warn("workflow labels: provisioning on enable failed; the next sweep retries", "repo", b.Repo, "workflow", b.Key(), "err", err)
warnings = append(warnings, fmt.Sprintf("%s: %s", b.Repo, err.Error()))
}
}
return warnings
}
Loading
Loading