Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

1.6 KB
Raw Blame
"use client";

import { useEffect, useRef } from "react";
import { ScrollArea } from "../ui/scroll-area";
import { cn } from "../lib/cn";

export interface JobLogEntry {
  text: string;
  /** Pipeline message level ("info", "warning", "error"); tints the line. */
  level?: string | number;
}

interface JobLogProps {
  entries: JobLogEntry[];
  maxLines?: number;
}

function levelClass(level: JobLogEntry["level"]): string {
  if (level === "error") return "text-[var(--color-outdated)]";
  if (level === "warning") return "text-[var(--color-warning)]";
  return "text-[var(--color-text-tertiary)]";
}

export function JobLog({ entries, maxLines = 6 }: JobLogProps) {
  const bottomRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    bottomRef.current?.scrollIntoView({ behavior: "smooth" });
  }, [entries]);

  const visible = entries.slice(-maxLines);

  return (
    // Radix wraps the viewport's content in a `display:table` div that grows to
    // its widest line, so `truncate` below never applied and a long line
    // widened the whole panel. `block` holds the content to the panel's width.
    <ScrollArea
      className="h-28 rounded border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)]"
      viewportClassName="[&>div]:block!"
    >
      <div className="p-2 space-y-0.5 font-mono text-xs">
        {visible.map((e, i) => (
          <div key={i} className={cn("leading-5 truncate", levelClass(e.level))}>
            <span className="text-[var(--color-accent-primary)] mr-1">›</span>
            {e.text}
          </div>
        ))}
        <div ref={bottomRef} />
      </div>
    </ScrollArea>
  );
}