| 1 | import { |
| 2 | Activity as ActivityIcon, |
| 3 | ArrowDownLeft, |
| 4 | ArrowRight, |
| 5 | ArrowUpRight, |
| 6 | Bot, |
| 7 | Brain, |
| 8 | Code2, |
| 9 | GitBranch, |
| 10 | GitCommitHorizontal, |
| 11 | GitMerge, |
| 12 | Hand, |
| 13 | HeartPulse, |
| 14 | Loader2, |
| 15 | Lock, |
| 16 | Network, |
| 17 | Package as PackageGlyph, |
| 18 | Pin, |
| 19 | Rocket, |
| 20 | RotateCw, |
| 21 | } from "lucide-react"; |
| 22 | import { type ReactNode, Suspense } from "react"; |
| 23 | import { Await, Form, Link } from "react-router"; |
| 24 | |
| 25 | import { |
| 26 | type AgentRun, |
| 27 | type G1tEvent, |
| 28 | type Memory, |
| 29 | type PackageSummary, |
| 30 | type Project, |
| 31 | type Pull, |
| 32 | RUN_KIND_LABEL, |
| 33 | isActiveRun, |
| 34 | workOwner, |
| 35 | } from "@g1t/contracts"; |
| 36 | |
| 37 | import type { Route } from "./+types/overview"; |
| 38 | import { host, StatusDot } from "../../components/deploy"; |
| 39 | import { CheckBadge } from "../../components/checks"; |
| 40 | import { Elapsed, formatCost, useLiveRefresh } from "../../components/agents"; |
| 41 | import { ActivityFeed, DeployStrip, Meter, NeedsList, Panel, Quiet, Unavailable, percent } from "../../components/mission"; |
| 42 | import { type ActiveBranch, ActiveBranches } from "../../components/branches"; |
| 43 | import { ProductionChecklist } from "../../components/checklist"; |
| 44 | import { PackageIcon } from "../../components/package-icon"; |
| 45 | import { Skeleton, SkeletonRows } from "../../components/ui/skeleton"; |
| 46 | import { ProductionShot } from "../../components/production-shot"; |
| 47 | import { GithubLinkStrip } from "../../components/github"; |
| 48 | import { githubApp } from "../../lib/github.server"; |
| 49 | import { Avatar, ButtonLink, CopyLine, SubmitButton, TimeAgo } from "../../components/ui"; |
| 50 | import { ChangeSize } from "../../components/work"; |
| 51 | import { |
| 52 | type ActivityItem, |
| 53 | type Need, |
| 54 | type PipelineStage, |
| 55 | PIPELINE, |
| 56 | TIME, |
| 57 | ageBuckets, |
| 58 | eventItem, |
| 59 | firstPassRate, |
| 60 | groupActivity, |
| 61 | passRate, |
| 62 | pipelineStage, |
| 63 | queuedNumbers, |
| 64 | rankNeeds, |
| 65 | stuckMinutes, |
| 66 | } from "../../lib/mission"; |
| 67 | import { agentWasAssigned, hasInstructions, productionChecklist, releaseChecklist } from "../../lib/checklist"; |
| 68 | import { ECOSYSTEM_LABEL, installCommands } from "../../lib/packages"; |
| 69 | import { PUBLISH_GUIDES, hasRelease, libraryPackages, packageName, packagePath, publishGuide } from "../../lib/project-kind"; |
| 70 | import { actions, agents, deployments, events as eventLog, packages, projects, repos, work } from "../../lib/services.server"; |
| 71 | import { madeByG1t } from "../../lib/opened-by"; |
| 72 | import { assertSameOrigin, getViewer, requireUser } from "../../lib/session.server"; |
| 73 | import { accessTo, countsFor, refusal, repoFor } from "../../lib/access.server"; |
| 74 | import { shotVersion } from "./production-screenshot"; |
| 75 | import { cloneUrl, useAddresses } from "../../lib/addresses"; |
| 76 | import { readBranches } from "../../lib/branches.server"; |
| 77 | |
| 78 | const MAX_LANDED = 6; |
| 79 | /** Branches read for the Active branches list, and shown. */ |
| 80 | const BRANCHES_READ = 10; |
| 81 | const BRANCHES_SHOWN = 5; |
| 82 | /** A library's packages shown on its overview; the rest are a link away. */ |
| 83 | const PACKAGES_SHOWN = 3; |
| 84 | |
| 85 | /** |
| 86 | * The overview streams: the layout's header and tabs (one repository |
| 87 | * lookup, one project) go out at once with a skeleton below them, and |
| 88 | * everything here, seventeen calls across six services, follows in the |
| 89 | * same response as it settles. Crawlers wait for all of it |
| 90 | * (entry.server.tsx). Before, the first byte waited on the slowest of them. |
| 91 | */ |
| 92 | export function loader({ params, context }: Route.LoaderArgs) { |
| 93 | return { overview: overviewData({ params, context }) }; |
| 94 | } |
| 95 | |
| 96 | async function overviewData({ params, context }: Pick<Route.LoaderArgs, "params" | "context">) { |
| 97 | const viewer = getViewer(context); |
| 98 | const path = { namespace: params.owner, name: params.repo }; |
| 99 | const ref = { workspace: params.owner, slug: params.repo }; |
| 100 | const now = Date.now(); |
| 101 | // A section whose service fails shows its own empty state; the page stays up. |
| 102 | const soft = <T,>(promise: Promise<T> | null): Promise<T | null> => |
| 103 | promise ? promise.catch((error) => (console.warn("overview:", error), null)) : Promise.resolve(null); |
| 104 | // People with a role of their own here see its running parts: deployments, |
| 105 | // memory, setup; everyone who can read it sees the rest. Not awaited: only |
| 106 | // those sections wait on the repository lookup, which the layout makes in |
| 107 | // this request too. |
| 108 | const accessP = accessTo(context, params); |
| 109 | const memberP = accessP.then((access) => access.insider); |
| 110 | const forMembers = <T,>(start: () => Promise<T>): Promise<T | null> => |
| 111 | memberP.then((member) => (member ? soft(start()) : null)); |
| 112 | const repoP = soft(repoFor(context, params)); |
| 113 | const projectP = soft(projects.get(params.owner, params.repo, viewer)); |
| 114 | // A library shows its packages where an app shows production, and its |
| 115 | // checklist counts a workflow and a release instead of deploys. |
| 116 | const libraryRepoP = Promise.all([projectP, repoP]).then(([project, repo]) => |
| 117 | project?.ok && project.value.kind === "library" && repo?.ok ? repo.value : null, |
| 118 | ); |
| 119 | const packagesP = libraryRepoP.then((repo) => (repo ? soft(packages.list(params.owner, viewer, { repoId: repo.id })) : null)); |
| 120 | const workflowsP = libraryRepoP.then((repo) => (repo ? forMembers(() => actions.workflows(path, viewer)) : null)); |
| 121 | const eventsP = repoP.then((repo) => (repo?.ok ? soft(eventLog.list({ repoId: repo.value.id, limit: 150 })) : null)); |
| 122 | const minePullsP = repoP.then((repo) => |
| 123 | repo?.ok && viewer |
| 124 | ? soft(work.listActivePulls(viewer)).then((list) => (list ?? []).filter((item) => item.pull.repoId === repo.value.id)) |
| 125 | : null, |
| 126 | ); |
| 127 | const openP = soft(work.listPulls(path, viewer, "open")); |
| 128 | // Where its code came from on GitHub, for members. |
| 129 | const githubP = repoP.then((repo) => (repo?.ok ? forMembers(() => githubApp.link(repo.value.id)) : null)); |
| 130 | const listP = forMembers(() => deployments.list(ref, viewer)); |
| 131 | // Active branches: the newest few besides the default, with how far each |
| 132 | // has moved. Branches with an open pull request are read first. |
| 133 | const branchesP = Promise.all([repoP, soft(repos.branches(path, viewer)), openP, listP]).then( |
| 134 | async ([repo, branchList, pulls, deploys]): Promise<{ main: string; total: number; shown: ActiveBranch[] } | null> => { |
| 135 | if (!repo?.ok || !branchList?.ok) return null; |
| 136 | const main = repo.value.defaultBranch; |
| 137 | if (branchList.value.every((branch) => branch.name === main)) return { main, total: 0, shown: [] }; |
| 138 | const read = await readBranches( |
| 139 | path, |
| 140 | viewer, |
| 141 | { |
| 142 | defaultBranch: main, |
| 143 | branches: branchList.value, |
| 144 | pulls: pulls?.ok ? pulls.value : [], |
| 145 | previews: deploys?.ok ? deploys.value.live.filter((app) => app.kind === "preview") : [], |
| 146 | }, |
| 147 | BRANCHES_READ, |
| 148 | ); |
| 149 | return { main, total: read.total, shown: read.shown.slice(0, BRANCHES_SHOWN) }; |
| 150 | }, |
| 151 | ); |
| 152 | // Active branches read several logs each: streamed, so the rest shows first. |
| 153 | const branches = branchesP.catch(() => null); |
| 154 | const [{ insider: member, can }, project, settings, list, open, closed, log, counts, deps, runs, queue, issues, memories, recent, mine, domains, root, packageList, workflows] = await Promise.all([ |
| 155 | accessP, |
| 156 | projectP, |
| 157 | forMembers(() => deployments.settings(ref, viewer)), |
| 158 | listP, |
| 159 | openP, |
| 160 | soft(work.listPulls(path, viewer, "closed")), |
| 161 | soft(repos.log(path, viewer, null, 1)), |
| 162 | soft(countsFor(context, params)), |
| 163 | soft(projects.dependencies(params.owner, params.repo, viewer)), |
| 164 | soft(agents.listRuns(viewer, { repo: path, limit: 60 })), |
| 165 | soft(work.queue(path, viewer)), |
| 166 | soft(work.listIssues(path, viewer, { state: "open" })), |
| 167 | forMembers(() => agents.listMemories(viewer, params.owner, path)), |
| 168 | eventsP, |
| 169 | minePullsP, |
| 170 | // For the checklist, which only members see. |
| 171 | forMembers(() => deployments.domains(ref, viewer)), |
| 172 | forMembers(() => repos.tree(path, viewer, null, "")), |
| 173 | packagesP, |
| 174 | workflowsP, |
| 175 | ]); |
| 176 | const ok = <T,>(result: { ok: true; value: T } | { ok: false } | null): T | null => (result?.ok ? result.value : null); |
| 177 | |
| 178 | const openPulls = ok(open) ?? []; |
| 179 | const runList = ok(runs) ?? []; |
| 180 | const live = runList.filter((run) => isActiveRun(run.status)); |
| 181 | const builds = ok(list)?.deployments ?? []; |
| 182 | const landed = (ok(closed) ?? []) |
| 183 | .filter((pull) => pull.status === "merged") |
| 184 | .sort((a, b) => Date.parse(b.mergedAt ?? b.updatedAt) - Date.parse(a.mergedAt ?? a.updatedAt)); |
| 185 | const queued = queuedNumbers(ok(queue)?.active ?? []); |
| 186 | const runOn = new Map<number, AgentRun>(); |
| 187 | for (const run of live) if (run.number != null && !runOn.has(run.number)) runOn.set(run.number, run); |
| 188 | const lifecycleOf = new Map((mine ?? []).map((item) => [item.pull.number, item.lifecycle])); |
| 189 | |
| 190 | // --- The pipeline ----------------------------------------------------------- |
| 191 | type Card = { |
| 192 | number: number; |
| 193 | title: string; |
| 194 | agent: string; |
| 195 | status: Pull["status"]; |
| 196 | checkStatus: Pull["checkStatus"]; |
| 197 | step: string | null; |
| 198 | runKind: string | null; |
| 199 | runStarted: string | null; |
| 200 | needsYou: boolean; |
| 201 | at: string; |
| 202 | }; |
| 203 | const columns: Record<PipelineStage, Card[]> = { working: [], checking: [], reviewing: [], queue: [], landed: [] }; |
| 204 | for (const pull of openPulls.slice(0, 40)) { |
| 205 | const run = runOn.get(pull.number); |
| 206 | columns[pipelineStage(pull, run, queued, lifecycleOf.get(pull.number))].push({ |
| 207 | number: pull.number, |
| 208 | title: pull.title, |
| 209 | agent: pull.agent, |
| 210 | status: pull.status, |
| 211 | checkStatus: pull.checkStatus, |
| 212 | step: run?.step ?? null, |
| 213 | runKind: run ? RUN_KIND_LABEL[run.kind] : null, |
| 214 | runStarted: run ? (run.startedAt ?? run.createdAt) : null, |
| 215 | needsYou: lifecycleOf.get(pull.number)?.stage === "needs_you", |
| 216 | at: pull.updatedAt, |
| 217 | }); |
| 218 | } |
| 219 | for (const pull of landed.filter((p) => now - Date.parse(p.mergedAt ?? p.updatedAt) < 3 * TIME.DAY).slice(0, 5)) { |
| 220 | columns.landed.push({ |
| 221 | number: pull.number, |
| 222 | title: pull.title, |
| 223 | agent: pull.agent, |
| 224 | status: pull.status, |
| 225 | checkStatus: pull.checkStatus, |
| 226 | step: null, |
| 227 | runKind: null, |
| 228 | runStarted: null, |
| 229 | needsYou: false, |
| 230 | at: pull.mergedAt ?? pull.updatedAt, |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | // --- Needs you --------------------------------------------------------------- |
| 235 | const base = `/${params.owner}/${params.repo}`; |
| 236 | const needs: Need[] = []; |
| 237 | const latestProduction = builds.find((build) => build.kind === "production") ?? null; |
| 238 | if (latestProduction?.status === "failed") { |
| 239 | needs.push({ |
| 240 | key: "deploy", |
| 241 | kind: "deploy", |
| 242 | title: "The production build failed", |
| 243 | detail: latestProduction.error ?? "Production still serves the build before it.", |
| 244 | to: `${base}/deployments/${latestProduction.id}`, |
| 245 | action: "See the build", |
| 246 | at: Date.parse(latestProduction.finishedAt ?? latestProduction.createdAt), |
| 247 | where: latestProduction.commit.slice(0, 7), |
| 248 | }); |
| 249 | } |
| 250 | const me = viewer?.username.toLowerCase(); |
| 251 | for (const pull of openPulls) { |
| 252 | const to = `${base}/pull/${pull.number}`; |
| 253 | const where = `#${pull.number}`; |
| 254 | const lifecycle = lifecycleOf.get(pull.number); |
| 255 | if (lifecycle?.stage === "needs_you") { |
| 256 | const conflict = /conflict/i.test(lifecycle.detail); |
| 257 | needs.push({ key: `pull:${pull.number}`, kind: conflict ? "conflict" : "stalled", title: pull.title, detail: lifecycle.detail, to, action: conflict ? "Resolve" : "Decide", at: Date.parse(pull.updatedAt), where }); |
| 258 | } else if (lifecycle?.stage === "ready") { |
| 259 | needs.push({ key: `pull:${pull.number}`, kind: "ready", title: pull.title, detail: "Ready to land when you merge it.", to, action: "Merge", at: Date.parse(pull.updatedAt), where }); |
| 260 | } |
| 261 | // Never your own, nor one g1t made for you; whoever it is for asked. |
| 262 | const owner = workOwner(pull).username; |
| 263 | if (me && pull.status === "open" && owner.toLowerCase() !== me && pull.reviewers.some((name) => name.toLowerCase() === me)) { |
| 264 | needs.push({ key: `review:${pull.number}`, kind: "review", title: pull.title, detail: `${owner} asked for your review.`, to, action: "Review", at: Date.parse(pull.updatedAt), where }); |
| 265 | } |
| 266 | if (member && pull.status === "open" && pull.checkStatus === "failed" && !runOn.has(pull.number) && !lifecycle) { |
| 267 | needs.push({ key: `checks:${pull.number}`, kind: "checks", title: pull.title, detail: "It failed in the merge queue and no agent is fixing it.", to, action: "See checks", at: Date.parse(pull.updatedAt), where }); |
| 268 | } |
| 269 | } |
| 270 | for (const run of live) { |
| 271 | const minutes = stuckMinutes(run, now); |
| 272 | if (minutes == null) continue; |
| 273 | needs.push({ |
| 274 | key: `run:${run.id}`, |
| 275 | kind: "stuck", |
| 276 | title: run.title ?? `${run.agent}'s run`, |
| 277 | detail: `${run.agent} has reported nothing for ${minutes} min${run.step ? `. Last: ${run.step}` : ""}.`, |
| 278 | to: `${base}/agents/runs/${run.id}`, |
| 279 | action: "Look", |
| 280 | at: Date.parse(run.updatedAt), |
| 281 | where: run.number != null ? `#${run.number}` : null, |
| 282 | }); |
| 283 | } |
| 284 | |
| 285 | // --- Activity and health ------------------------------------------------------- |
| 286 | const eventList: G1tEvent[] = recent ?? []; |
| 287 | const items = eventList |
| 288 | .map((event) => eventItem(event, path)) |
| 289 | .filter((item): item is ActivityItem => item != null); |
| 290 | const checkEvents = eventList.flatMap((event) => |
| 291 | event.type === "checks.completed" ? [{ repo: "", number: event.data.number, at: Date.parse(event.time), passed: event.data.status === "passed" }] : [], |
| 292 | ); |
| 293 | const memoryList = ok(memories)?.project ?? []; |
| 294 | const knows = [...memoryList.filter((m) => m.pinned), ...memoryList.filter((m) => !m.pinned).sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))].slice(0, 5); |
| 295 | const openIssues = ok(issues); |
| 296 | |
| 297 | // --- Getting to production ---------------------------------------------------- |
| 298 | const wentLive = (status: string) => status === "ready" || status === "replaced" || status === "down"; |
| 299 | const liveApps = ok(list)?.live ?? []; |
| 300 | const commitNow = ok(log)?.[0] ?? null; |
| 301 | const projectValue = ok(project); |
| 302 | const isLibrary = projectValue?.kind === "library"; |
| 303 | const published = libraryPackages(ok(packageList) ?? []); |
| 304 | const firstSteps = { |
| 305 | base, |
| 306 | hasCode: commitNow != null || projectValue?.source.kind === "mirror", |
| 307 | instructions: commitNow == null ? false : root?.ok ? hasInstructions(root.value.entries.map((entry) => entry.name)) : null, |
| 308 | agentAssigned: agentWasAssigned({ |
| 309 | runAgents: runList.map((run) => run.agent), |
| 310 | pullAgents: [...openPulls, ...(ok(closed) ?? [])].map((pull) => pull.agent), |
| 311 | issues: openIssues ?? [], |
| 312 | }), |
| 313 | }; |
| 314 | const checklist = !member |
| 315 | ? null |
| 316 | : isLibrary |
| 317 | ? releaseChecklist({ |
| 318 | ...firstSteps, |
| 319 | hasWorkflow: workflows?.ok ? workflows.value.length > 0 : null, |
| 320 | released: hasRelease(published), |
| 321 | releaseTo: published[0] |
| 322 | ? packagePath(published[0]) |
| 323 | : (publishGuide(projectValue?.ecosystem ?? null)?.guide ?? "https://docs.g1t.sh/guides/packages/"), |
| 324 | }) |
| 325 | : productionChecklist({ |
| 326 | ...firstSteps, |
| 327 | deploysEnabled: ok(settings)?.enabled ?? false, |
| 328 | productionDeployed: |
| 329 | liveApps.some((app) => app.kind === "production") || |
| 330 | builds.some((build) => build.kind === "production" && wentLive(build.status)), |
| 331 | domains: ok(domains)?.domains.length ?? null, |
| 332 | previewOpened: |
| 333 | liveApps.some((app) => app.kind === "preview") || builds.some((build) => build.kind === "preview" && wentLive(build.status)), |
| 334 | }); |
| 335 | |
| 336 | const github = await githubP; |
| 337 | return { |
| 338 | member, |
| 339 | can, |
| 340 | github, |
| 341 | project: ok(project), |
| 342 | settings: ok(settings), |
| 343 | builds: builds.slice(0, 30), |
| 344 | live: ok(list)?.live ?? [], |
| 345 | commit: ok(log)?.[0] ?? null, |
| 346 | open: ok(counts) ?? { issues: openIssues?.length ?? 0, pulls: openPulls.length }, |
| 347 | dependencies: ok(deps), |
| 348 | agentsLive: live.slice(0, 6), |
| 349 | runsLoaded: runs?.ok ?? false, |
| 350 | pullsLoaded: open?.ok ?? false, |
| 351 | columns, |
| 352 | needs: rankNeeds(needs), |
| 353 | landed: landed.slice(0, MAX_LANDED), |
| 354 | groups: groupActivity(items).slice(0, 30), |
| 355 | eventsLoaded: recent != null, |
| 356 | health: { |
| 357 | passRate: passRate(checkEvents.map((c) => c.passed)), |
| 358 | firstPass: firstPassRate(checkEvents), |
| 359 | checkRuns: checkEvents.length, |
| 360 | ages: openIssues ? ageBuckets(openIssues.map((issue) => issue.createdAt), now) : null, |
| 361 | }, |
| 362 | knows: knows as Memory[], |
| 363 | memoryCount: memoryList.length, |
| 364 | memoriesLoaded: memories?.ok ?? false, |
| 365 | checklist, |
| 366 | library: isLibrary |
| 367 | ? { packages: published.slice(0, PACKAGES_SHOWN), total: published.length, loaded: packageList?.ok ?? false } |
| 368 | : null, |
| 369 | branches, |
| 370 | }; |
| 371 | } |
| 372 | |
| 373 | export async function action({ request, params, context }: Route.ActionArgs) { |
| 374 | assertSameOrigin(request); |
| 375 | const user = requireUser(context, request); |
| 376 | const form = await request.formData().catch(() => null); |
| 377 | const intent = form?.get("intent"); |
| 378 | // Syncing from GitHub is pushing; stopping it is an integration; deploying is compute. |
| 379 | const refused = await refusal(context, params, intent === "github-sync" ? "push" : intent === "github-stop" ? "manage_integrations" : "run"); |
| 380 | if (refused) return { error: refused }; |
| 381 | if (intent === "github-sync" || intent === "github-stop") { |
| 382 | const repo = await repos.get({ namespace: params.owner, name: params.repo }, user); |
| 383 | if (!repo.ok) return { error: repo.error.message }; |
| 384 | const done = |
| 385 | intent === "github-sync" ? await githubApp.sync(user, repo.value.id) : await githubApp.unlinkRepo(user, repo.value.id); |
| 386 | return done.ok |
| 387 | ? { notice: intent === "github-sync" ? "Synced with GitHub." : "It is no longer kept in step with GitHub." } |
| 388 | : { error: done.error.message }; |
| 389 | } |
| 390 | const started = await deployments.redeploy(user, { workspace: params.owner, slug: params.repo }, null); |
| 391 | return started.ok ? { notice: "Production is building." } : { error: started.error.message }; |
| 392 | } |
| 393 | |
| 394 | type Loaded = Awaited<ReturnType<typeof overviewData>>; |
| 395 | type Card = Loaded["columns"]["working"][number]; |
| 396 | |
| 397 | const STAGE_TONE: Record<PipelineStage, string> = { |
| 398 | working: "bg-merged", |
| 399 | checking: "bg-info", |
| 400 | reviewing: "bg-warn", |
| 401 | queue: "bg-accent-dim", |
| 402 | landed: "bg-accent", |
| 403 | }; |
| 404 | |
| 405 | function PipelineCard({ card, base, stage }: { card: Card; base: string; stage: PipelineStage }) { |
| 406 | return ( |
| 407 | <li> |
| 408 | <Link |
| 409 | to={`${base}/pull/${card.number}`} |
| 410 | prefetch="intent" |
| 411 | className={`block rounded-lg border bg-bg/60 p-2.5 transition-colors hover:border-line-strong hover:bg-raised ${ |
| 412 | card.needsYou ? "border-warn/50" : card.step ? "border-merged/30" : "border-line" |
| 413 | }`} |
| 414 | > |
| 415 | <span className="line-clamp-2 text-[0.8125rem] leading-snug font-medium">{card.title}</span> |
| 416 | <span className="mt-1.5 flex items-center gap-1.5 text-[0.6875rem] text-muted"> |
| 417 | <Avatar name={card.agent} size={14} /> |
| 418 | <span className="font-mono text-faint">#{card.number}</span> |
| 419 | <span className="grow" /> |
| 420 | {card.needsYou ? ( |
| 421 | <span className="inline-flex items-center gap-1 text-warn" title="Stopped: a person decides what happens next"> |
| 422 | <Hand size={11} /> you |
| 423 | </span> |
| 424 | ) : stage === "landed" ? ( |
| 425 | <TimeAgo at={card.at} /> |
| 426 | ) : card.runStarted ? ( |
| 427 | <span className="inline-flex items-center gap-1 text-merged"> |
| 428 | <Loader2 size={11} className="animate-spin" /> |
| 429 | <Elapsed from={card.runStarted} /> |
| 430 | </span> |
| 431 | ) : ( |
| 432 | <CheckBadge status={card.checkStatus} /> |
| 433 | )} |
| 434 | </span> |
| 435 | {card.step && ( |
| 436 | <span className="mt-1.5 block truncate font-mono text-[0.6875rem] text-fg/70" title={card.step}> |
| 437 | {card.runKind}: {card.step} |
| 438 | </span> |
| 439 | )} |
| 440 | </Link> |
| 441 | </li> |
| 442 | ); |
| 443 | } |
| 444 | |
| 445 | /** Open pull requests moving through Working → Checking → Reviewing → Queue → Landed. */ |
| 446 | function Pipeline({ columns, base }: { columns: Loaded["columns"]; base: string }) { |
| 447 | return ( |
| 448 | <div className="relative -mx-4 overflow-x-auto px-4 pb-1 sm:mx-0 sm:px-0"> |
| 449 | {/* Each stage as tall as what is in it: an empty one stays short |
| 450 | instead of stretching to the busiest. */} |
| 451 | <ol className="grid min-w-176 grid-cols-5 items-start gap-2"> |
| 452 | {PIPELINE.map(({ stage, label }, index) => { |
| 453 | const cards = columns[stage]; |
| 454 | return ( |
| 455 | <li key={stage} className="flex min-w-0 flex-col rounded-xl border border-line bg-surface p-2"> |
| 456 | <p className="flex items-center gap-2 px-1 pt-0.5 pb-2 text-xs font-medium text-muted"> |
| 457 | <span className={`size-1.5 rounded-full ${STAGE_TONE[stage]} ${cards.length && stage !== "landed" ? "animate-pulse" : ""}`} /> |
| 458 | {label} |
| 459 | <span className="tabular-nums text-faint">{cards.length}</span> |
| 460 | {index < PIPELINE.length - 1 && <ArrowRight size={11} className="ml-auto text-line-strong" />} |
| 461 | </p> |
| 462 | {cards.length === 0 ? ( |
| 463 | <p className="rounded-lg border border-dashed border-line/70 px-2 py-3 text-center text-[0.6875rem] text-faint">Empty</p> |
| 464 | ) : ( |
| 465 | <ul className="space-y-1.5"> |
| 466 | {cards.slice(0, 6).map((card) => ( |
| 467 | <PipelineCard key={card.number} card={card} base={base} stage={stage} /> |
| 468 | ))} |
| 469 | {cards.length > 6 && ( |
| 470 | <li className="px-1 text-[0.6875rem] text-muted"> |
| 471 | <Link to={`${base}/pulls`} className="hover:text-fg"> |
| 472 | {cards.length - 6} more |
| 473 | </Link> |
| 474 | </li> |
| 475 | )} |
| 476 | </ul> |
| 477 | )} |
| 478 | </li> |
| 479 | ); |
| 480 | })} |
| 481 | </ol> |
| 482 | </div> |
| 483 | ); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Where an app's overview shows production, a library's shows what it |
| 488 | * publishes: each package with its latest version and how to install it, |
| 489 | * or, before there is one, how to publish a first version. |
| 490 | */ |
| 491 | function LibraryHead({ |
| 492 | library, |
| 493 | project, |
| 494 | base, |
| 495 | canChange, |
| 496 | workspace, |
| 497 | }: { |
| 498 | library: { packages: PackageSummary[]; total: number; loaded: boolean }; |
| 499 | project: Project | null; |
| 500 | base: string; |
| 501 | canChange: boolean; |
| 502 | workspace: string; |
| 503 | }) { |
| 504 | const guide = publishGuide(project?.ecosystem ?? null); |
| 505 | const name = project?.name ?? base.split("/").pop(); |
| 506 | return ( |
| 507 | <div className="p-5 sm:p-6"> |
| 508 | <p className="flex items-center gap-2 text-xs font-medium tracking-wide text-muted uppercase"> |
| 509 | <PackageGlyph size={13} className="text-accent" /> |
| 510 | Packages |
| 511 | </p> |
| 512 | {library.packages.length > 0 ? ( |
| 513 | <> |
| 514 | <ul className="mt-3 space-y-4"> |
| 515 | {library.packages.map((pkg) => { |
| 516 | const commands = installCommands(pkg, pkg.latest, "you"); |
| 517 | return ( |
| 518 | <li key={pkg.id} className="flex flex-col gap-2.5 lg:flex-row lg:items-start lg:gap-5"> |
| 519 | <Link to={packagePath(pkg)} className="group flex min-w-0 items-center gap-3 lg:w-72 lg:shrink-0"> |
| 520 | <PackageIcon ecosystem={pkg.ecosystem} size={32} /> |
| 521 | <span className="min-w-0"> |
| 522 | <span className="block truncate font-mono text-[0.9375rem] font-medium group-hover:text-accent">{packageName(pkg)}</span> |
| 523 | <span className="block text-xs text-muted"> |
| 524 | {ECOSYSTEM_LABEL[pkg.ecosystem]} · {pkg.latest ?? "no versions yet"} |
| 525 | {pkg.versions > 1 && ` · ${pkg.versions} versions`} |
| 526 | </span> |
| 527 | </span> |
| 528 | </Link> |
| 529 | <div className="min-w-0 grow space-y-1.5"> |
| 530 | {/* The workspace's registry first, or the tool installs a package of the same name from elsewhere. */} |
| 531 | {commands.registry && <CopyLine prompt text={commands.registry} />} |
| 532 | <CopyLine prompt text={commands.install} /> |
| 533 | </div> |
| 534 | </li> |
| 535 | ); |
| 536 | })} |
| 537 | </ul> |
| 538 | {library.total > library.packages.length && ( |
| 539 | <Link to={`/${workspace}/-/packages`} className="mt-3 inline-block text-xs text-muted hover:text-fg"> |
| 540 | All {library.total} packages |
| 541 | </Link> |
| 542 | )} |
| 543 | </> |
| 544 | ) : ( |
| 545 | <> |
| 546 | <p className="mt-2 text-lg font-medium">{library.loaded ? "Not published yet" : "Packages could not be loaded just now"}</p> |
| 547 | {guide ? ( |
| 548 | <> |
| 549 | <p className="mt-1 max-w-lg text-sm text-muted"> |
| 550 | Publish a first version of {name} to the workspace's {guide.label} registry, for others to install |
| 551 | {guide.start ? ":" : "."} |
| 552 | </p> |
| 553 | {guide.start && ( |
| 554 | <div className="mt-3 max-w-lg"> |
| 555 | <CopyLine prompt text={guide.start} /> |
| 556 | </div> |
| 557 | )} |
| 558 | <a href={guide.guide} className="mt-3 inline-flex items-center gap-1 text-sm text-accent hover:underline"> |
| 559 | Publishing to {guide.label} <ArrowUpRight size={13} /> |
| 560 | </a> |
| 561 | </> |
| 562 | ) : ( |
| 563 | <> |
| 564 | <p className="mt-1 max-w-lg text-sm text-muted">Publish a first version of {name} to one of the workspace's registries:</p> |
| 565 | <p className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-sm"> |
| 566 | {PUBLISH_GUIDES.map((one) => ( |
| 567 | <a key={one.label} href={one.guide} className="inline-flex items-center gap-1 text-accent hover:underline"> |
| 568 | {one.label} <ArrowUpRight size={13} /> |
| 569 | </a> |
| 570 | ))} |
| 571 | </p> |
| 572 | </> |
| 573 | )} |
| 574 | </> |
| 575 | )} |
| 576 | {canChange && ( |
| 577 | <p className="mt-4 text-xs text-faint"> |
| 578 | Deploys?{" "} |
| 579 | <Link to={`${base}/settings#deploys`} className="underline-offset-4 hover:text-fg hover:underline"> |
| 580 | Change it in Settings. |
| 581 | </Link> |
| 582 | </p> |
| 583 | )} |
| 584 | </div> |
| 585 | ); |
| 586 | } |
| 587 | |
| 588 | function Stat({ label, value, to }: { label: string; value: ReactNode; to?: string }) { |
| 589 | const body = ( |
| 590 | <> |
| 591 | <span className="block text-[0.6875rem] text-faint">{label}</span> |
| 592 | <span className="mt-0.5 block truncate text-[0.8125rem] font-medium">{value}</span> |
| 593 | </> |
| 594 | ); |
| 595 | return to ? ( |
| 596 | <Link to={to} className="min-w-0 px-5 py-3 transition-colors hover:bg-raised/50"> |
| 597 | {body} |
| 598 | </Link> |
| 599 | ) : ( |
| 600 | <div className="min-w-0 px-5 py-3">{body}</div> |
| 601 | ); |
| 602 | } |
| 603 | |
| 604 | export default function ProjectOverview({ loaderData, actionData, params }: Route.ComponentProps) { |
| 605 | return ( |
| 606 | <Suspense fallback={<OverviewSkeleton />}> |
| 607 | <Await resolve={loaderData.overview} errorElement={<OverviewFailed />}> |
| 608 | {(overview) => <Overview loaderData={overview} actionData={actionData} params={params} />} |
| 609 | </Await> |
| 610 | </Suspense> |
| 611 | ); |
| 612 | } |
| 613 | |
| 614 | /** The overview's sections as they will sit, while they stream in. */ |
| 615 | function OverviewSkeleton() { |
| 616 | return ( |
| 617 | <div className="space-y-8" aria-busy="true" aria-label="Loading the overview"> |
| 618 | <section className="rounded-2xl border border-line bg-surface p-5 sm:p-6"> |
| 619 | <Skeleton className="h-3 w-24" /> |
| 620 | <Skeleton className="mt-3 h-5 w-64 max-w-full" /> |
| 621 | <Skeleton className="mt-3 h-3 w-48 max-w-full" /> |
| 622 | </section> |
| 623 | <section className="rounded-2xl border border-line bg-surface p-2"> |
| 624 | <div className="grid grid-cols-2 gap-2 sm:grid-cols-5"> |
| 625 | {Array.from({ length: 5 }, (_, index) => ( |
| 626 | <Skeleton key={index} className="h-24 rounded-xl" /> |
| 627 | ))} |
| 628 | </div> |
| 629 | </section> |
| 630 | <div className="grid gap-6 lg:grid-cols-2"> |
| 631 | <section className="rounded-2xl border border-line bg-surface"> |
| 632 | <SkeletonRows rows={4} /> |
| 633 | </section> |
| 634 | <section className="rounded-2xl border border-line bg-surface"> |
| 635 | <SkeletonRows rows={4} /> |
| 636 | </section> |
| 637 | </div> |
| 638 | </div> |
| 639 | ); |
| 640 | } |
| 641 | |
| 642 | function OverviewFailed() { |
| 643 | return ( |
| 644 | <p className="rounded-2xl border border-line bg-surface p-6 text-sm text-muted"> |
| 645 | The overview could not be loaded just now. Reload the page to try again. |
| 646 | </p> |
| 647 | ); |
| 648 | } |
| 649 | |
| 650 | function Overview({ |
| 651 | loaderData, |
| 652 | actionData, |
| 653 | params, |
| 654 | }: { |
| 655 | loaderData: Loaded; |
| 656 | actionData: Route.ComponentProps["actionData"]; |
| 657 | params: Route.ComponentProps["params"]; |
| 658 | }) { |
| 659 | const { member, project, settings, builds, live, commit, open, dependencies, agentsLive, columns, needs, landed, groups, health, knows, checklist, branches, library } = |
| 660 | loaderData; |
| 661 | const base = `/${params.owner}/${params.repo}`; |
| 662 | const production = live.find((app) => app.kind === "production") ?? null; |
| 663 | // The project's own domain, once it is active, is where production is visited. |
| 664 | const productionUrl = production ? (settings?.primaryDomain ? `https://${settings.primaryDomain}` : production.url) : null; |
| 665 | const previews = live.filter((app) => app.kind === "preview"); |
| 666 | const latestProduction = builds.find((build) => build.kind === "production") ?? null; |
| 667 | const addresses = useAddresses(); |
| 668 | const source = project?.source.kind === "hosted" ? project.source : null; |
| 669 | const moving = agentsLive.length > 0 || columns.working.length + columns.checking.length > 0; |
| 670 | useLiveRefresh(moving); |
| 671 | const ages = health.ages; |
| 672 | const oldest = ages ? Math.max(1, ...ages.map((a) => a.count)) : 1; |
| 673 | |
| 674 | return ( |
| 675 | <div className="space-y-8"> |
| 676 | {loaderData.github && <GithubLinkStrip link={loaderData.github} />} |
| 677 | {/* What the project is, running, and where its code is. */} |
| 678 | <section className="overflow-hidden rounded-2xl border border-line bg-surface"> |
| 679 | {library ? ( |
| 680 | <LibraryHead library={library} project={project} base={base} canChange={loaderData.can.manage_settings} workspace={params.owner} /> |
| 681 | ) : ( |
| 682 | <div className="flex flex-col gap-5 p-5 sm:flex-row sm:items-start sm:p-6"> |
| 683 | {member && (production || settings?.enabled) && ( |
| 684 | <ProductionShot |
| 685 | src={production ? `${base}/production.jpg?v=${shotVersion(production)}` : null} |
| 686 | href={production ? (productionUrl ?? production.url) : null} |
| 687 | label={host(production ? (productionUrl ?? production.url) : (settings?.productionUrl ?? ""))} |
| 688 | className="w-full shrink-0 sm:w-60 lg:w-72" |
| 689 | /> |
| 690 | )} |
| 691 | <div className="flex min-w-0 grow flex-wrap items-start justify-between gap-4"> |
| 692 | <div className="min-w-0"> |
| 693 | <p className="flex items-center gap-2 text-xs font-medium tracking-wide text-muted uppercase"> |
| 694 | <Rocket size={13} className="text-accent" /> |
| 695 | Production |
| 696 | </p> |
| 697 | {production ? ( |
| 698 | <> |
| 699 | <a |
| 700 | href={productionUrl ?? production.url} |
| 701 | className="mt-2 flex items-center gap-1.5 truncate font-mono text-lg font-medium hover:text-accent" |
| 702 | > |
| 703 | {host(productionUrl ?? production.url)} |
| 704 | <ArrowUpRight size={16} className="shrink-0 text-faint" /> |
| 705 | </a> |
| 706 | <p className="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted"> |
| 707 | {latestProduction && <StatusDot status={latestProduction.status} label={latestProduction.status === "ready" ? "Live" : undefined} />} |
| 708 | <span className="inline-flex items-center gap-1 font-mono"> |
| 709 | <GitCommitHorizontal size={13} className="text-faint" /> |
| 710 | {production.commit.slice(0, 7)} |
| 711 | </span> |
| 712 | <span> |
| 713 | deployed <TimeAgo at={production.deployedAt} /> |
| 714 | </span> |
| 715 | {settings?.primaryDomain && <span className="text-faint">also at {host(production.url)}</span>} |
| 716 | </p> |
| 717 | </> |
| 718 | ) : settings?.enabled ? ( |
| 719 | <> |
| 720 | <p className="mt-2 font-mono text-lg text-muted">{host(settings.productionUrl)}</p> |
| 721 | <p className="mt-1.5 text-xs text-muted"> |
| 722 | {latestProduction ? ( |
| 723 | <StatusDot status={latestProduction.status} label={latestProduction.status === "failed" ? "The last build failed" : undefined} /> |
| 724 | ) : ( |
| 725 | "Not deployed yet. Push to the default branch, or deploy it now." |
| 726 | )} |
| 727 | </p> |
| 728 | </> |
| 729 | ) : ( |
| 730 | <> |
| 731 | <p className="mt-2 text-lg font-medium">Deployments are off</p> |
| 732 | <p className="mt-1 max-w-lg text-sm text-muted"> |
| 733 | Nothing builds or runs until you turn them on. Then {project?.name ?? params.repo} goes up on g1t.page: |
| 734 | production from the default branch, and a live preview for every pull request. It runs only while |
| 735 | someone visits. |
| 736 | </p> |
| 737 | </> |
| 738 | )} |
| 739 | </div> |
| 740 | {member && ( |
| 741 | <div className="flex shrink-0 items-center gap-2"> |
| 742 | {production && ( |
| 743 | <ButtonLink to={productionUrl ?? production.url} variant="accent" reloadDocument> |
| 744 | Visit |
| 745 | <ArrowUpRight size={14} /> |
| 746 | </ButtonLink> |
| 747 | )} |
| 748 | {settings?.enabled ? ( |
| 749 | loaderData.can.run && <Form method="post"> |
| 750 | <SubmitButton |
| 751 | variant="quiet" |
| 752 | name="intent" |
| 753 | value="redeploy" |
| 754 | pending="Redeploying…" |
| 755 | title="Build production again from the default branch" |
| 756 | > |
| 757 | <RotateCw size={14} /> |
| 758 | Redeploy |
| 759 | </SubmitButton> |
| 760 | </Form> |
| 761 | ) : loaderData.can.manage_integrations && ( |
| 762 | <ButtonLink to={`${base}/settings/deployments`} variant="accent"> |
| 763 | <Rocket size={14} /> |
| 764 | Turn on deployments |
| 765 | </ButtonLink> |
| 766 | )} |
| 767 | </div> |
| 768 | )} |
| 769 | </div> |
| 770 | </div> |
| 771 | )} |
| 772 | {actionData && ( |
| 773 | <p className={`border-t border-line px-6 py-2.5 text-sm ${"error" in actionData ? "text-danger" : "text-accent"}`}> |
| 774 | {"error" in actionData ? actionData.error : actionData.notice} |
| 775 | </p> |
| 776 | )} |
| 777 | <div className="grid grid-cols-2 divide-line border-t border-line text-sm sm:grid-cols-4 sm:divide-x"> |
| 778 | <Stat |
| 779 | label="Source" |
| 780 | to={`${base}/code`} |
| 781 | value={ |
| 782 | source ? ( |
| 783 | <span className="inline-flex items-center gap-1.5 font-mono"> |
| 784 | {project?.private ? <Lock size={12} className="text-faint" /> : <Code2 size={12} className="text-faint" />} |
| 785 | {source.repo.name} |
| 786 | {source.rootDir ? `/${source.rootDir}` : ""} |
| 787 | </span> |
| 788 | ) : ( |
| 789 | "—" |
| 790 | ) |
| 791 | } |
| 792 | /> |
| 793 | <Stat |
| 794 | label="Default branch" |
| 795 | to={`${base}/commits`} |
| 796 | value={ |
| 797 | <span className="inline-flex items-center gap-1.5 font-mono"> |
| 798 | <GitBranch size={12} className="text-faint" /> |
| 799 | {source?.defaultBranch ?? "main"} |
| 800 | </span> |
| 801 | } |
| 802 | /> |
| 803 | <Stat |
| 804 | label="Latest commit" |
| 805 | to={commit ? `${base}/commit/${commit.hash}` : undefined} |
| 806 | value={ |
| 807 | commit ? ( |
| 808 | <span title={commit.message.split("\n")[0]}> |
| 809 | <span className="font-mono">{commit.hash.slice(0, 7)}</span>{" "} |
| 810 | <span className="font-normal text-muted"> |
| 811 | <TimeAgo at={commit.authoredAt} /> |
| 812 | </span> |
| 813 | </span> |
| 814 | ) : ( |
| 815 | "No commits yet" |
| 816 | ) |
| 817 | } |
| 818 | /> |
| 819 | <Stat |
| 820 | label={member && settings?.enabled && !library ? "Last deploy" : "Open"} |
| 821 | to={member && settings?.enabled && !library ? `${base}/deployments` : `${base}/pulls`} |
| 822 | value={ |
| 823 | member && settings?.enabled && !library ? ( |
| 824 | latestProduction ? ( |
| 825 | <span className="inline-flex items-center gap-2"> |
| 826 | <StatusDot status={latestProduction.status} /> |
| 827 | <span className="font-normal text-muted"> |
| 828 | <TimeAgo at={latestProduction.createdAt} /> |
| 829 | </span> |
| 830 | </span> |
| 831 | ) : ( |
| 832 | "None yet" |
| 833 | ) |
| 834 | ) : ( |
| 835 | `${open.pulls} pull requests · ${open.issues} issues` |
| 836 | ) |
| 837 | } |
| 838 | /> |
| 839 | </div> |
| 840 | {commit && ( |
| 841 | <p className="truncate border-t border-line px-5 py-2.5 text-xs text-muted sm:px-6"> |
| 842 | <GitCommitHorizontal size={12} className="mr-1.5 inline text-faint" /> |
| 843 | {commit.message.split("\n")[0]} <span className="text-faint">· {commit.author.name}</span> |
| 844 | </p> |
| 845 | )} |
| 846 | </section> |
| 847 | |
| 848 | {checklist && <ProductionChecklist base={base} items={checklist} title={library ? "Ship a release" : undefined} />} |
| 849 | |
| 850 | <Panel |
| 851 | title="Right now" |
| 852 | icon={<span className={`block size-2 rounded-full ${agentsLive.length > 0 ? "animate-pulse bg-merged" : "bg-line-strong"}`} />} |
| 853 | count={agentsLive.length} |
| 854 | all={{ to: `${base}/agents`, label: "Agents" }} |
| 855 | > |
| 856 | {agentsLive.length > 0 && ( |
| 857 | <ul className="mb-3 grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3"> |
| 858 | {agentsLive.map((run) => ( |
| 859 | <li key={run.id} className="min-w-0 rounded-xl border border-merged/30 bg-surface px-3.5 py-3"> |
| 860 | <div className="flex items-center gap-2 text-sm"> |
| 861 | <Avatar name={run.agent} size={18} /> |
| 862 | <span className="font-medium">{run.agent}</span> |
| 863 | <span className="text-xs text-muted">{RUN_KIND_LABEL[run.kind].toLowerCase()}</span> |
| 864 | <span className="grow" /> |
| 865 | <span className="text-xs text-muted"> |
| 866 | <Elapsed from={run.startedAt ?? run.createdAt} /> |
| 867 | </span> |
| 868 | </div> |
| 869 | <Link |
| 870 | to={run.number != null ? `${base}/pull/${run.number}` : `${base}/agents/runs/${run.id}`} |
| 871 | className="mt-1 block truncate text-[0.8125rem] hover:text-accent" |
| 872 | > |
| 873 | {run.title ?? "A run"} {run.number != null && <span className="text-faint">#{run.number}</span>} |
| 874 | </Link> |
| 875 | {run.step && ( |
| 876 | <p className="mt-1 truncate font-mono text-[0.6875rem] text-fg/70" title={run.step}> |
| 877 | <span className="mr-1.5 inline-block size-1.5 animate-pulse rounded-full bg-merged align-middle" /> |
| 878 | {run.step} |
| 879 | </p> |
| 880 | )} |
| 881 | <p className="mt-1.5 flex items-center gap-3 text-[0.6875rem] text-faint"> |
| 882 | {formatCost(run.costUsd) && <span>{formatCost(run.costUsd)} so far</span>} |
| 883 | <Link to={`${base}/agents/runs/${run.id}`} className="hover:text-fg"> |
| 884 | {run.stepCount} steps |
| 885 | </Link> |
| 886 | {run.number != null && ( |
| 887 | <Link to={`${base}/sessions/${run.number}`} className="hover:text-fg"> |
| 888 | Session |
| 889 | </Link> |
| 890 | )} |
| 891 | </p> |
| 892 | </li> |
| 893 | ))} |
| 894 | </ul> |
| 895 | )} |
| 896 | {!loaderData.pullsLoaded ? ( |
| 897 | <Unavailable what="Pull requests" /> |
| 898 | ) : Object.values(columns).every((c) => c.length === 0) ? ( |
| 899 | <Quiet |
| 900 | action={ |
| 901 | member ? ( |
| 902 | <Link to={`${base}/issues/new`} className="inline-flex items-center gap-1.5 rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-bg hover:bg-white"> |
| 903 | <Bot size={12} /> Open an issue for an agent |
| 904 | </Link> |
| 905 | ) : null |
| 906 | } |
| 907 | > |
| 908 | Nothing is moving. Open an issue and hand it to g1t, or push a branch and open a pull request. |
| 909 | </Quiet> |
| 910 | ) : ( |
| 911 | <Pipeline columns={columns} base={base} /> |
| 912 | )} |
| 913 | </Panel> |
| 914 | |
| 915 | <div className="grid gap-x-8 gap-y-8 lg:grid-cols-[minmax(0,1fr)_20rem]"> |
| 916 | <div className="min-w-0 space-y-8"> |
| 917 | {needs.length > 0 && ( |
| 918 | <Panel title="Needs you" icon={<Hand size={14} className="text-warn" />} count={needs.length}> |
| 919 | <NeedsList needs={needs} limit={5} /> |
| 920 | </Panel> |
| 921 | )} |
| 922 | |
| 923 | <Suspense |
| 924 | fallback={ |
| 925 | <Panel title="Active branches" icon={<GitBranch size={14} />}> |
| 926 | <div aria-busy="true"> |
| 927 | <SkeletonRows rows={3} rowClassName="h-12" /> |
| 928 | </div> |
| 929 | </Panel> |
| 930 | } |
| 931 | > |
| 932 | <Await resolve={branches}> |
| 933 | {(branches) => ( |
| 934 | <Panel title="Active branches" icon={<GitBranch size={14} />} count={branches?.total || null}> |
| 935 | {!branches ? ( |
| 936 | <Unavailable what="Branches" /> |
| 937 | ) : branches.shown.length === 0 ? ( |
| 938 | <Quiet> |
| 939 | Only {branches.main} so far. Branches pushed here show with how far each has moved from {branches.main}, and |
| 940 | its pull request and preview. |
| 941 | </Quiet> |
| 942 | ) : ( |
| 943 | <> |
| 944 | <ActiveBranches branches={branches.shown} base={base} main={branches.main} /> |
| 945 | {branches.total > branches.shown.length && ( |
| 946 | <p className="mt-2 px-1 text-xs text-faint"> |
| 947 | The {branches.shown.length} most recently changed of {branches.total} branches. |
| 948 | </p> |
| 949 | )} |
| 950 | </> |
| 951 | )} |
| 952 | </Panel> |
| 953 | )} |
| 954 | </Await> |
| 955 | </Suspense> |
| 956 | |
| 957 | <Panel title="Recent changes" icon={<GitMerge size={14} />} all={{ to: `${base}/pulls?state=closed`, label: "All landed" }}> |
| 958 | {landed.length === 0 ? ( |
| 959 | <Quiet>Nothing has landed yet. Merged pull requests show here with who made them and why.</Quiet> |
| 960 | ) : ( |
| 961 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line bg-surface"> |
| 962 | {landed.map((pull) => { |
| 963 | const byAgent = pull.runtime === "hosted" || madeByG1t(pull); |
| 964 | return ( |
| 965 | <li key={pull.id} className="flex items-start gap-3 px-4 py-3"> |
| 966 | <GitMerge size={15} className="mt-0.5 shrink-0 text-merged" /> |
| 967 | <span className="min-w-0 grow"> |
| 968 | <Link to={`${base}/pull/${pull.number}`} prefetch="intent" className="block truncate text-sm font-medium hover:text-accent"> |
| 969 | {pull.title} |
| 970 | </Link> |
| 971 | <span className="mt-0.5 flex flex-wrap items-center gap-x-1.5 text-xs text-muted"> |
| 972 | <span className="font-mono text-faint">#{pull.number}</span> |
| 973 | <span>·</span> |
| 974 | <span className="inline-flex items-center gap-1"> |
| 975 | <Avatar name={pull.agent} size={13} /> |
| 976 | {pull.requestedBy |
| 977 | ? `made by ${pull.author.username} for ${pull.requestedBy.username}` |
| 978 | : byAgent |
| 979 | ? `made by ${pull.agent}` |
| 980 | : `by ${pull.author.username}`} |
| 981 | </span> |
| 982 | {pull.issue != null && ( |
| 983 | <> |
| 984 | <span>· for</span> |
| 985 | <Link to={`${base}/issues/${pull.issue}`} className="hover:text-fg"> |
| 986 | #{pull.issue} |
| 987 | </Link> |
| 988 | </> |
| 989 | )} |
| 990 | {pull.mergedBy && <span>· landed by {pull.mergedBy}</span>} |
| 991 | <span> |
| 992 | · <TimeAgo at={pull.mergedAt ?? pull.updatedAt} /> |
| 993 | </span> |
| 994 | </span> |
| 995 | </span> |
| 996 | <span className="hidden shrink-0 text-xs text-faint sm:block"> |
| 997 | <ChangeSize files={pull.files} /> |
| 998 | </span> |
| 999 | {byAgent && ( |
| 1000 | <Link to={`${base}/sessions/${pull.number}`} className="shrink-0 text-xs text-muted hover:text-fg"> |
| 1001 | Session |
| 1002 | </Link> |
| 1003 | )} |
| 1004 | </li> |
| 1005 | ); |
| 1006 | })} |
| 1007 | </ul> |
| 1008 | )} |
| 1009 | </Panel> |
| 1010 | |
| 1011 | <Panel title="Activity" icon={<ActivityIcon size={14} />}> |
| 1012 | {loaderData.eventsLoaded ? ( |
| 1013 | <ActivityFeed groups={groups} showRepo={false} limit={8} empty="Nothing has happened here yet." /> |
| 1014 | ) : ( |
| 1015 | <Unavailable what="Activity" /> |
| 1016 | )} |
| 1017 | </Panel> |
| 1018 | |
| 1019 | {previews.length > 0 && ( |
| 1020 | <Panel title="Previews" icon={<GitBranch size={14} />} count={previews.length} all={{ to: `${base}/deployments`, label: "Deployments" }}> |
| 1021 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line bg-surface"> |
| 1022 | {previews.map((app) => ( |
| 1023 | <li key={app.url} className="flex items-center gap-3 px-4 py-2.5 text-sm"> |
| 1024 | <span className="min-w-0 grow"> |
| 1025 | <a href={app.url} className="block truncate font-mono text-[0.8125rem] hover:text-accent"> |
| 1026 | {host(app.url)} |
| 1027 | </a> |
| 1028 | <span className="text-xs text-muted"> |
| 1029 | {app.branch} |
| 1030 | {app.number != null && ( |
| 1031 | <> |
| 1032 | {" · "} |
| 1033 | <Link to={`${base}/pull/${app.number}`} className="hover:underline"> |
| 1034 | #{app.number} |
| 1035 | </Link> |
| 1036 | </> |
| 1037 | )} |
| 1038 | </span> |
| 1039 | </span> |
| 1040 | <span className="shrink-0 text-xs text-faint"> |
| 1041 | <TimeAgo at={app.deployedAt} /> |
| 1042 | </span> |
| 1043 | </li> |
| 1044 | ))} |
| 1045 | </ul> |
| 1046 | </Panel> |
| 1047 | )} |
| 1048 | </div> |
| 1049 | |
| 1050 | <aside className="space-y-4 text-sm"> |
| 1051 | {member && ( |
| 1052 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1053 | <div className="flex items-center justify-between"> |
| 1054 | <h2 className="flex items-center gap-1.5 text-sm font-semibold"> |
| 1055 | <Brain size={14} className="text-merged" /> |
| 1056 | What agents know here |
| 1057 | </h2> |
| 1058 | <Link to={`${base}/memory`} className="text-xs text-muted hover:text-fg"> |
| 1059 | Memory |
| 1060 | </Link> |
| 1061 | </div> |
| 1062 | {!loaderData.memoriesLoaded ? ( |
| 1063 | <p className="mt-3 text-xs text-muted">Memory could not be loaded just now.</p> |
| 1064 | ) : knows.length === 0 ? ( |
| 1065 | <p className="mt-3 text-xs leading-5 text-muted"> |
| 1066 | Nothing yet. Agents note conventions, decisions and traps as they work, and every agent starting here reads them. |
| 1067 | </p> |
| 1068 | ) : ( |
| 1069 | <ul className="mt-3 space-y-2.5"> |
| 1070 | {knows.map((memory) => ( |
| 1071 | <li key={memory.id} className="text-xs leading-5"> |
| 1072 | <p className="line-clamp-3 text-fg-soft"> |
| 1073 | {memory.pinned && <Pin size={11} className="mr-1 inline text-accent" />} |
| 1074 | {memory.text} |
| 1075 | </p> |
| 1076 | <p className="text-faint"> |
| 1077 | {memory.kind} · {memory.createdBy} · <TimeAgo at={memory.createdAt} /> |
| 1078 | </p> |
| 1079 | </li> |
| 1080 | ))} |
| 1081 | {loaderData.memoryCount > knows.length && ( |
| 1082 | <li> |
| 1083 | <Link to={`${base}/memory`} className="text-xs text-muted hover:text-fg"> |
| 1084 | {loaderData.memoryCount - knows.length} more |
| 1085 | </Link> |
| 1086 | </li> |
| 1087 | )} |
| 1088 | </ul> |
| 1089 | )} |
| 1090 | </section> |
| 1091 | )} |
| 1092 | |
| 1093 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1094 | <h2 className="flex items-center gap-1.5 text-sm font-semibold"> |
| 1095 | <HeartPulse size={14} className="text-faint" /> |
| 1096 | Health |
| 1097 | </h2> |
| 1098 | <div className="mt-4 space-y-4 text-xs"> |
| 1099 | <div> |
| 1100 | <div className="flex items-baseline justify-between"> |
| 1101 | <span className="text-muted">Checks passing</span> |
| 1102 | <span className="font-medium tabular-nums">{percent(health.passRate)}</span> |
| 1103 | </div> |
| 1104 | <div className="mt-1.5"> |
| 1105 | <Meter value={health.passRate} tone={health.passRate != null && health.passRate < 0.7 ? "bg-warn" : "bg-accent"} /> |
| 1106 | </div> |
| 1107 | <p className="mt-1 text-faint"> |
| 1108 | {health.checkRuns |
| 1109 | ? `${health.checkRuns} recent runs · ${percent(health.firstPass.rate)} pass on the first try` |
| 1110 | : "No checks have run recently."} |
| 1111 | </p> |
| 1112 | </div> |
| 1113 | {member && (!library || builds.length > 0) && ( |
| 1114 | <div> |
| 1115 | <div className="flex items-baseline justify-between"> |
| 1116 | <span className="text-muted">Deploys</span> |
| 1117 | <Link to={`${base}/deployments`} className="text-faint hover:text-fg"> |
| 1118 | {builds.length ? `last ${Math.min(builds.length, 20)}` : "none yet"} |
| 1119 | </Link> |
| 1120 | </div> |
| 1121 | <div className="mt-1.5"> |
| 1122 | <DeployStrip builds={builds} base={base} /> |
| 1123 | </div> |
| 1124 | </div> |
| 1125 | )} |
| 1126 | <div> |
| 1127 | <div className="flex items-baseline justify-between"> |
| 1128 | <span className="text-muted">Open issues by age</span> |
| 1129 | <Link to={`${base}/issues`} className="font-medium tabular-nums hover:text-accent"> |
| 1130 | {open.issues} |
| 1131 | </Link> |
| 1132 | </div> |
| 1133 | {ages ? ( |
| 1134 | <ul className="mt-2 space-y-1.5"> |
| 1135 | {ages.map((bucket) => ( |
| 1136 | <li key={bucket.label} className="grid grid-cols-[6.5rem_1fr_1.5rem] items-center gap-2"> |
| 1137 | <span className="text-faint">{bucket.label}</span> |
| 1138 | <span className="block h-1.5 overflow-hidden rounded-full bg-line"> |
| 1139 | <span |
| 1140 | className={`block h-full rounded-full ${bucket.label === "Older" ? "bg-warn" : "bg-fg-soft/60"}`} |
| 1141 | style={{ width: `${(bucket.count / oldest) * 100}%` }} |
| 1142 | /> |
| 1143 | </span> |
| 1144 | <span className="text-right tabular-nums text-muted">{bucket.count}</span> |
| 1145 | </li> |
| 1146 | ))} |
| 1147 | </ul> |
| 1148 | ) : ( |
| 1149 | <p className="mt-1 text-faint">Issues could not be loaded just now.</p> |
| 1150 | )} |
| 1151 | </div> |
| 1152 | </div> |
| 1153 | </section> |
| 1154 | |
| 1155 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1156 | <div className="flex items-center justify-between"> |
| 1157 | <h2 className="flex items-center gap-1.5 text-sm font-semibold"> |
| 1158 | <Network size={14} className="text-faint" /> |
| 1159 | Dependencies |
| 1160 | </h2> |
| 1161 | {member && ( |
| 1162 | <Link to={`${base}/settings/dependencies`} className="text-xs text-muted hover:text-fg"> |
| 1163 | Manage |
| 1164 | </Link> |
| 1165 | )} |
| 1166 | </div> |
| 1167 | {!dependencies ? ( |
| 1168 | <p className="mt-3 text-xs text-muted">Dependencies could not be loaded just now.</p> |
| 1169 | ) : dependencies.dependsOn.length === 0 && dependencies.usedBy.length === 0 ? ( |
| 1170 | <p className="mt-3 text-xs leading-5 text-muted"> |
| 1171 | Uses no other project, and none uses it. Declare one, and builds get its address and agents know what depends on |
| 1172 | what. |
| 1173 | </p> |
| 1174 | ) : ( |
| 1175 | <div className="mt-3 space-y-3 text-xs"> |
| 1176 | {dependencies.dependsOn.length > 0 && ( |
| 1177 | <div> |
| 1178 | <p className="flex items-center gap-1 text-muted"> |
| 1179 | <ArrowUpRight size={12} /> Uses |
| 1180 | </p> |
| 1181 | <ul className="mt-1.5 space-y-1"> |
| 1182 | {dependencies.dependsOn.map((d) => ( |
| 1183 | <li key={d.slug} className="flex items-center justify-between gap-2"> |
| 1184 | <Link to={`/${params.owner}/${d.slug}`} className="font-medium hover:underline"> |
| 1185 | {d.name} |
| 1186 | </Link> |
| 1187 | {d.as && <code className="font-mono text-faint">{d.as}</code>} |
| 1188 | </li> |
| 1189 | ))} |
| 1190 | </ul> |
| 1191 | </div> |
| 1192 | )} |
| 1193 | {dependencies.usedBy.length > 0 && ( |
| 1194 | <div> |
| 1195 | <p className="flex items-center gap-1 text-muted"> |
| 1196 | <ArrowDownLeft size={12} /> Used by |
| 1197 | </p> |
| 1198 | <ul className="mt-1.5 space-y-1"> |
| 1199 | {dependencies.usedBy.map((d) => ( |
| 1200 | <li key={d.slug}> |
| 1201 | <Link to={`/${params.owner}/${d.slug}`} className="font-medium hover:underline"> |
| 1202 | {d.name} |
| 1203 | </Link> |
| 1204 | </li> |
| 1205 | ))} |
| 1206 | </ul> |
| 1207 | </div> |
| 1208 | )} |
| 1209 | </div> |
| 1210 | )} |
| 1211 | </section> |
| 1212 | |
| 1213 | {source && ( |
| 1214 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1215 | <h2 className="text-sm font-semibold">Clone</h2> |
| 1216 | <div className="mt-3"> |
| 1217 | <CopyLine text={`git clone ${cloneUrl(addresses, `${source.repo.namespace}/${source.repo.name}`)}`} /> |
| 1218 | </div> |
| 1219 | </section> |
| 1220 | )} |
| 1221 | </aside> |
| 1222 | </div> |
| 1223 | </div> |
| 1224 | ); |
| 1225 | } |