# Agent tasks

> Background coding-agent task hub with task launcher, status filters (All, Running, Ready, Merged), cancel and Open PR actions.

- Kind: block · Category: Agents · Interactivity: script
- Install: `npx shadcn@latest add @haze/agent-tasks`
- File: `src/components/haze/blocks/agent-tasks.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/agent-tasks

## Use when
- Launching and tracking multiple asynchronous coding-agent runs across branches
- Filtering background tasks by lifecycle state with quick Cancel and Open PR controls

## Avoid when
- Inspecting a single agent's step-by-step diff approval; use agent-run

## Alternatives
- [agent-run](https://hazeui.com/blocks/agent-run.md)
- [kanban-board](https://hazeui.com/ui/kanban-board.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-agent-tasks" | no | Unique prefix for form and heading IDs. |
| heading | `string` | "Background agent tasks" | no | Hub heading. |
| tasks | `AgentTask[]` | 3 demo tasks | no | Background tasks with repo, branch, status and progress. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Status filter tabs expose aria-selected and dynamically filter the task list without page reloads.
- Starting, cancelling or opening a PR announces the result in a polite role="status" element.
- Key Tab: Move across status tabs, task launcher inputs, Cancel and Open PR buttons
- Key Enter / Space: Filter tasks, launch a new background task, cancel a run or open a PR

## Agent prompts

### Install and use

Install the Haze UI block "Agent tasks" with `npx shadcn@latest add @haze/agent-tasks`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AgentTasks from "@/components/haze/blocks/agent-tasks.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/agent-tasks.md

### Customize with real content

Adapt the Haze agent-tasks block for our product. Replace the demo values of these props with our real content: id, heading, tasks, class. Keep the layout, the heading level rules and these accessibility details: Status filter tabs expose aria-selected and dynamically filter the task list without page reloads. Starting, cancelling or opening a PR announces the result in a polite role="status" element. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using agent-tasks, check it fits: use it when launching and tracking multiple asynchronous coding-agent runs across branches; filtering background tasks by lifecycle state with quick cancel and open pr controls. Avoid it when inspecting a single agent's step-by-step diff approval; use agent-run. Alternatives: @haze/agent-run, @haze/kanban-board.

## Example requests that should lead here
- Create a background coding-agent task hub with repo/branch launcher, status filter tabs and Open PR buttons

## Source

```astro
---
import { Bot, GitBranch, GitPullRequest, Play, XCircle } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface AgentTask {
  id: string;
  title: string;
  repo: string;
  branch: string;
  status: "Running" | "Ready" | "Merged";
  progress: number;
  summary: string;
}

interface Props {
  id?: string;
  heading?: string;
  tasks?: AgentTask[];
  class?: string;
}

const {
  id = "haze-agent-tasks",
  heading = "Background agent tasks",
  tasks = [
    { id: "tk1", title: "Add keyboard navigation tests for command palette", repo: "haze/ui", branch: "agent/palette-e2e", status: "Running", progress: 68, summary: "Running Playwright suite (14/21 specs)" },
    { id: "tk2", title: "Migrate dark contrast tokens to OKLCH scale", repo: "haze/ui", branch: "agent/oklch-tokens", status: "Ready", progress: 100, summary: "4 files changed · 148/148 contrast pairs pass" },
    { id: "tk3", title: "Generate sitemap.xml and llms.txt on build", repo: "haze/docs", branch: "agent/seo-gen", status: "Merged", progress: 100, summary: "Merged in PR 484 · 261 URLs indexed" },
  ],
  class: className,
} = Astro.props;
const filters = ["All", "Running", "Ready", "Merged"] as const;
---

