agent-swarm.devagent-swarm.dev
Playbooks

PR Timeline App

One Swarm App that puts every open and recently merged pull request on a single timeline, with its CI, merge queue, build and deploy, the swarm tasks working on it, and the workflows it triggered. Built from one script, one HTML page and one App definition, with a prompt you can hand to your own lead.

Every PR, its CI, and the agents on it, on one timeline.

GitHub shows one pull request at a time. The swarm dashboard shows one task at a time. When several agents ship PRs in parallel, the questions you ask are across both: which PRs are ready but not queued, what is still running CI, which agent owns the PR that conflicts, and when will a merge reach production.

The PR timeline answers them on one screen. It is a Swarm App with no tables of its own: a script reads GitHub and the swarm database, caches the result, and a custom HTML page draws it.

PR timeline: the agents strip on top, then PRs grouped into Ready, not queued and Checks running, each with a lane of CI bars and agent task markers against a time axis

What it shows

  • One row per PR, grouped into sections by what the PR needs next: shipping, merge queue, ready but not queued, checks running, failing, in review, conflicts, agent working with no CI yet, drafts, shipped, and quiet. Quiet holds PRs with no activity for 72 hours and open PRs that match no other section.
  • A lane per row on a shared time axis: check runs per workflow, merge queue entry and position, the build on the merge commit, and the deployment that put it live. Running checks get an ETA from past job durations.
  • A task track under each lane: the swarm tasks linked to the PR, coloured by kind (implement, review, fix, lead), each linking to its task and session.
  • A detail panel per PR: the CI job graph by stage, the related swarm tasks, and the swarm workflow runs the PR triggered, with their steps as a waterfall.
  • An agents strip: who is working now, on which task, and on which PR.

Search, a repo filter, zoom and pan, keyboard navigation, and light and dark themes are page code. Skip them in a first version.

Prerequisites

  • Swarm Apps and HTML pages (Pages API). The App embeds the page with a PageFrame element.
  • Scripts runtime with db_query and KV access. Every agent can run read-only SQL on the swarm database.
  • A GitHub token for the script, stored as a secret and bound with a credential binding for api.github.com. The script sends Authorization: Bearer [REDACTED:GITHUB_TOKEN] and the egress layer swaps in the real value, so the token never reaches the script or the browser.
  • The GitHub integration (recommended). Tasks it creates from PR events carry vcsRepo and vcsNumber, which is the cleanest link between a task and a PR.

Architecture

PieceBuilt fromJob
pr-timeline-apiA script with an op argumenttimeline (all PRs), detail (CI jobs of one PR), agents, workflows (swarm runs of one PR)
Timeline pageOne self-contained HTML pageDraws the board, calls the script through window.appContext.action("api", { op, ... })
PR timeline AppAn App definition with one page holding a PageFrame, and one script action named apiHosts the page in the dashboard and allowlists the one action it may call

The App definition is small. It has no tables, but models is required, so it stays an empty object. actions on the PageFrame is the allowlist: the page can call api and nothing else, and it holds no credential.

{
  "models": {},
  "actions": { "api": { "kind": "script", "scriptId": "<script id>" } },
  "pages": {
    "main": {
      "title": "PR timeline",
      "root": "root",
      "elements": {
        "root": { "type": "Stack", "props": { "fill": true }, "children": ["frame"] },
        "frame": {
          "type": "PageFrame",
          "props": { "id": "timeline", "fill": true, "pageId": "<page id>", "actions": ["api"] }
        }
      }
    }
  },
  "defaultPage": "main"
}

Data sources

DataSourceHow
Pull requestsGitHub GraphQL searchOpen PRs in the organization (up to 100) plus PRs merged in the last 48 hours (up to 60). Fetch ids first, then full fields in aliased batches of 5 PRs: one search page with check rollups times out at GitHub.
CIThe PR's head commit check runsGrouped by workflow run, newest attempt per workflow. The merge queue entry adds position, enqueue time, GitHub's estimated time to merge and the queue commit's checks.
Build and deployThe merge commitpush workflow runs on the merge commit are the build. The deploy comes from a separate query: the last 40 deployments of each repository with a merged PR, matched to the PR by repository and merge SHA (newest status wins).
Swarm tasksagent_tasks via db_queryTasks updated in the last 4 days whose vcsRepo and vcsNumber match the PR, or whose task, progress or output text contains the PR URL. Walk parentTaskId to the root for the session link; join workflow_runs for the workflow name.
Swarm workflowsworkflow_runs and workflow_run_stepsRuns whose triggerData names the PR number and repo, inside the PR's lifetime (at most 7 days: the scan reads webhook payloads), plus runs that created a linked task.
Agentsagents and their open tasksStatus and current task, polled every 20 seconds.

Caching

