From 841c6aea16a3945ded94e617ec0b4da414f45b68 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 13 Nov 2026 18:01:33 +1100 Subject: [PATCH] feat(workflow): serve which workflows start each one; the trigger card stops re-deriving it (#1960) --- internal/domain/workflow/started_by.go | 80 ++++++++++++++++++++++++++ internal/domain/workflow/task/task.go | 22 +++++++ internal/webui/workflows.go | 7 ++- ui/src/workflows/WorkflowEditor.vue | 6 +- ui/src/workflows/WorkflowsPage.vue | 2 +- ui/src/workflows/workflow-rows.ts | 2 + ui/src/workflows/workflow-triggers.ts | 51 +++------------- 7 files changed, 122 insertions(+), 48 deletions(-) create mode 100644 internal/domain/workflow/started_by.go diff --git a/internal/domain/workflow/started_by.go b/internal/domain/workflow/started_by.go new file mode 100644 index 000000000..70d3984a0 --- /dev/null +++ b/internal/domain/workflow/started_by.go @@ -0,0 +1,80 @@ +package workflow + +import ( + "maps" + "slices" + "strings" + + "gopkg.in/yaml.v3" + + "github.com/samcharles93/archie-core/internal/domain/workflow/task" +) + +// StartedBy reports, for each workflow named in sources (id to YAML), the +// other workflows whose steps start it. It reads the same settings the engine +// follows: a call's workflow, a handoff's target (or every value an agent +// result's enum allows when the target is templated from one), and an +// approval's then. A definition that does not parse starts nothing. +func StartedBy(sources map[string]string) map[string][]task.Starter { + type edge struct { + target string + starter task.Starter + } + seen := map[edge]bool{} + starters := map[string][]task.Starter{} + for _, id := range slices.Sorted(maps.Keys(sources)) { + var definition YAMLDefinition + if err := yaml.Unmarshal([]byte(sources[id]), &definition); err != nil { + continue + } + // The visitor never fails, so walkSteps has no error to report. + _ = walkSteps(definition.Steps, id, func(_ string, step StepRecord) error { + for target, via := range stepTargets(definition, step) { + e := edge{target: target, starter: task.Starter{Workflow: id, Via: via}} + if target == id || seen[e] { + continue + } + seen[e] = true + starters[target] = append(starters[target], e.starter) + } + return nil + }) + } + // Map order would reorder the list between reads; sorted, it holds still. + for _, list := range starters { + slices.SortFunc(list, func(a, b task.Starter) int { + return strings.Compare(a.Workflow+string(a.Via), b.Workflow+string(b.Via)) + }) + } + return starters +} + +// stepTargets is every workflow one step can start, with how it starts it. +func stepTargets(definition YAMLDefinition, step StepRecord) map[string]task.StartedVia { + switch step.Type { + case WorkflowCallStepName: + settings, err := decodeCallSettings(step) + if err != nil || strings.TrimSpace(settings.Workflow) == "" { + return nil + } + return map[string]task.StartedVia{strings.TrimSpace(settings.Workflow): task.StartedViaCall} + case HandoffStepName, ApproveStepName: + target, ok, err := controlTarget(step) + if err != nil || !ok || target == "" { + return nil + } + via := task.StartedViaHandoff + if step.Type == ApproveStepName { + via = task.StartedViaApprove + } + if !referencePattern.MatchString(target) { + return map[string]task.StartedVia{target: via} + } + targets := map[string]task.StartedVia{} + for _, name := range targetEnum(definition, target) { + targets[name] = via + } + return targets + } + return nil +} diff --git a/internal/domain/workflow/task/task.go b/internal/domain/workflow/task/task.go index f4fdf19e0..f7c78aa32 100644 --- a/internal/domain/workflow/task/task.go +++ b/internal/domain/workflow/task/task.go @@ -236,8 +236,30 @@ type Definition struct { // editor can offer the inputs to assign and whether to name a repository. Inputs map[string]InputSpec `json:"inputs,omitempty"` Repository RepositoryMode `json:"repository,omitempty"` + // StartedBy lists the other workflows whose steps start this one. + StartedBy []Starter `json:"started_by,omitempty"` } +// Starter is a workflow whose steps start another, and the step kind that +// does it. +type Starter struct { + Workflow string `json:"workflow"` + Via StartedVia `json:"via"` +} + +// StartedVia is how one workflow starts another. +type StartedVia string + +const ( + // StartedViaCall is a workflow.call step. + StartedViaCall StartedVia = "call" + // StartedViaHandoff is a workflow.handoff step, including one whose + // target an agent picks from a fixed set. + StartedViaHandoff StartedVia = "handoff" + // StartedViaApprove is a workflow.approve step's then target. + StartedViaApprove StartedVia = "approve" +) + // HasRepository reports whether the task works on a repository. A task a // binding started for a workflow with repository none (or optional, with no // repository named) has neither owner nor repo and runs in a scratch diff --git a/internal/webui/workflows.go b/internal/webui/workflows.go index 7c0bc7aac..4f7d43b91 100644 --- a/internal/webui/workflows.go +++ b/internal/webui/workflows.go @@ -339,9 +339,14 @@ func (a *workflowsAPI) workflowDefinitions(ctx context.Context) ([]task.Definiti if err != nil { return nil, err } + sources := make(map[string]string, len(collection.Definitions)) + for _, entry := range collection.Definitions { + sources[entry.ID] = entry.YAML + } + startedBy := workflow.StartedBy(sources) definitions := make([]task.Definition, 0, len(collection.Definitions)) for _, entry := range collection.Definitions { - definition := task.Definition{ID: entry.ID, Name: entry.ID, Origin: "database", Enabled: enablement.Enabled(org.OrgFromContext(ctx), entry.ID), Repository: task.RepositoryRequired} + definition := task.Definition{ID: entry.ID, Name: entry.ID, Origin: "database", Enabled: enablement.Enabled(org.OrgFromContext(ctx), entry.ID), Repository: task.RepositoryRequired, StartedBy: startedBy[entry.ID]} if iface, err := task.ParseWorkflowInterface(entry.YAML); err == nil { definition.Inputs, definition.Repository = iface.Inputs, iface.RepositoryMode() } diff --git a/ui/src/workflows/WorkflowEditor.vue b/ui/src/workflows/WorkflowEditor.vue index 59a5d7df6..8e04def13 100644 --- a/ui/src/workflows/WorkflowEditor.vue +++ b/ui/src/workflows/WorkflowEditor.vue @@ -9,7 +9,7 @@ import { AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; -import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue"; +import { computed, nextTick, onBeforeUnmount, onMounted, ref, toRef, watch } from "vue"; import { CircleAlert, Copy, RotateCcw, Trash2 } from "@lucide/vue"; import { isSending, setTurnHooks } from "@/chat/state"; @@ -71,7 +71,7 @@ const collection = computed(() => workflows.collection); const selected = defineModel("selected", { required: true }); const emit = defineEmits<{ duplicate: [id: string] }>(); // Stage statistics are read by the page with the rest of the workflow stats. -defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string }>(); +const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[] }>(); const id = ref(""); const yaml = ref(""); const loadedYaml = ref(""); @@ -117,7 +117,7 @@ async function restartFrom(from: string): Promise { restarting.value = false; } } -const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected); +const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected, toRef(() => props.startedBy)); const { revisions, error: historyError, loaded: historyLoaded, reload: reloadHistory } = useWorkflowHistory(selected); const historyRevision = ref(0); diff --git a/ui/src/workflows/WorkflowsPage.vue b/ui/src/workflows/WorkflowsPage.vue index bec4a9d7b..3d21030ca 100644 --- a/ui/src/workflows/WorkflowsPage.vue +++ b/ui/src/workflows/WorkflowsPage.vue @@ -267,7 +267,7 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total : {{ provenance }} - +