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-settings-event-triggers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add owner-only Event triggers settings with scoped scanner first-seen issue presets, advanced CEL editing, validation, durable conflict-protected saves, and a direct link from agent Channels.
73 changes: 73 additions & 0 deletions dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -32369,6 +32369,79 @@
}
}
},
"/api/config/triggers": {
"get": {
"tags": ["System"],
"summary": "Get Event triggers editor configuration",
"description": "Verified owner only. Returns ordered rules, an opaque quoted version/ETag, existing agent names, and managed repositories with configured event.repo values and qualified display labels. apply_mode is next_evaluation and requires_restart is false. No sources or webhooks are installed.",
"responses": {
"200": {"description": "rules, version, agents, repositories, apply_mode and requires_restart"},
"403": {"description": "Owner access required"},
"503": {"description": "Configuration unavailable"}
}
},
"put": {
"tags": ["System"],
"summary": "Validate and persist Event triggers",
"description": "Verified owner only. Compare-and-save the full ordered trigger list without changing unrelated config. Compiles every CEL expression to bool before persistence; new or edited rules require a name and existing agent. Optional preset replaces only its indexed expression with a scoped first-seen event expression. Successful persistence is published for next evaluation without resetting first-seen history. No enabled field is supported; remove a rule from the list to stop its routing.",
"parameters": [
{
"name": "If-Match",
"in": "header",
"required": true,
"description": "Exact opaque version/ETag from GET; stale revisions are rejected, never retried automatically.",
"schema": {"type": "string"}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": false,
"required": ["rules"],
"properties": {
"rules": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["name", "agent", "expr"],
"properties": {
"name": {"type": "string"},
"agent": {"type": "string"},
"expr": {"type": "string"},
"priority": {"type": "integer", "format": "int64", "default": 0}
}
}
},
"preset": {
"type": "object",
"additionalProperties": false,
"required": ["index", "kind", "repo"],
"properties": {
"index": {"type": "integer", "minimum": 0},
"kind": {"type": "string", "enum": ["issue.opened", "pr.opened"]},
"repo": {"type": "string", "description": "One exact configured managed repository value; not its qualified display label or a wildcard."}
}
}
}
}
}
}
},
"responses": {
"200": {"description": "Updated rules and editor metadata, with current version/ETag"},
"400": {"description": "Invalid schema, target, preset scope, or non-boolean/malformed CEL"},
"403": {"description": "Owner access required"},
"412": {"description": "Trigger revision changed; reload before saving"},
"428": {"description": "Missing If-Match revision"},
"500": {"description": "Persistence failed; live rules unchanged"},
"503": {"description": "Configuration unavailable"}
}
}
},
"/api/config/dashboard/theme": {
"get": {
"tags": [
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/hive/celwire.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func celEngineFor(cfg *config.Config, logger *slog.Logger) *celtrigger.Engine {
if cfg == nil {
return nil
}
sig := triggersSignature(cfg.Triggers)
triggers := cfg.TriggerRulesSnapshot()
sig := triggersSignature(triggers)

globalCELEngine.mu.Lock()
defer globalCELEngine.mu.Unlock()
Expand All @@ -82,12 +83,12 @@ func celEngineFor(cfg *config.Config, logger *slog.Logger) *celtrigger.Engine {
globalCELEngine.sig = sig
globalCELEngine.built = true

if len(cfg.Triggers) == 0 {
if len(triggers) == 0 {
globalCELEngine.engine = nil
return nil
}

engine, err := celtrigger.CompileFromConfig(cfg)
engine, err := celtrigger.CompileFromConfig(&config.Config{Triggers: triggers})
if err != nil {
// Fail-closed: a malformed rule must never crash the fleet or silently
// change routing. Log once (per triggers change) and run with no CEL
Expand Down
64 changes: 64 additions & 0 deletions src/cmd/hive/celwire_settings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"path/filepath"
"reflect"
"testing"

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

func TestCELPersistedSettingsReloadWithoutReplayingSeenItems(t *testing.T) {
resetCELCache()
t.Cleanup(resetCELCache)
dir := t.TempDir()
oldRuntime, oldOverlay := config.RuntimeConfigFile, config.DashboardOverlayFile
config.RuntimeConfigFile, config.DashboardOverlayFile = filepath.Join(dir, "runtime.yaml"), filepath.Join(dir, "overlay.yaml")
t.Cleanup(func() { config.RuntimeConfigFile, config.DashboardOverlayFile = oldRuntime, oldOverlay })
cfg := &config.Config{
SourcePath: filepath.Join(dir, "hive.yaml"),
Project: config.ProjectConfig{Org: "org", Repos: []string{"repo"}},
Triggers: []config.TriggerRule{{Name: "first-seen", Expr: `event.kind == "issue.opened" && event.repo == "repo"`, Agent: "reviewer"}},
AgentRuntimeConfig: config.AgentRuntimeConfig{Agents: map[string]config.AgentConfig{
"reviewer": {Enabled: true, Backend: "claude"},
"scanner": {Enabled: true, Backend: "claude"},
}},
}
gov := newTestGovernor(cfg.Agents)
var seen celSeenSet
run := func(number int) []string {
result := &github.ActionableResult{}
result.Issues.Items = append(result.Issues.Items, github.Issue{Repo: "repo", Number: number})
return celMatchedAgentsOnce(celEngineFor(cfg, celTestLogger()), result, cfg, gov, func(string) bool { return false }, celTestLogger(), &seen)
}
if got := run(1); !reflect.DeepEqual(got, []string{"reviewer"}) {
t.Fatalf("initial existing actionable issue: %v", got)
}
oldEngine := celEngineFor(cfg, celTestLogger())
next := cfg.TriggerRulesSnapshot()
next[0].Agent = "scanner"
if err := cfg.SaveTriggerRules(config.TriggerRulesVersion(cfg.TriggerRulesSnapshot()), next); err != nil {
t.Fatal(err)
}
if celEngineFor(cfg, celTestLogger()) == oldEngine {
t.Fatal("next evaluation did not recompile saved settings")
}
if got := run(1); len(got) != 0 {
t.Fatalf("editing rules reset first-seen history: %v", got)
}
if got := run(2); !reflect.DeepEqual(got, []string{"scanner"}) {
t.Fatalf("new actionable issue did not use updated rule: %v", got)
}
currentEngine := celEngineFor(cfg, celTestLogger())
cfg.SourcePath = ""
if err := cfg.SaveTriggerRules(config.TriggerRulesVersion(next), nil); err == nil {
t.Fatal("expected persistence failure")
}
if celEngineFor(cfg, celTestLogger()) != currentEngine {
t.Fatal("failed save changed the live compiled engine")
}
if got := run(3); !reflect.DeepEqual(got, []string{"scanner"}) {
t.Fatalf("failed save changed runtime routing: %v", got)
}
}
Loading
Loading