<section aria-labelledby={`${id}-title`} data-haze-agent-tasks class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-4xl rounded-2xl border border-border bg-card p-5 sm:p-6">
    <div class="flex flex-wrap items-center justify-between gap-3">
      <div class="flex items-center gap-2">
        <Bot class="size-4 text-muted-foreground" aria-hidden="true" />
        <h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">{heading}</h2>
      </div>
      <div role="tablist" aria-label="Filter tasks by status" class="inline-flex rounded-lg border border-frame bg-muted p-0.5">
        {
          filters.map((f, idx) => (
            <button
              type="button"
              role="tab"
              data-at-filter={f}
              aria-selected={idx === 0 ? "true" : "false"}
              class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground aria-selected:bg-background aria-selected:text-foreground aria-selected:shadow-key focus-visible:outline-2 focus-visible:outline-ring"
            >
              {f}
            </button>
          ))
        }
      </div>
    </div>

    <form data-at-form class="mt-4 grid gap-2 rounded-xl border border-border bg-muted/40 p-3 sm:grid-cols-[minmax(0,1fr)_auto_auto]">
      <label for={`${id}-new`} class="sr-only">Describe a coding task</label>
      <input id={`${id}-new`} data-at-input type="text" placeholder="Kick off a background task on haze/ui…" class="h-9 min-w-0 rounded-lg border border-frame-input bg-field px-3 text-xs text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
      <label for={`${id}-branch`} class="sr-only">Target branch</label>
      <select id={`${id}-branch`} class="h-9 rounded-lg border border-frame-input bg-field px-2.5 font-mono text-xs text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground">
        <option>main</option>
        <option>release/2.8</option>
      </select>
      <button type="submit" class="inline-flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
        <Play class="size-3.5" aria-hidden="true" />
        Start task
      </button>
    </form>

    <ul role="list" data-at-list class="mt-4 space-y-2.5">
      {
        tasks.map((task) => (
          <li data-at-row data-status={task.status} class="rounded-xl border border-border bg-muted/40 p-4">
            <div class="flex flex-wrap items-start justify-between gap-2">
              <div class="min-w-0">
                <div class="flex flex-wrap items-center gap-2">
                  <span class={cn(
                    "rounded-md border px-2 py-0.5 text-[0.6875rem]/4 font-medium",
                    task.status === "Running" ? "border-frame bg-muted text-foreground" :
                    task.status === "Ready" ? "border-frame-success bg-success/10 text-success" :
                    "border-frame bg-card text-muted-foreground",
                  )}>{task.status}</span>
                  <span class="inline-flex items-center gap-1 font-mono text-[0.6875rem] text-muted-foreground">
                    <GitBranch class="size-3" aria-hidden="true" />
                    {task.repo} · {task.branch}
                  </span>
                </div>
                <h3 class="mt-1.5 text-sm/5 font-medium text-foreground">{task.title}</h3>
                <p class="mt-0.5 text-xs/5 text-muted-foreground">{task.summary}</p>
              </div>
              <div class="flex shrink-0 items-center gap-1.5">
                {task.status === "Running" && (
                  <button type="button" data-at-cancel class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-muted-foreground hover:border-destructive-border hover:text-destructive focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
                    <XCircle class="size-3.5" aria-hidden="true" />
                    Cancel
                  </button>
                )}
                {task.status === "Ready" && (
                  <button type="button" data-at-pr class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-3 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
                    <GitPullRequest class="size-3.5" aria-hidden="true" />
                    Open PR
                  </button>
                )}
              </div>
            </div>
            {task.status === "Running" && (
              <div class="mt-3 h-1.5 w-full overflow-hidden rounded-full bg-muted">
                <div class="h-full rounded-full bg-primary" style={`width: ${task.progress}%`}></div>
              </div>
            )}
          </li>
        ))
      }
    </ul>

    <p data-at-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initAgentTasks() {
    document.querySelectorAll<HTMLElement>("[data-haze-agent-tasks]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const list = root.querySelector<HTMLUListElement>("[data-at-list]");
      const input = root.querySelector<HTMLInputElement>("[data-at-input]");
      const status = root.querySelector<HTMLElement>("[data-at-status]");
      let activeFilter = "All";

      const applyFilter = () => {
        root.querySelectorAll<HTMLElement>("[data-at-row]").forEach((row) => {
          row.hidden = activeFilter !== "All" && row.dataset.status !== activeFilter;
        });
      };

      root.querySelectorAll<HTMLButtonElement>("[data-at-filter]").forEach((tab) => {
        tab.addEventListener("click", () => {
          activeFilter = tab.dataset.atFilter ?? "All";
          root.querySelectorAll<HTMLButtonElement>("[data-at-filter]").forEach((t) => t.setAttribute("aria-selected", String(t === tab)));
          applyFilter();
        });
      });

      root.querySelector<HTMLFormElement>("[data-at-form]")?.addEventListener("submit", (ev) => {
        ev.preventDefault();
        const title = input?.value.trim();
        if (!title || !list) return;
        const li = document.createElement("li");
        li.setAttribute("data-at-row", "");
        li.dataset.status = "Running";
        li.className = "rounded-xl border border-border bg-muted/40 p-4";
        li.innerHTML = `<div class="flex flex-wrap items-start justify-between gap-2"><div><span class="rounded-md border border-frame bg-muted px-2 py-0.5 text-[0.6875rem]/4 font-medium text-foreground">Running</span><h3 class="mt-1.5 text-sm/5 font-medium text-foreground"></h3><p class="mt-0.5 text-xs/5 text-muted-foreground">Queued on haze/ui · starting container</p></div></div>`;
        li.querySelector("h3")!.textContent = title;
        list.prepend(li);
        if (input) input.value = "";
        applyFilter();
        if (status) status.textContent = `Started background task "${title}".`;
      });

      list?.addEventListener("click", (ev) => {
        const target = ev.target as HTMLElement | null;
        const cancel = target?.closest<HTMLButtonElement>("[data-at-cancel]");
        if (cancel) {
          cancel.closest("[data-at-row]")?.remove();
          if (status) status.textContent = "Running task cancelled.";
          return;
        }
        const pr = target?.closest<HTMLButtonElement>("[data-at-pr]");
        if (pr) {
          pr.textContent = "PR opened";
          pr.disabled = true;
          if (status) status.textContent = "Pull request opened for ready task.";
        }
      });
    });
  }
  initAgentTasks();
  document.addEventListener("astro:page-load", initAgentTasks);
</script>
```
