fix: tab title followups — empty name guard, dedupe truncation

- Guard against empty project name in getProjectName() and icon.tsx
  (falls back to config key or "A" initial)
- Extract branch truncation into shared `truncate()` helper in
  session detail page
- Addresses bugbot comments from PR #111

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Prateek 2026-02-19 07:00:53 +05:30
parent b605ee8ed4
commit ab6ef71c89
3 changed files with 9 additions and 13 deletions

View File

@ -15,7 +15,7 @@ function stringToHue(s: string): number {
export default function Icon() {
const name = getProjectName();
const initial = name.charAt(0).toUpperCase();
const initial = (name.charAt(0) || "A").toUpperCase();
const hue = stringToHue(name);
return new ImageResponse(

View File

@ -6,6 +6,10 @@ import { SessionDetail } from "@/components/SessionDetail";
import type { DashboardSession } from "@/lib/types";
import { activityIcon } from "@/lib/activity-icons";
function truncate(s: string, max: number): string {
return s.length > max ? s.slice(0, max) + "..." : s;
}
/** Build a descriptive tab title from session data. */
function buildSessionTitle(session: DashboardSession): string {
const id = session.id;
@ -17,18 +21,9 @@ function buildSessionTitle(session: DashboardSession): string {
if (isOrchestrator) {
detail = "Orchestrator Terminal";
} else if (session.pr) {
const prNum = `#${session.pr.number}`;
const branch = session.pr.branch;
const maxBranch = 30;
const truncated = branch.length > maxBranch ? branch.slice(0, maxBranch) + "..." : branch;
detail = `${prNum} ${truncated}`;
detail = `#${session.pr.number} ${truncate(session.pr.branch, 30)}`;
} else if (session.branch) {
const maxBranch = 30;
const truncated =
session.branch.length > maxBranch
? session.branch.slice(0, maxBranch) + "..."
: session.branch;
detail = truncated;
detail = truncate(session.branch, 30);
} else {
detail = "Session Detail";
}

View File

@ -14,7 +14,8 @@ export const getProjectName = cache((): string => {
const config = loadConfig();
const firstKey = Object.keys(config.projects)[0];
if (firstKey) {
return config.projects[firstKey].name ?? firstKey;
const name = config.projects[firstKey].name ?? firstKey;
return name || firstKey || "ao";
}
} catch {
// Config not available