π OpenHands: AI-Driven Development
feat: show manifest-declared value statements on dashboard cards and rows (#16921)
Hiep Leb50c60c6728e
diff --git a/__tests__/components/automations/automation-card.test.tsx b/__tests__/components/automations/automation-card.test.tsxindex e872b72cc7..1961bdc6b5 100644--- a/__tests__/components/automations/automation-card.test.tsx+++ b/__tests__/components/automations/automation-card.test.tsx@@ -36,6 +36,27 @@ vi.mock("#/hooks/use-has-permission", () => ({useHasPermission: () => true,}));+// The pinned package predates the `impact` field, so an entry carrying one is+// appended to the real catalog.+vi.mock("@openhands/extensions/automations", async (importOriginal) => {+ const actual =+ await importOriginal<typeof import("@openhands/extensions/automations")>();+ return {+ ...actual,+ AUTOMATION_CATALOG: [+ ...actual.AUTOMATION_CATALOG,+ {+ id: "widget-checker",+ impact: {+ basis: "completed-runs",+ one: "1 widget check completed",+ other: "{{count}} widget checks completed",+ },+ },+ ] as typeof actual.AUTOMATION_CATALOG,+ };+});+const automation: Automation = {id: "automation-1",name: "Async Standup Digest",@@ -158,6 +179,7 @@ describe("AutomationCard", () => {state: {summary: {total: 4,+ completedTotal: 4,latestRun,recentRuns: [latestRun],recentSuccessRate: 1,@@ -184,6 +206,48 @@ describe("AutomationCard", () => {expect(screen.getByText("4")).toBeInTheDocument();expect(screen.getByText("100%")).toBeInTheDocument();});++ it("shows the value statement for its completed runs", () => {+ // Arrange β provenance joining back to a catalog entry with an impact+ // declaration, and a summary carrying the lifetime completed count.+ const latestRun = createRun();++ // Act+ render(+ <AutomationCard+ automation={{+ ...automation,+ preset_metadata: {+ template: { id: "widget-checker", version: "1.0.0", config: {} },+ },+ }}+ onToggle={vi.fn()}+ onRunNow={vi.fn()}+ onExport={vi.fn()}+ onDelete={vi.fn()}+ insights={{+ spec: insightsSpec satisfies InterfaceListInsights,+ state: {+ summary: {+ total: 5,+ completedTotal: 4,+ latestRun,+ recentRuns: [latestRun],+ recentSuccessRate: 1,+ averageDurationMs: 120_000,+ },+ isLoading: false,+ isError: false,+ },+ }}+ />,+ );++ // Assert+ expect(+ screen.getByTestId("automation-impact-automation-1"),+ ).toHaveTextContent("4 widget checks completed");+ });});describe("AutomationCard β run phase", () => {diff --git a/__tests__/components/automations/automation-list-row.test.tsx b/__tests__/components/automations/automation-list-row.test.tsxindex b5925d8f75..7f1c56756a 100644--- a/__tests__/components/automations/automation-list-row.test.tsx+++ b/__tests__/components/automations/automation-list-row.test.tsx@@ -24,6 +24,27 @@ vi.mock("#/hooks/use-has-permission", () => ({useHasPermission: () => true,}));+// The pinned package predates the `impact` field, so an entry carrying one is+// appended to the real catalog.+vi.mock("@openhands/extensions/automations", async (importOriginal) => {+ const actual =+ await importOriginal<typeof import("@openhands/extensions/automations")>();+ return {+ ...actual,+ AUTOMATION_CATALOG: [+ ...actual.AUTOMATION_CATALOG,+ {+ id: "widget-checker",+ impact: {+ basis: "completed-runs",+ one: "1 widget check completed",+ other: "{{count}} widget checks completed",+ },+ },+ ] as typeof actual.AUTOMATION_CATALOG,+ };+});+const automation: Automation = {id: "automation-1",name: "GitHub PR Reviewer",@@ -113,6 +134,7 @@ describe("AutomationListRow", () => {state: {summary: {total: 4,+ completedTotal: 4,latestRun,recentRuns: [latestRun],recentSuccessRate: 1,@@ -134,6 +156,48 @@ describe("AutomationListRow", () => {).toBeInTheDocument();});+ it("shows the value statement in the meta line", () => {+ // Arrange β provenance joining back to a catalog entry with an impact+ // declaration, and a summary carrying the lifetime completed count.+ const latestRun = createRun();++ // Act+ render(+ <AutomationListRow+ automation={{+ ...automation,+ preset_metadata: {+ template: { id: "widget-checker", version: "1.0.0", config: {} },+ },+ }}+ onToggle={vi.fn()}+ onRunNow={vi.fn()}+ onExport={vi.fn()}+ onDelete={vi.fn()}+ insights={{+ spec: insightsSpec satisfies InterfaceListInsights,+ state: {+ summary: {+ total: 5,+ completedTotal: 4,+ latestRun,+ recentRuns: [latestRun],+ recentSuccessRate: 1,+ averageDurationMs: 120_000,+ },+ isLoading: false,+ isError: false,+ },+ }}+ />,+ );++ // Assert+ expect(+ screen.getByTestId("automation-impact-automation-1"),+ ).toHaveTextContent("4 widget checks completed");+ });+it("opens the actions menu without triggering row navigation handlers", async () => {const user = userEvent.setup();diff --git a/__tests__/manifests/automation-insights.test.ts b/__tests__/manifests/automation-insights.test.tsindex a7f0dfbe35..26bf208ed4 100644--- a/__tests__/manifests/automation-insights.test.ts+++ b/__tests__/manifests/automation-insights.test.ts@@ -48,6 +48,7 @@ function settled(summary: Partial<AutomationRunSummary>): RunSummaryState {return {summary: {total: 0,+ completedTotal: null,latestRun: null,recentRuns: [],recentSuccessRate: null,@@ -154,9 +155,12 @@ describe("summarizeAutomationRuns", () => {const summary = summarizeAutomationRuns({ runs, total: 40 });// Assert β success rate and durations consider COMPLETED and FAILED only;- // total is the response's lifetime count, not the sample's length.+ // total is the response's lifetime count, not the sample's length. With+ // no status_counts and more history than the sample, the completed count+ // is unknowable rather than guessed.expect(summary).toEqual({total: 40,+ completedTotal: null,latestRun: runs[0],recentRuns: runs,recentSuccessRate: 0.5,@@ -179,6 +183,51 @@ describe("summarizeAutomationRuns", () => {duration: summary.averageDurationMs,}).toEqual({ rate: null, duration: null });});++ it("takes the lifetime completed count from status_counts", () => {+ // Arrange β the service's counts outrank anything the sample suggests.+ const runs = [createRun({ status: AutomationRunStatus.FAILED })];++ // Act+ const summary = summarizeAutomationRuns({+ runs,+ total: 80,+ status_counts: { COMPLETED: 70, FAILED: 10 },+ });++ // Assert+ expect(summary.completedTotal).toBe(70);+ });++ it("treats a missing COMPLETED key as zero when status_counts is present", () => {+ // Arrange β the field is sparse, so its presence makes absence mean zero.+ const runs = [createRun({ status: AutomationRunStatus.FAILED })];++ // Act+ const summary = summarizeAutomationRuns({+ runs,+ total: 1,+ status_counts: { FAILED: 1 },+ });++ // Assert+ expect(summary.completedTotal).toBe(0);+ });++ it("counts the sample exactly when it holds the whole history", () => {+ // Arrange β an older service reports no status_counts, but total says the+ // two sampled runs are all there ever were.+ const runs = [+ createRun(),+ createRun({ status: AutomationRunStatus.FAILED }),+ ];++ // Act+ const summary = summarizeAutomationRuns({ runs, total: 2 });++ // Assert+ expect(summary.completedTotal).toBe(1);+ });});describe("matchesAutomationSearch", () => {diff --git a/__tests__/utils/automation-catalog.test.ts b/__tests__/utils/automation-catalog.test.tsindex 4decd8fbce..e71c5ab75d 100644--- a/__tests__/utils/automation-catalog.test.ts+++ b/__tests__/utils/automation-catalog.test.ts@@ -1,14 +1,85 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import { AUTOMATION_CATALOG } from "@openhands/extensions/automations";import { Activity, Bot } from "lucide-react";import {getAutomationIcon,getAutomationLaunchPrompt,+ resolveAutomationImpactStatement,} from "#/utils/automation-catalog";+import type { Automation } from "#/types/automation";++// Entries carrying an `impact` β valid and malformed β and one declaring none+// are appended to the real catalog, so what a given package release declares+// never decides these assertions.+vi.mock("@openhands/extensions/automations", async (importOriginal) => {+ const actual =+ await importOriginal<typeof import("@openhands/extensions/automations")>();+ const syntheticEntries = [+ { id: "impact-absent" },+ {+ id: "impact-valid",+ impact: {+ basis: "completed-runs",+ one: "1 widget check completed",+ other: "{{count}} widget checks completed",+ },+ },+ {+ id: "impact-unknown-basis",+ impact: { basis: "run-counter", one: "1 widget", other: "{{count}} widgets" },+ },+ {+ id: "impact-markup",+ impact: {+ basis: "completed-runs",+ one: "<b>1 check</b>",+ other: "{{count}} <b>checks</b>",+ },+ },+ {+ id: "impact-no-count",+ impact: { basis: "completed-runs", one: "one check", other: "many checks" },+ },+ {+ id: "impact-foreign-placeholder",+ impact: {+ basis: "completed-runs",+ one: "1 check",+ other: "{{count}} checks for {{form.repo}}",+ },+ },+ ];+ return {+ ...actual,+ AUTOMATION_CATALOG: [+ ...actual.AUTOMATION_CATALOG,+ ...syntheticEntries,+ ] as typeof actual.AUTOMATION_CATALOG,+ };+});const automationById = (id: string) =>AUTOMATION_CATALOG.find((automation) => automation.id === id)!;+function createInstalledAutomation(templateId?: string): Automation {+ return {+ id: "automation-1",+ name: "Widget Monitor",+ trigger: { type: "cron" },+ enabled: true,+ prompt: null,+ created_at: "2026-01-01T00:00:00Z",+ updated_at: "2026-01-01T00:00:00Z",+ ...(templateId+ ? {+ preset_metadata: {+ template: { id: templateId, version: "1.0.0", config: {} },+ },+ }+ : {}),+ };+}+describe("getAutomationLaunchPrompt", () => {it("resolves the command from the skill that implements the automation", () => {// Arrange / Act / Assert β an entry whose skill is its own id, and one@@ -58,3 +129,76 @@ describe("getAutomationIcon", () => {).toBeNull();});});++describe("resolveAutomationImpactStatement", () => {+ it("renders the phrase for the count, singular and plural", () => {+ // Arrange+ const automation = createInstalledAutomation("impact-valid");++ // Act / Assert+ expect(resolveAutomationImpactStatement(automation, 1)).toBe(+ "1 widget check completed",+ );+ expect(resolveAutomationImpactStatement(automation, 4)).toBe(+ "4 widget checks completed",+ );+ });++ it("says nothing for a zero or unknown count", () => {+ // Arrange β zero must never surface as zero-value copy, and null is an+ // older service whose lifetime count is unknowable.+ const automation = createInstalledAutomation("impact-valid");++ // Act / Assert+ expect(resolveAutomationImpactStatement(automation, 0)).toBeNull();+ expect(resolveAutomationImpactStatement(automation, null)).toBeNull();+ });++ it("says nothing without a template to join back to", () => {+ // Arrange / Act / Assert β no provenance at all, and provenance naming an+ // entry the catalog does not hold.+ expect(+ resolveAutomationImpactStatement(createInstalledAutomation(), 4),+ ).toBeNull();+ expect(+ resolveAutomationImpactStatement(+ createInstalledAutomation("not-in-catalog"),+ 4,+ ),+ ).toBeNull();+ });++ it("says nothing when the entry declares no impact this host honors", () => {+ // Arrange / Act / Assert β an entry without the field, and one whose+ // basis this host does not know how to compute.+ expect(+ resolveAutomationImpactStatement(+ createInstalledAutomation("impact-absent"),+ 4,+ ),+ ).toBeNull();+ expect(+ resolveAutomationImpactStatement(+ createInstalledAutomation("impact-unknown-basis"),+ 4,+ ),+ ).toBeNull();+ });++ it("rejects a malformed impact declaration", () => {+ // Arrange / Act / Assert β markup, a plural without the count, and a+ // placeholder from another namespace each invalidate the declaration.+ for (const templateId of [+ "impact-markup",+ "impact-no-count",+ "impact-foreign-placeholder",+ ]) {+ expect(+ resolveAutomationImpactStatement(+ createInstalledAutomation(templateId),+ 4,+ ),+ ).toBeNull();+ }+ });+});diff --git a/src/components/features/automations/automation-card.tsx b/src/components/features/automations/automation-card.tsxindex de0cd7b29f..6195f8740d 100644--- a/src/components/features/automations/automation-card.tsx+++ b/src/components/features/automations/automation-card.tsx@@ -23,6 +23,7 @@ import {} from "#/utils/extension-module-card-classes";import { toLatestRunState } from "./to-latest-run-state";import { RunPhase, shouldShowRunPhase } from "./detail/run-phase";+import { resolveAutomationImpactStatement } from "#/utils/automation-catalog";import { RunStatusBadge } from "./detail/run-status-badge";import { AutomationRunActivitySparkline } from "#/components/features/home/featured-automations/automation-run-activity-sparkline";import type { RunSummaryState } from "#/manifests/automation-insights";@@ -89,6 +90,10 @@ export function AutomationCard({});const runState = toLatestRunState(insights?.state);+ const impactStatement = resolveAutomationImpactStatement(+ automation,+ insights?.state?.summary?.completedTotal ?? null,+ );const { latestRun, recentRuns, isLoading, isError } = runState;const timestamp = latestRun ? getLastRunTimestamp(latestRun) : null;const errorDetail =@@ -258,6 +263,15 @@ export function AutomationCard({</div>) : null}+ {impactStatement ? (+ <p+ data-testid={`automation-impact-${automation.id}`}+ className="mt-3 truncate text-xs text-[var(--oh-text-secondary)]"+ >+ {impactStatement}+ </p>+ ) : null}+{insights ? (<div className="mt-3"><AutomationRunStatsdiff --git a/src/components/features/automations/automation-list-row.tsx b/src/components/features/automations/automation-list-row.tsxindex 80a1a59d47..134086391f 100644--- a/src/components/features/automations/automation-list-row.tsx+++ b/src/components/features/automations/automation-list-row.tsx@@ -33,6 +33,7 @@ import {} from "#/components/features/home/featured-automations/automation-run-health";import type { AutomationInsightsProps } from "./automation-card";import { toLatestRunState } from "./to-latest-run-state";+import { resolveAutomationImpactStatement } from "#/utils/automation-catalog";interface AutomationListRowProps {automation: Automation;@@ -87,6 +88,10 @@ export function AutomationListRow({const runState = toLatestRunState(insights?.state);const health = deriveRunHealth(runState);+ const impactStatement = resolveAutomationImpactStatement(+ automation,+ insights?.state?.summary?.completedTotal ?? null,+ );const latestRun = runState.latestRun;const lastRunAt = latestRun? getLastRunTimestamp(latestRun)@@ -176,6 +181,21 @@ export function AutomationListRow({<RunStatusBadge status={latestRun.status} compact /></>) : null}+ {impactStatement ? (+ <>+ {hasTriggerMeta || whenLabel || latestRun ? (+ <span className="shrink-0" aria-hidden="true">+ Β·+ </span>+ ) : null}+ <span+ data-testid={`automation-impact-${automation.id}`}+ className="truncate"+ >+ {impactStatement}+ </span>+ </>+ ) : null}</span>) : null}<span className="sr-only">{t(statusLabelKey)}</span>diff --git a/src/manifests/automation-insights.ts b/src/manifests/automation-insights.tsindex 55a3dee8ae..866b9e235e 100644--- a/src/manifests/automation-insights.ts+++ b/src/manifests/automation-insights.ts@@ -51,6 +51,13 @@ export const HEALTH_LABEL_KEYS: Record<export interface AutomationRunSummary {/** Lifetime run count, from the response β not the sample's length. */total: number;+ /**+ * Lifetime COMPLETED-run count. From the response's `status_counts` when+ * the service reports it; an older service leaves that out, so the sample+ * stands in exactly when it holds the whole history (`total` β€ its length)+ * and the count is null β unknowable, never guessed β otherwise.+ */+ completedTotal: number | null;latestRun: AutomationRun | null;/** Newest-first sample used by the list sparkline (same page as the summary). */recentRuns: AutomationRun[];@@ -84,6 +91,15 @@ export function summarizeAutomationRuns((run) => run.status === AutomationRunStatus.COMPLETED,).length;+ let completedTotal: number | null;+ if (response.status_counts) {+ completedTotal = response.status_counts[AutomationRunStatus.COMPLETED] ?? 0;+ } else if (response.total <= response.runs.length) {+ completedTotal = completed;+ } else {+ completedTotal = null;+ }+const durations = terminal.flatMap((run) => {if (!run.completed_at) return [];const ms =@@ -93,6 +109,7 @@ export function summarizeAutomationRuns(return {total: response.total,+ completedTotal,latestRun: response.runs[0] ?? null,recentRuns: response.runs,recentSuccessRate:diff --git a/src/mocks/automation-handlers.ts b/src/mocks/automation-handlers.tsindex 2e34b6dc8b..d88f7b4674 100644--- a/src/mocks/automation-handlers.ts+++ b/src/mocks/automation-handlers.ts@@ -216,10 +216,15 @@ export const AUTOMATION_HANDLERS = [const offset = Number(url.searchParams.get("offset") ?? "0");const allRuns = MOCK_AUTOMATION_RUNS[id] ?? [];const page = allRuns.slice(offset, offset + limit);+ const statusCounts: AutomationRunsResponse["status_counts"] = {};+ for (const run of allRuns) {+ statusCounts[run.status] = (statusCounts[run.status] ?? 0) + 1;+ }const response: AutomationRunsResponse = {runs: page,total: allRuns.length,+ status_counts: statusCounts,};return HttpResponse.json(response);diff --git a/src/mocks/automations.mock.ts b/src/mocks/automations.mock.tsindex 95441f3da9..c252b0f8a8 100644--- a/src/mocks/automations.mock.ts+++ b/src/mocks/automations.mock.ts@@ -145,6 +145,11 @@ export const MOCK_AUTOMATIONS_RESPONSE: AutomationsResponse = {plugins: ["GitHub"],notification: "GitHub PR comment",last_triggered_at: daysAgo(0),+ // Template provenance, as the setup flow stores it. The other mock+ // automations stay without one to exercise the no-statement path.+ preset_metadata: {+ template: { id: "github-pr-reviewer", version: "1.0.0", config: {} },+ },},{id: "a1000000-0000-0000-0000-000000000007",diff --git a/src/types/automation.ts b/src/types/automation.tsindex 504cbf9548..04efe9e669 100644--- a/src/types/automation.ts+++ b/src/types/automation.ts@@ -43,11 +43,18 @@ export interface Automation {notification?: string;timezone?: string;last_triggered_at?: string | null;+ /**+ * Service-owned preset state, returned verbatim. The GUI reads only the+ * `template` provenance block inside it ({id, version, config}, written at+ * setup time), and only through the guarded helper in+ * `#/utils/automation-catalog`.+ */+ preset_metadata?: Record<string, unknown> | null;}export type AutomationSpec = Omit<Automation,- "id" | "created_at" | "updated_at" | "last_triggered_at"+ "id" | "created_at" | "updated_at" | "last_triggered_at" | "preset_metadata">;/** The envelope constants come from the interface manifest's import/export spec. */@@ -115,6 +122,13 @@ export interface AutomationRun {export interface AutomationRunsResponse {runs: AutomationRun[];total: number;+ /**+ * Lifetime run counts by status, unaffected by pagination. Sparse β a+ * status with no runs has no key, so when the field is present a missing+ * key means zero. Absent entirely when the automation service is older+ * than the release that added it.+ */+ status_counts?: Partial<Record<AutomationRunStatus, number>>;}export type ActivityLogExportFormat = "json" | "csv";diff --git a/src/utils/automation-catalog.ts b/src/utils/automation-catalog.tsindex a62944be2d..aa7ffbeebe 100644--- a/src/utils/automation-catalog.ts+++ b/src/utils/automation-catalog.ts@@ -1,10 +1,15 @@-import type { RecommendedAutomation } from "@openhands/extensions/automations";+import {+ AUTOMATION_CATALOG,+ type RecommendedAutomation,+} from "@openhands/extensions/automations";import {SKILLS_CATALOG,type SkillCatalogEntry,} from "@openhands/extensions/skills";import type { LucideIcon } from "lucide-react";import { MANIFEST_ICON_BY_SLUG } from "#/components/features/manifest/manifest-icons";+import { interpolateValues } from "#/manifests/manifest-template";+import type { Automation } from "#/types/automation";/*** Reading a published automation catalog entry.@@ -91,3 +96,90 @@ export function getAutomationLaunchPrompt(`Set up the ${automation.name} automation`);}++const CATALOG_ENTRY_BY_ID = new Map<string, RecommendedAutomation>(+ AUTOMATION_CATALOG.map((entry) => [entry.id, entry]),+);++/** Rejects markup the same way the catalog schema's copy rule does. */+const MARKUP_PATTERN = /<[A-Za-z/!]/;++/** Every `{{` an impact phrase opens must be the count placeholder. */+const FOREIGN_PLACEHOLDER_PATTERN = /\{\{(?!count\}\})/;++const COUNT_PLACEHOLDER = "{{count}}";++interface AutomationImpactCopy {+ one: string;+ other: string;+}++function isImpactPhrase(value: unknown): value is string {+ return (+ typeof value === "string" &&+ value.length > 0 &&+ !MARKUP_PATTERN.test(value) &&+ !FOREIGN_PLACEHOLDER_PATTERN.test(value)+ );+}++/**+ * The entry's `impact` value statement, or null when it declares none this+ * host can honor. The catalog is published elsewhere, so the field is read+ * off the raw entry and validated here rather than trusted from the package+ * types β which also keeps this module compiling against a pinned package+ * that predates the field. A basis other than `completed-runs` is a counter+ * this host does not know how to compute, so it renders nothing rather than+ * a number the phrase was not written for.+ */+function readImpactCopy(+ entry: RecommendedAutomation,+): AutomationImpactCopy | null {+ const { impact } = entry as unknown as Record<string, unknown>;+ if (typeof impact !== "object" || impact === null) return null;+ const { basis, one, other } = impact as Record<string, unknown>;+ if (basis !== "completed-runs") return null;+ if (!isImpactPhrase(one) || !isImpactPhrase(other)) return null;+ if (!other.includes(COUNT_PLACEHOLDER)) return null;+ return { one, other };+}++/**+ * The catalog entry an installed automation was created from, via the+ * `template` provenance its setup stored β the only join back to the catalog.+ * Null for automations without provenance: imports, agent-built ones, and+ * entries whose setup publishes no version.+ */+function getAutomationTemplateEntry(+ automation: Automation,+): RecommendedAutomation | null {+ const metadata = automation.preset_metadata;+ if (typeof metadata !== "object" || metadata === null) return null;+ const { template } = metadata as Record<string, unknown>;+ if (typeof template !== "object" || template === null) return null;+ const { id } = template as Record<string, unknown>;+ if (typeof id !== "string" || id.length === 0) return null;+ return CATALOG_ENTRY_BY_ID.get(id) ?? null;+}++/**+ * The value statement an automation card shows for its completed runs, or+ * null when there is nothing defensible to say: no template provenance, no+ * honored `impact` declaration, an unknown count (older service with more+ * history than the sample), or a count of zero β absence, never a zero-value+ * claim. Provenance persists across prompt edits, so a reworked automation+ * keeps its template's phrase; the phrases are run-shaped, which keeps them+ * true for as long as the automation runs at all.+ */+export function resolveAutomationImpactStatement(+ automation: Automation,+ completedTotal: number | null,+): string | null {+ if (completedTotal === null || completedTotal < 1) return null;+ const entry = getAutomationTemplateEntry(automation);+ if (!entry) return null;+ const copy = readImpactCopy(entry);+ if (!copy) return null;+ const phrase = completedTotal === 1 ? copy.one : copy.other;+ return interpolateValues(phrase, { count: completedTotal.toLocaleString() });+}