Merge pull request 'chore(workflow): remove the needs block (#1888)' (#1916) from chore/1888-remove-workflow-needs into main
deploy / plan (push) Successful in 26s
ci/woodpecker/push/deploy Pipeline failed
deploy / gate (push) Failing after 8m36s
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped

Reviewed-on: #1916
This commit was merged in pull request #1916.
This commit is contained in:
sam committed 2026-11-12 15:31:42 +00:00
commit a04fd3834d
5 files changed
+106 -53

No files matched your search

-1
View File
@@ -46,7 +46,6 @@ steps:
| `outputs` | mapping | Named, typed results the run writes once each (same shape as inputs). A required output the run never writes parks it. A calling workflow reads them. |
| `profile` | text | The container profile (`[containers.profiles]`) the run's agents use. Resolved when the task is dispatched. |
| `identity` | text | The identity every run acts as, whatever started it. Empty runs as the starter. |
| `needs` | mapping | Harness capabilities the run requires: `captures` (bool), `gate_retries` (number). Declared outputs imply `captures`. |
## A step
+36 -1
View File
@@ -86,10 +86,45 @@ type StepFactory func(yaml.Node) (Stage, error)
// StepRegistry is the closed set of safe workflow operations available to YAML.
type StepRegistry map[string]StepFactory
// dropNeeds removes a needs: block a definition written before the field went
// away may still carry. The key is deleted from the document's root mapping,
// so the caller's strict decode sees no trace of it while every other key,
// including those inside steps, keeps its original wording.
func dropNeeds(src string) ([]byte, error) {
decoder := yaml.NewDecoder(strings.NewReader(src))
var document yaml.Node
if err := decoder.Decode(&document); err != nil {
return nil, fmt.Errorf("parse workflow YAML: %w", err)
}
if document.Kind == yaml.DocumentNode && len(document.Content) > 0 {
if root := document.Content[0]; root.Kind == yaml.MappingNode {
for i := 0; i+1 < len(root.Content); i += 2 {
if root.Content[i].Value == "needs" {
root.Content = slices.Delete(root.Content, i, i+2)
break
}
}
}
}
var encoded bytes.Buffer
encoder := yaml.NewEncoder(&encoded)
if err := encoder.Encode(&document); err != nil {
return nil, err
}
if err := encoder.Close(); err != nil {
return nil, err
}
return encoded.Bytes(), nil
}
// ParseDefinition strictly parses and validates one YAML workflow.
func ParseDefinition(src string, registry StepRegistry) (YAMLDefinition, error) {
document, err := dropNeeds(src)
if err != nil {
return YAMLDefinition{}, err
}
var definition YAMLDefinition
decoder := yaml.NewDecoder(strings.NewReader(src))
decoder := yaml.NewDecoder(bytes.NewReader(document))
decoder.KnownFields(true)
if err := decoder.Decode(&definition); err != nil {
return YAMLDefinition{}, fmt.Errorf("parse workflow YAML: %w", err)
@@ -0,0 +1,70 @@
package workflow
import (
"encoding/json"
"testing"
)
// Definitions written before the needs block went away still carry a needs
// entry in their YAML. The load path drops it, so a definition that parsed
// when it was saved still loads now, while strictness for everything else is
// unchanged.
func TestParseDefinitionDropsStoredNeeds(t *testing.T) {
t.Parallel()
var shipped string
for _, entry := range ShippedDefinitions().Definitions {
if entry.ID == "triage" {
shipped = entry.YAML
}
}
if shipped == "" {
t.Fatal("the triage definition is not shipped")
}
tests := []struct {
name string
yaml string
wantErr bool
}{
{
name: "a stored definition carrying needs still loads",
yaml: shipped + "needs:\n captures: true\n gate_retries: 3\n",
},
{
// The strip must drop exactly the needs key, not sed the parser
// into a lenient one: anything else unknown is still refused.
name: "a stored definition with another unknown key is still refused",
yaml: shipped + "bogus: 1\n",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// Ship the whole collection: a call target only validates
// against the workflows beside it.
entries := []WorkflowDefinitionEntry{}
for _, entry := range ShippedDefinitions().Definitions {
if entry.ID == "triage" {
entry.YAML = tt.yaml
}
entries = append(entries, entry)
}
value, err := json.Marshal(WorkflowDefinitionCollection{Definitions: entries})
if err != nil {
t.Fatal(err)
}
collection, err := DecodeDefinitionCollection(value, triageRegistry())
if (err != nil) != tt.wantErr {
t.Fatalf("DecodeDefinitionCollection() err = %v, wantErr %v", err, tt.wantErr)
}
if tt.wantErr {
return
}
if len(collection.Definitions) != len(entries) {
t.Fatalf("kept %d definitions, want %d", len(collection.Definitions), len(entries))
}
})
}
}
@@ -63,29 +63,6 @@ type WorkflowInterface struct {
// Instructions are the workflow's layer of the instructions every agent
// stage of a run follows.
Instructions string `yaml:"instructions,omitempty" json:"instructions,omitempty"`
// DeclaredNeeds is what the definition's needs: block declares. Read
// Needs, not this, when deciding a harness requirement: a declared output
// forces the captures capability and Needs resolves it.
DeclaredNeeds WorkflowNeeds `yaml:"needs" json:"needs"`
}
// Needs returns the declared needs plus captures when outputs are declared.
func (w WorkflowInterface) Needs() WorkflowNeeds {
needs := w.DeclaredNeeds
if len(w.Outputs) > 0 {
needs.Captures = true
}
return needs
}
// WorkflowNeeds is WorkflowInterface's declared harness requirements.
type WorkflowNeeds struct {
// Captures declares that a stage returns structured output through
// capture tools.
Captures bool `yaml:"captures,omitempty" json:"captures,omitempty"`
// GateRetries is the largest gate-retry budget any stage declares. Zero
// means no stage gates its result, so no resume capability is needed.
GateRetries int `yaml:"gate_retries,omitempty" json:"gate_retries,omitempty"`
}
var (
@@ -127,9 +104,6 @@ func (w WorkflowInterface) Validate() error {
return fmt.Errorf("workflow output %q type %q must be one of %s", name, spec.Type, strings.Join(inputTypes, ", "))
}
}
if w.DeclaredNeeds.GateRetries < 0 {
return fmt.Errorf("workflow needs.gate_retries must not be negative")
}
return nil
}
-25
View File
@@ -2,12 +2,10 @@
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Label } from "@/components/ui/label";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { computed, ref, onMounted } from "vue";
import { Button } from "@/components/ui/button";
import { Switch } from "@/components/ui/switch";
import { api } from "@/lib/api";
import type { Identity } from "@/stores/org";
import { useOrgStore } from "@/stores/org";
@@ -66,14 +64,6 @@ const MODES = [
{ value: "none", label: "None", hint: "Scratch workspace, no clone" },
];
const repository = computed(() => text("repository") || "required");
// needs is the workflow's declared harness requirements: captures (a stage
// returns structured output through capture tools) and the largest gate-retry
// budget any stage declares.
const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => {
const value = workflowField(props.yaml, "needs");
return value && typeof value === "object" ? (value as { captures?: boolean; gate_retries?: number }) : {};
});
</script>
<template>
@@ -111,21 +101,6 @@ const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => {
<ToggleGroupItem v-for="mode in MODES" :key="mode.value" :value="mode.value" :title="mode.hint">{{ mode.label }}</ToggleGroupItem>
</ToggleGroup>
</div>
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-label" title="Stages return structured output through capture tools">Captures</span>
<Switch :model-value="needs.captures === true" @update:model-value="set('needs', { ...needs, captures: $event || undefined })" />
</Label>
<Label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-label">Gate retries</span>
<Input
type="number"
min="0"
placeholder="0"
class="h-8 w-20 text-right text-label"
:model-value="needs.gate_retries ?? ''"
@update:model-value="(value) => set('needs', { ...needs, gate_retries: String(value) === '' ? undefined : Number(String(value)) })"
/>
</Label>
</div>
<section class="space-y-1.5">