A full GitHub rebuild takes about 10 seconds. Once a usable snapshot exists (one in this browser younger than seven days, or one in KV), the page does not wait for one.

  1. Browser first. When this browser has a saved snapshot younger than seven days, the page paints it from localStorage at once. It ignores an older one.
  2. Server snapshot. op: "timeline", mode: "cached" returns the KV snapshot at any age, with ageMs and a 45 second ttlMs. When a KV snapshot exists, it answers in under a second. When none exists, the same call rebuilds from GitHub first.
  3. Revalidate. When the snapshot is older than the TTL, the page calls timeline without mode. The script rebuilds from GitHub, unless a building key in KV says another call is already rebuilding: then it returns the stale snapshot with revalidating: true. A Refresh button passes force: true.
  4. Keep it warm. Snapshots live 24 hours in KV, so a new browser paints from KV while someone opened the page in the last day. Freshness comes from the snapshot's timestamp, not the expiry. The page polls every 60 seconds while visible.
  5. Prefetch details. Hovering a row prefetches its detail, so the job graph opens from memory.

Cold cache. With no usable browser snapshot (empty storage, or one seven days old or more) and no KV snapshot (the first ever load, or 24 hours after the last one), the page shows placeholder rows until the full GitHub rebuild returns, about 10 seconds.

The same KV namespace keeps the last 25 successful durations per CI job. The ETA of a running check is its start plus the median.

Swarm KV has no compare-and-set. Two callers can still rebuild in the same second. Both write the same data, so it is harmless here, but do not reuse this lock for anything that must run once.

Build it in your swarm

Build it in this order. Each step is usable on its own.

  1. Store the token. Save a GitHub token with read access to pull requests, checks, deployments and Actions as a secret, then add a credential binding with allowedHosts: ["api.github.com"] and the header Authorization: Bearer [REDACTED:GITHUB_TOKEN]. Run a one-line script that queries viewer { login } to prove it works.
  2. Write the timeline op. One script with three GitHub reads: a light search that returns only repository names and PR numbers, then the heavy fields (head, merge queue and merge commit check rollups) in aliased queries of 5 PRs each. One search page with check rollups times out at GitHub. Deployments are the third, separate read: one aliased repository { deployments(last: 40) } per repository with a merged PR, joined to PRs by repository and merge SHA. Add one db_query for linked tasks. Return plain JSON: PRs with their segments (checks, queue, build, deploy) and tasks. Run it with script-run until the output looks right.
  3. Start from a custom page. Create an HTML page that calls window.appContext.action("api", { op: "timeline" }) and draws one row per PR with absolutely positioned bars on a time axis. Iterate locally: save one snapshot to a file and serve the page with a stub appContext that returns it.
  4. Wrap it in an App. Create the App with the definition above, open /apps/<id>, and check that the page loads live data.
  5. Add the cache. Write the snapshot to KV, add mode: "cached", the building key and the page's localStorage paint.
  6. Add depth. The detail op for the job graph, agents for the strip, workflows for the swarm runs tab. Then sections, search and zoom in the page.

Message to your lead

Build me a Swarm App called PR timeline: every open PR and every PR merged in the last 48 hours across our GitHub organization <org>, on one horizontal timeline. Back it with one script action named api that reads GitHub GraphQL through a credential binding for api.github.com (never put the token in the script or the page) and the swarm database through read-only db_query. Per PR, show check runs grouped by workflow, the merge queue entry, the build on the merge commit and the deployment on the merge SHA. Under each PR, show the swarm tasks linked to it (vcsRepo and vcsNumber, or the PR URL in the task text) with links to the task and its session, and in a detail panel the CI job graph and the swarm workflow runs the PR triggered. Group rows by what the PR needs next: shipping, merge queue, ready but not queued, checks running, failing, in review, conflicts, agent working with no CI yet, drafts, shipped, and quiet (no activity for 72 hours, or open with no other match). Fetch PRs in two phases: a search for repository names and numbers, then check rollups in aliased batches of 5 PRs. Fetch deployments separately per repository with merged PRs and match them by repository and merge SHA. Draw it as a custom HTML page inside a PageFrame. Cache the snapshot in KV for 45 seconds with stale-while-revalidate and one rebuilder at a time. Send me the App link and a screenshot when it loads real data.

Lessons

  • Batch GitHub queries small. A search page that also asks for check rollups returns 504. Fetch ids, then 5 PRs per aliased query.
  • Link tasks two ways. vcsRepo and vcsNumber cover tasks the GitHub integration created. A PR URL in the task text covers tasks an agent created by hand.
  • Bound the workflow scan. triggerData holds whole webhook payloads. Scanning 30 days of runs times out; the PR's own lifetime, capped at 7 days, does not.
  • Label estimates. ETAs and "next live" are medians of past runs, not promises. Say so in the tooltip.
  • Keep zoom out of render. Position bars with CSS variables and change only those on zoom. Re-rendering a few hundred rows on every zoom step made each click take 250 to 330 ms.

On this page