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.

fix(commits): show the agent trend when a server omits the enabled flag (#4306)

Raghav Chamadiya30d74d64e893
diff --git a/packages/api-client/src/types/git.ts b/packages/api-client/src/types/git.ts
index d68d2bb8a..0264f0f87 100644
--- a/packages/api-client/src/types/git.ts
+++ b/packages/api-client/src/types/git.ts
@@ -237,7 +237,7 @@ export interface AgentTrendBucket extends AttributionShareFields {
}
export interface AgentTrend extends AttributionShareFields {
- enabled: boolean;
+ enabled?: boolean;
coverage_floor_pct: number;
buckets: AgentTrendBucket[];
agent_names: { name: string; count: number }[];
diff --git a/packages/types/src/git.ts b/packages/types/src/git.ts
index e6c8f4dfe..7e29c9833 100644
--- a/packages/types/src/git.ts
+++ b/packages/types/src/git.ts
@@ -293,7 +293,9 @@ export interface AgentTrendBucket extends AttributionShareFields {
/** Monthly attribution trend across the indexed commit window. `enabled` is
* false, with every figure empty, when attribution is off for the repo. */
export interface AgentTrend extends AttributionShareFields {
- enabled: boolean;
+ /** Absent from a server that does not send it; a trend carrying
+ * `agent_pct_of_covered` then reads as on. */
+ enabled?: boolean;
coverage_floor_pct: number;
buckets: AgentTrendBucket[];
agent_names: { name: string; count: number }[];
diff --git a/packages/ui/__tests__/commits/agent-trend-strip.test.tsx b/packages/ui/__tests__/commits/agent-trend-strip.test.tsx
new file mode 100644
index 000000000..6c948cd19
--- /dev/null
+++ b/packages/ui/__tests__/commits/agent-trend-strip.test.tsx
@@ -0,0 +1,39 @@
+import { describe, expect, it } from "vitest";
+import { render } from "@testing-library/react";
+import type { AgentTrend } from "@repowise-dev/types/git";
+
+import { AgentTrendStrip } from "../../src/commits/agent-trend-strip";
+
+const trend = (over: Partial<AgentTrend> = {}): AgentTrend => ({
+ enabled: true,
+ total_commits: 40,
+ agent_commits: 10,
+ human_attested_commits: 20,
+ unknown_commits: 10,
+ coverage_pct: 75,
+ agent_pct_of_covered: 33.3,
+ suppressed_reason: null,
+ coverage_floor_pct: 20,
+ buckets: [],
+ agent_names: [{ name: "claude", count: 10 }],
+ ...over,
+});
+
+describe("AgentTrendStrip", () => {
+ it("renders nothing when attribution is off", () => {
+ const { container } = render(<AgentTrendStrip trend={trend({ enabled: false })} />);
+ expect(container.textContent).toBe("");
+ });
+
+ it("reads a trend with no enabled flag as on when it carries the share", () => {
+ const { enabled: _e, ...unflagged } = trend();
+ const { container } = render(<AgentTrendStrip trend={unflagged} />);
+ expect(container.textContent).toContain("33%");
+ });
+
+ it("stays hidden for a trend with neither the flag nor the share", () => {
+ const { enabled: _e, agent_pct_of_covered: _p, ...older } = trend();
+ const { container } = render(<AgentTrendStrip trend={older as AgentTrend} />);
+ expect(container.textContent).toBe("");
+ });
+});
diff --git a/packages/ui/src/commits/agent-trend-strip.tsx b/packages/ui/src/commits/agent-trend-strip.tsx
index e7198e8e9..d7d7d68e9 100644
--- a/packages/ui/src/commits/agent-trend-strip.tsx
+++ b/packages/ui/src/commits/agent-trend-strip.tsx
@@ -23,7 +23,10 @@ function share(part: number, whole: number): number {
* commit in the window carries agent attribution.
*/
export function AgentTrendStrip({ trend, className }: AgentTrendStripProps) {
- if (!trend.enabled || trend.agent_commits === 0) return null;
+ // A server that omits `enabled` has no off switch: a trend that carries the
+ // coverage-aware share is on, and an older shape without it stays hidden.
+ const enabled = trend.enabled ?? "agent_pct_of_covered" in trend;
+ if (!enabled || trend.agent_commits === 0) return null;
// Cap the strip at the last 12 months so it stays a glanceable sparkline.
const buckets = trend.buckets.slice(-12);
const topAgents = trend.agent_names.slice(0, 3);
diff --git a/packages/web/src/components/commits/commits-view.tsx b/packages/web/src/components/commits/commits-view.tsx
index 7d3474ed9..10bc4fbf6 100644
--- a/packages/web/src/components/commits/commits-view.tsx
+++ b/packages/web/src/components/commits/commits-view.tsx
@@ -133,7 +133,7 @@ export async function CommitsView({
</OverviewSection>
)}
- {trend && trend.enabled && trend.agent_commits > 0 && <AgentTrendStrip trend={trend} />}
+ {trend && <AgentTrendStrip trend={trend} />}
<OverviewSection
title={t("scoreBehaviourTitle")}