# CI Checks

> A branch's checks with their failures and Re-run.

Page: https://uicontext.com/docs/components/ci-checks

Group: Agents.

## When to use

A branch's checks with their failures and Re-run. Use [Branch Strip](https://uicontext.com/docs/components/branch-strip.md) instead when you need the branch's next step.

## Usage

```ts
import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"
import { type CheckRun, Checks } from "./ui/uicontext/components/Checks.ts"

const Message = UiSchema.TaggedEnum({
	RequestedRerunChecks: { check: Schema.String },
	RequestedAutoFixChecks: { on: Schema.Boolean },
	RequestedAutoMergeChecks: { on: Schema.Boolean },
})

// the code host owns the checks; answer a re-run through `outcome` with request `rerun:<name>`
export const BranchChecks = (h: Html.H<typeof Message.Type>, checks: ReadonlyArray<CheckRun>, auto: { readonly fix: boolean; readonly merge: boolean }, outcome: Outcome | null) =>
	Checks(h, {
		props: { id: "512", checks, autoFix: auto.fix, autoMerge: auto.merge, can: ["rerun", "auto"], outcome },
		onEmit: {
			RequestedRerun: ({ check }) => Message.RequestedRerunChecks({ check }),
			RequestedAutoFix: ({ on }) => Message.RequestedAutoFixChecks({ on }),
			RequestedAutoMerge: ({ on }) => Message.RequestedAutoMergeChecks({ on }),
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A failed check, re-run

Turn on Auto-merge, then Re-run the failed check: it runs for a moment, passes, and the branch merges by itself.

```ts title="src/demo.ts" source="www/src/examples/ci-checks/demo.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"
import { CheckRun, Checks, checksSummary } from "./ui/uicontext/components/Checks.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const Message = UiSchema.TaggedEnum({
	RequestedRerunChecks: { check: Schema.String },
	CompletedRerun: { check: Schema.String },
	RequestedAutoFixChecks: { on: Schema.Boolean },
	RequestedAutoMergeChecks: { on: Schema.Boolean },
})

// stands in for CI: two seconds, then it passes
const Rerun = Command.make("RerunCheck", { args: { check: Schema.String } }, ({ check }) =>
	Effect.sleep("2 seconds").pipe(Effect.as(Message.CompletedRerun({ check }))))

const styles = stylex.create({
	frame: { display: "grid", gap: space.md, inlineSize: "min(100%, 30rem)" },
	merged: { margin: 0, fontSize: font.sm, fontWeight: 500, color: color.done },
})

const initial: ReadonlyArray<CheckRun> = [
	{ name: "Typecheck", status: "passed", required: true, duration: 41_000 },
	{ name: "Lint", status: "passed", required: true, duration: 18_000 },
	{ name: "Unit tests", status: "failed", required: true, duration: 96_000, description: "InvoicesTable › keeps the page after sorting", href: "#unit-tests" },
	{ name: "Preview deploy", status: "pending" },
	{ name: "End-to-end", status: "skipped", description: "Runs on release branches only" },
]

export const BranchChecks = Html.component({
	name: "BranchChecks",
	model: Schema.Struct({ checks: Schema.Array(CheckRun), autoFix: Schema.Boolean, autoMerge: Schema.Boolean, merged: Schema.Boolean, outcome: Schema.NullOr(Outcome) }),
	message: Message,
}).make({
	init: () => ({ checks: initial, autoFix: false, autoMerge: false, merged: false, outcome: null }),
	update: {
		RequestedRerunChecks: ($, { check }) => $.evolve({
			outcome: { _tag: "Pending", request: `rerun:${check}` },
			checks: (cs) => cs.map((c) => (c.name === check ? { name: c.name, status: "pending" as const, required: true } : c)),
		}).run(Rerun.make({ check })),
		CompletedRerun: ($, { check }) => {
			const checks = $.model.checks.map((c): CheckRun => (c.name === check || c.status === "pending"
				? { name: c.name, status: "passed", duration: 88_000, ...(c.required === undefined ? {} : { required: c.required }) }
				: c))
			const green = checksSummary(checks.filter((c) => c.required === true)).state === "passed"
			return $.evolve({ checks, outcome: { _tag: "Accepted", request: `rerun:${check}` }, merged: green && $.model.autoMerge })
		},
		RequestedAutoFixChecks: ($, { on }) => $.evolve({ autoFix: on }),
		RequestedAutoMergeChecks: ($, { on }) => $.evolve({ autoMerge: on, merged: on && checksSummary($.model.checks.filter((c) => c.required === true)).state === "passed" }),
	},
	view: (h, model) => h.div.attrs(sx(styles.frame)).children(
		Checks(h, {
			props: { id: "512", checks: model.checks, autoFix: model.autoFix, autoMerge: model.autoMerge, can: model.merged ? [] : ["rerun", "auto"], outcome: model.outcome, label: "Checks on #512" },
			onEmit: {
				RequestedRerun: ({ check }) => Message.RequestedRerunChecks({ check }),
				RequestedAutoFix: ({ on }) => Message.RequestedAutoFixChecks({ on }),
				RequestedAutoMerge: ({ on }) => Message.RequestedAutoMergeChecks({ on }),
			},
		}),
		model.merged && h.p.attrs({ role: "status", ...sx(styles.merged) }).children("Merged into main."),
	),
})
```

## API reference

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | Names the change these checks ran on, in events |
| `checks` (required) | `CheckRun[]` | — |
| `autoFix` | `boolean` | A failed check goes back to the agent to fix; leave out for no switch |
| `autoMerge` | `boolean` | Merge once every required check passes; leave out for no switch |
| `can` (required) | `("rerun" \| "auto")[]` | "rerun" offers Re-run on a failed check; "auto" lets the person flip the switches |
| `outcome` | `Outcome \| null` | The app's answer to the last request: "rerun:\<check>", "auto-fix", "auto-merge" |
| `label` | `string` | "CI checks" by default |
| `agentId` | `string` | — |
| `locale` | `string` | — |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedRerun` | `{ id: string; check: string }` | Run a failed check again; answer with outcome `rerun:<check>` |
| `RequestedAutoFix` | `{ id: string; on: boolean }` | — |
| `RequestedAutoMerge` | `{ id: string; on: boolean }` | — |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedRerun` | Run a failed check again, by its name |
| `ToggledAutoFix` | Turn on or off sending failed checks back to the agent |
| `ToggledAutoMerge` (asks first) | Turn on or off merging once every required check passes |

## Keyboard and accessibility

- The counts are a description list; each check says its status in words beside its mark.
- Re-run is a button named for its check, and the switches are labelled. Auto-merge is consequential for agents: a person confirms.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/ci-checks
```

With npm: `npx shadcn@latest add checkfu/uicontext/ci-checks`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/ci-checks`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/ci-checks`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Callout.ts`
- `src/ui/uicontext/components/Checks.ts`
- `src/ui/uicontext/components/Diff.ts`
- `src/ui/uicontext/components/DiffStat.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/PullRequest.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/StatusBadge.ts`
- `src/ui/uicontext/components/Switch.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/ToolCallGroup.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Run.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Checks.ts](https://github.com/checkfu/uicontext/blob/main/src/Checks.ts)

## Used in

- [Agent studio](https://uicontext.com/blocks/agent-studio.md)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
