diff --git a/api/openapi.yaml b/api/openapi.yaml index e821ca022..ea4ecb57d 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -3618,6 +3618,10 @@ components: - "null" state: type: string + summary: + type: string + target: + $ref: "#/components/schemas/RunsTarget" type: type: string required: @@ -3642,6 +3646,17 @@ components: - needs_repository - settings type: object + RunsTarget: + additionalProperties: false + properties: + id: + type: string + kind: + type: string + required: + - kind + - id + type: object RunsToolCallView: additionalProperties: false properties: diff --git a/modules/runs/context.go b/modules/runs/context.go index cb15499ea..19e030fb4 100644 --- a/modules/runs/context.go +++ b/modules/runs/context.go @@ -47,6 +47,8 @@ type Context struct { nextMarker int // entered holds the top-level steps an earlier attempt reached. entered map[string]bool + // done holds the top-level steps whose outcome is recorded. + done map[string]bool // ending is set when the run ends before its last step. A run that // completes every step has no ending and succeeds. ending *Ending @@ -67,11 +69,14 @@ const ( // enteredPrefix names the marker that records the position a top-level // step began at, so a parked run can retry from it. enteredPrefix = "at:" + // donePrefix names the marker that records a finished top-level step's + // summary and target, for the run's trail. + donePrefix = "done:" ) func newContext(ctx context.Context, work runWork, run store.Run, token uuid.UUID, steps []store.Step) *Context { saved := make(map[int]store.Step, len(steps)) - started, entered := map[string]bool{}, map[string]bool{} + started, entered, done := map[string]bool{}, map[string]bool{}, map[string]bool{} nextMarker := markerBase for _, s := range steps { saved[s.Seq] = s @@ -83,8 +88,12 @@ func newContext(ctx context.Context, work runWork, run store.Run, token uuid.UUI entered[name] = true nextMarker = max(nextMarker, s.Seq+1) } + if name, ok := strings.CutPrefix(s.Name, donePrefix); ok { + done[name] = true + nextMarker = max(nextMarker, s.Seq+1) + } } - rc := &Context{ctx: ctx, work: work, run: run, token: token, saved: saved, started: started, entered: entered, nextMarker: nextMarker} + rc := &Context{ctx: ctx, work: work, run: run, token: token, saved: saved, started: started, entered: entered, done: done, nextMarker: nextMarker} rc.resolve = func(ctx context.Context, req StartRequest) (store.NewRun, error) { return newRun(ctx, work, req) } if run.Dry { rc.overlay, _ = readOverlay(run.Overlay) @@ -125,6 +134,28 @@ func (rc *Context) Enter(ctx context.Context, name string) error { return nil } +// stepOutcome is what a done marker stores for a finished top-level step. +type stepOutcome struct { + Summary string `json:"summary"` + Target *Target `json:"target,omitzero"` +} + +// Done records the summary and target of the top-level step name once it has +// finished, unless an earlier attempt already did. +func (rc *Context) Done(ctx context.Context, name string, res StepResult) error { + if rc.done[name] { + return nil + } + seq := rc.nextMarker + out := stepOutcome{Summary: res.Summary, Target: res.Target} + if _, err := rc.record(ctx, seq, donePrefix+name, out, nil); err != nil && !errors.Is(err, store.ErrStepExists) { + return err + } + rc.done[name] = true + rc.nextMarker = seq + 1 + return nil +} + // End records that the run ends before its last step, with this state and // detail. func (rc *Context) End(state, detail string) { diff --git a/modules/runs/interpreter.go b/modules/runs/interpreter.go index ed6b8ab96..d8c635ab8 100644 --- a/modules/runs/interpreter.go +++ b/modules/runs/interpreter.go @@ -246,7 +246,7 @@ func (d Deps) runStep(rc *Context, p *progress, s Step, index int) error { p.results[s.ID] = res } p.last = res.Summary - return nil + return rc.Done(rc.Context(), name, res) } // stepFailed reports whether err is the step's own failure, which on_failure diff --git a/modules/runs/message.go b/modules/runs/message.go index 07bc4cca5..e0585fd13 100644 --- a/modules/runs/message.go +++ b/modules/runs/message.go @@ -32,13 +32,15 @@ func (s messageSettings) describe() string { // runMessage sends the message. A dry run records it without sending. func runMessage(d Deps, rc *Context, _ *progress, _ string, s messageSettings) (StepResult, error) { - sent := fmt.Sprintf("send to %s chat %s: %s", s.Channel, s.ChatID, s.Text) + res := StepResult{Summary: s.Text, Target: &Target{Kind: s.Channel, ID: s.ChatID}} if rc.Dry() { - _, err := rc.Step("send-skipped", func(context.Context, string) (string, error) { return sent, nil }) - return StepResult{Summary: sent}, err + _, err := rc.Step("send-skipped", func(context.Context, string) (string, error) { + return fmt.Sprintf("send to %s chat %s: %s", s.Channel, s.ChatID, s.Text), nil + }) + return res, err } _, err := rc.Step("send", func(ctx context.Context, key string) (bool, error) { return true, d.Messenger.Send(ctx, s.Channel, s.ChatID, s.Text, key) }) - return StepResult{Summary: sent}, err + return res, err } diff --git a/modules/runs/references.go b/modules/runs/references.go index bac20ceac..9ac20954d 100644 --- a/modules/runs/references.go +++ b/modules/runs/references.go @@ -10,10 +10,19 @@ import ( ) // StepResult is the output later steps can reference as -// steps..summary and steps..result.. +// steps..summary and steps..result.. Target is not referenceable; +// the run's trail shows it beside the summary. type StepResult struct { Summary string `json:"summary"` Result map[string]any `json:"result,omitzero"` + Target *Target `json:"target,omitzero"` +} + +// Target is the item a step acted on: its kind, such as a messaging channel, +// and its identifier. +type Target struct { + Kind string `json:"kind"` + ID string `json:"id"` } // referencePattern matches {{ path }} in a step's string settings. diff --git a/modules/runs/stages.go b/modules/runs/stages.go index 68c85ce73..6073dcbb5 100644 --- a/modules/runs/stages.go +++ b/modules/runs/stages.go @@ -30,6 +30,10 @@ type Stage struct { StartedAt *time.Time `json:"started_at,omitzero"` EndedAt *time.Time `json:"ended_at,omitzero"` Error string `json:"error,omitzero"` + // Summary and Target are the step's result. They are empty for a step that + // hasn't finished, or that finished before results were recorded. + Summary string `json:"summary,omitzero"` + Target *Target `json:"target,omitzero"` } // region is the span of recorded steps one top-level step made, which begins at @@ -80,10 +84,14 @@ func stagesOf(doc Document, steps []store.Recorded, run RunView) []Stage { skipped[name] = true } } + finished := outcomes(steps) out := make([]Stage, 0, len(doc.Steps)) for i, step := range doc.Steps { name := step.name(i) st := Stage{Name: name, Type: stepKind(step), State: StagePending} + if o, ok := finished[name]; ok { + st.Summary, st.Target = o.Summary, o.Target + } if terminal(run.State) { st.State = StageSkipped } @@ -95,6 +103,22 @@ func stagesOf(doc Document, steps []store.Recorded, run RunView) []Stage { return out } +// outcomes reads the done markers a run recorded, by step name. +func outcomes(steps []store.Recorded) map[string]stepOutcome { + out := map[string]stepOutcome{} + for _, s := range steps { + name, ok := strings.CutPrefix(s.Name, donePrefix) + if !ok || s.Seq < markerBase { + continue + } + var o stepOutcome + if json.Unmarshal(s.Output, &o) == nil { + out[name] = o + } + } + return out +} + // reached fills in a stage for the step that began at regs[at]. func reached(st *Stage, regs []region, at int, skipped bool, run RunView) { started := regs[at].at diff --git a/modules/runs/trail.go b/modules/runs/trail.go index 33c0bbfe4..c5c3d3861 100644 --- a/modules/runs/trail.go +++ b/modules/runs/trail.go @@ -284,10 +284,13 @@ func (a *runAPI) trail(ctx context.Context, in *runInput) (*httpapi.Reply[Trail] t.Origin = &o } for _, s := range steps { - e := entry(s) - if s.Seq < markerBase { - e.Step = stageOf(regs, s.Seq) + // Markers record step positions and results for the engine. The + // stages show what they record. + if s.Seq >= markerBase { + continue } + e := entry(s) + e.Step = stageOf(regs, s.Seq) t.Entries = append(t.Entries, e) } decisions, err := a.decisions.ForRun(ctx, id) diff --git a/ui/AGENTS.md b/ui/AGENTS.md index 79d7d44bb..633482410 100644 --- a/ui/AGENTS.md +++ b/ui/AGENTS.md @@ -46,14 +46,18 @@ state; the UI presents them and submits operator choices. ## Components and interaction -- Build pages only from components/ui, the design system modelled on Astryx - (astryx.atmeta.com/components). Use Section for a titled card, SettingRow - for a setting, MetadataList for label/value pairs, DataTable for a table - with optional columns, Badge and StatusDot for state, Timestamp for times, - MoreMenu for overflow actions, Empty for empty states, and the type scale - (text-caption, text-label, text-title) instead of pixel sizes. Never - hand-roll a card, heading, caption, status dot or date format; if a pattern - is missing, add it to components/ui with a real consumer first. +- Build pages only from components/ui and the page frame in src/base + (PageHeader for a page title and its actions, CodeView for code or a payload + with a copy button). Use Section for a titled card, SettingRow for a + setting, MetadataList for label/value pairs, DataTable for a table with + optional columns, Item for a list row, Field for a form field, Badge and + StatusDot for state, Timestamp for times, MoreMenu for overflow actions, + Empty for empty states (including an empty value or result), ReadError for a + failed read, Skeleton while loading, Trace for an agent's steps, + CodeBlockCopyButton to copy an ID or value, and the type scale (text-caption, + text-label, text-title) instead of pixel sizes. Never hand-roll a card, + heading, caption, status dot, copy button or date format; if a pattern is + missing, add it to components/ui with a real consumer first. - Add and update components/ui components with the shadcn-vue CLI, never by writing or copying them by hand: `pnpm dlx shadcn-vue@latest add ` from `ui/`, or the component's registry URL when the maintainer names one. Search diff --git a/ui/src/App.vue b/ui/src/App.vue index 972d414ee..f59deffb3 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -36,6 +36,7 @@ const route = useRoute(); const router = useRouter(); const workflowsPage = computed(() => route.name === "workflow"); const hidden = computed(() => hiddenPaths(session.sections)); +const sectionLink = computed(() => ({ workflow: "/workflows", run: "/runs" })[String(route.name)]); // The redirect below must not run during the router's first navigation: route // is still the start location then, so a deep link would be replaced by the // landing page before it resolves. @@ -118,11 +119,15 @@ watch(() => accounts.status?.user, (user) => { - + +
diff --git a/ui/src/events/EventDetail.vue b/ui/src/events/EventDetail.vue index a950c0b71..5812bd6a7 100644 --- a/ui/src/events/EventDetail.vue +++ b/ui/src/events/EventDetail.vue @@ -3,26 +3,30 @@ import { computed, onMounted } from "vue"; import { RouterLink } from "vue-router"; import CodeView from "@/base/CodeView.vue"; +import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty"; import { ReadError } from "@/components/ui/read-error"; import { Skeleton } from "@/components/ui/skeleton"; import { api } from "@/lib/api"; +import { emptyValue } from "@/lib/format"; import { useRead } from "@/lib/use-read"; /** One event's payload and the runs it started. */ const props = defineProps<{ id: string }>(); const { data, error, reload } = useRead(() => api.event(props.id)); onMounted(reload); -const body = computed(() => JSON.stringify(data.value?.body ?? null, null, 2)); +const body = computed(() => (emptyValue(data.value?.body) ? "" : JSON.stringify(data.value?.body, null, 2))); +const started = computed(() => (data.value?.runs ?? []).filter((run) => run.run_id)); diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index 61f7c5f01..a224caa30 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -920,6 +920,10 @@ export interface RunStage { started_at?: string; ended_at?: string; error?: string; + /** The step's result summary. */ + summary?: string; + /** The item the step acted on, such as a chat on a messaging channel. */ + target?: { kind: string; id: string }; } export interface RunTrail { @@ -976,7 +980,7 @@ export interface TriggerRun { export interface EventDetail { body: unknown; - runs?: { run_id: string; trigger: string }[]; + runs?: { run_id?: string; trigger: string; outcome: string }[]; } // Named with a trailing underscore: EventSource is the browser's SSE class. diff --git a/ui/src/lib/format.ts b/ui/src/lib/format.ts index c594e1928..9efc1a51a 100644 --- a/ui/src/lib/format.ts +++ b/ui/src/lib/format.ts @@ -77,3 +77,11 @@ export function duration(milliseconds: unknown): string { const remMin = minutes - hours * 60; return remMin === 0 ? `${hours} h` : `${hours} h ${remMin} min`; } + +/** emptyValue reports whether a JSON value is null, an empty string, an empty + * array or an empty object. */ +export function emptyValue(value: unknown): boolean { + if (value == null || value === "") return true; + if (Array.isArray(value)) return value.length === 0; + return typeof value === "object" && Object.keys(value).length === 0; +} diff --git a/ui/src/runs/RunPage.vue b/ui/src/runs/RunPage.vue index c3adf09e2..452f9c56c 100644 --- a/ui/src/runs/RunPage.vue +++ b/ui/src/runs/RunPage.vue @@ -6,14 +6,18 @@ import CodeView from "@/base/CodeView.vue"; import PageHeader from "@/base/PageHeader.vue"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; +import { CodeBlockCopyButton } from "@/components/ui/code-block"; import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty"; import { MetadataList } from "@/components/ui/metadata-list"; import { ReadError } from "@/components/ui/read-error"; import { Section } from "@/components/ui/section"; import { Skeleton } from "@/components/ui/skeleton"; +import { StatusDot } from "@/components/ui/status-dot"; import { Timestamp } from "@/components/ui/timestamp"; import { errors } from "@/copy/errors"; -import { api, describeError, type RunAction } from "@/lib/api"; +import { api, describeError, type RunAction, type RunEntry, type RunStage } from "@/lib/api"; +import { duration, emptyValue } from "@/lib/format"; +import AgentTranscript from "@/workflows/AgentTranscript.vue"; import { usePoll, useRead } from "@/lib/use-read"; import { useLiveResource } from "@/stores/session"; import ApprovalsSection from "./ApprovalsSection.vue"; @@ -43,18 +47,51 @@ const origin = computed(() => { ]; }); +// A run that succeeded ends with the summary of its last finished step, so +// that step's target is the run's target. +const finalTarget = computed(() => { + const trail = data.value; + if (trail?.run.state !== "succeeded") return undefined; + return trail.stages.filter((stage) => stage.state === "succeeded").at(-1)?.target; +}); + const details = computed(() => { const run = data.value?.run; if (!run) return []; return [ - { label: "Workflow", value: `${run.workflow} v${run.workflow_version}` }, + { label: "Workflow", value: run.workflow }, ...origin.value, ...(run.attempts > 1 ? [{ label: "Attempts", value: String(run.attempts) }] : []), ...(run.error ? [{ label: "Error", value: run.error }] : []), - ...(run.detail ? [{ label: "Detail", value: run.detail }] : []), + ...(finalTarget.value ? [{ label: "Target", value: finalTarget.value.id }] : []), + ...(run.detail ? [{ label: "Summary", value: run.detail }] : []), { label: "Run", value: run.id, mono: true }, ]; }); + +// A step without an id is named by its type and position, which the type +// badge already shows. +const unnamed = (stage: RunStage, index: number) => stage.name === `${stage.type}@${index}`; + +function stageDuration(stage: RunStage): string { + if (!stage.started_at || !stage.ended_at) return ""; + return duration(new Date(stage.ended_at).getTime() - new Date(stage.started_at).getTime()); +} + +const transcripts = computed(() => { + const byStage = new Map(); + for (const entry of data.value?.entries ?? []) { + if (!entry.step || entry.kind === "step") continue; + byStage.set(entry.step, [...(byStage.get(entry.step) ?? []), entry]); + } + return byStage; +}); +const openTranscripts = ref(new Set()); +function toggleTranscript(name: string): void { + const open = new Set(openTranscripts.value); + if (!open.delete(name)) open.add(name); + openTranscripts.value = open; +} const retrying = ref(false); const retryError = ref(""); async function retry(): Promise { @@ -87,9 +124,10 @@ function target(action: RunAction): string { const t = action.decision.action.target; return t?.ID ? `${t.Kind ? `${t.Kind} ` : ""}${t.ID}` : ""; } -const result = computed(() => - data.value?.run.result == null ? "" : JSON.stringify(data.value.run.result, null, 2), -); +const result = computed(() => { + const value = data.value?.run.result; + return emptyValue(value) ? "" : JSON.stringify(value, null, 2); +});
diff --git a/ui/src/workflows/StepRun.vue b/ui/src/workflows/StepRun.vue index 967c2f319..babc37f44 100644 --- a/ui/src/workflows/StepRun.vue +++ b/ui/src/workflows/StepRun.vue @@ -5,7 +5,7 @@ import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block"; import type { RunEntry } from "@/lib/api"; -import { duration } from "@/lib/format"; +import { duration, emptyValue } from "@/lib/format"; import { stageStatusMeta } from "@/tasks/stage-rail"; import AgentTranscript from "./AgentTranscript.vue"; import type { StageRun } from "./workflow-graph"; @@ -17,8 +17,11 @@ const transcriptOpen = ref(false); const meta = computed(() => stageStatusMeta(props.stage.status)); const talked = computed(() => props.entries.some((entry) => entry.kind === "model")); -// An agent's own steps are the transcript; every other recorded step is shown by name. -const recorded = computed(() => props.entries.filter((entry) => entry.kind === "step")); +// An agent's own steps are the transcript. Every other recorded step with a +// value or an error is listed by its name. +const recorded = computed(() => + props.entries.filter((entry) => entry.kind === "step" && (entry.error || !emptyValue(entry.value))), +); function shown(entry: RunEntry): string { if (entry.error) return entry.error;