Open-source SEO, GEO, and marketing skills for AI agents.
feat(goals): "Action taken" filter on the Checks rail
Yuting Zhongb4797b34348a
diff --git a/notfair/src/components/goal-checks-list.test.tsx b/notfair/src/components/goal-checks-list.test.tsxindex 3c66f247..5f82d162 100644--- a/notfair/src/components/goal-checks-list.test.tsx+++ b/notfair/src/components/goal-checks-list.test.tsx@@ -1,5 +1,5 @@// @vitest-environment jsdom-import { act, render, screen } from "@testing-library/react";+import { act, fireEvent, render, screen } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { GoalChecksList } from "@/components/goal-checks-list";@@ -44,6 +44,7 @@ function row(tick_number: number, over: Partial<CheckRow> = {}): CheckRow {started_at: "2026-07-15T00:00:00.000Z",finished_at: "2026-07-15T00:01:00.000Z",prs: [],+ actions_count: 0,...over,} as CheckRow;}@@ -103,7 +104,7 @@ describe("GoalChecksList", () => {/>,);await tripSentinel();- expect(loadMore).toHaveBeenCalledWith("g1", 3); // strictly older than shown+ expect(loadMore).toHaveBeenCalledWith("g1", 3, undefined); // strictly older than shownexpect(screen.getByText("summary 1")).toBeInTheDocument();expect(screen.getAllByText(/^Check/)).toHaveLength(4);});@@ -132,4 +133,64 @@ describe("GoalChecksList", () => {expect(screen.getByText("updated 4")).toBeInTheDocument();expect(screen.getByText("summary 1")).toBeInTheDocument(); // history kept});++ it("Action taken hides observe-only checks and fetches the filtered page", async () => {+ loadMore.mockResolvedValueOnce({+ rows: [row(1, { actions_count: 2 })],+ hasMore: false,+ });+ render(+ <GoalChecksList+ {...baseProps}+ initialRows={[+ row(4),+ row(3, { actions_count: 1 }),+ row(2, {+ prs: [+ {+ id: "pr1",+ url: "https://github.com/acme/site/pull/9",+ title: "Add FAQ",+ state: "open",+ },+ ],+ }),+ ]}+ initialHasMore={false}+ />,+ );++ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: "Action taken" }));+ });++ // First toggle fetches the newest filtered page from the server.+ expect(loadMore).toHaveBeenCalledWith("g1", undefined, "action");+ // Observe-only check 4 is hidden; action check 3, PR check 2, and the+ // server-fetched check 1 remain.+ expect(screen.queryByText("summary 4")).not.toBeInTheDocument();+ expect(screen.getByText("summary 3")).toBeInTheDocument();+ expect(screen.getByText("summary 2")).toBeInTheDocument();+ expect(screen.getByText("summary 1")).toBeInTheDocument();++ // Switching back shows everything again without another fetch.+ fireEvent.click(screen.getByRole("button", { name: "All" }));+ expect(screen.getByText("summary 4")).toBeInTheDocument();+ expect(loadMore).toHaveBeenCalledTimes(1);+ });++ it("shows an empty message when no check took action", async () => {+ loadMore.mockResolvedValueOnce({ rows: [], hasMore: false });+ render(+ <GoalChecksList+ {...baseProps}+ initialRows={[row(2), row(1)]}+ initialHasMore={false}+ />,+ );+ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: "Action taken" }));+ });+ expect(screen.getByText("No checks took action yet.")).toBeInTheDocument();+ });});diff --git a/notfair/src/components/goal-checks-list.tsx b/notfair/src/components/goal-checks-list.tsxindex d28033ae..1a53669b 100644--- a/notfair/src/components/goal-checks-list.tsx+++ b/notfair/src/components/goal-checks-list.tsx@@ -4,7 +4,7 @@ import Link from "next/link";import { useEffect, useRef, useState } from "react";import { Loader2 } from "lucide-react";import { loadMoreGoalChecksAction } from "@/server/actions/goals";-import type { CheckPr, CheckRow } from "@/server/goals/checks";+import type { CheckFilter, CheckPr, CheckRow } from "@/server/goals/checks";import { projectHref } from "@/lib/project-href";import { formatMetric } from "@/lib/format-metric";import { timeAgo } from "@/lib/time-ago";@@ -16,6 +16,11 @@ import { Markdown } from "@/components/markdown";* checks stream in as the sentinel scrolls into view (cursor-paged by* tick_number). The page's 5s auto-refresh re-sends the first page, which* is merged in by id so freshly loaded history is never dropped.+ *+ * The "Action taken" filter hides observe-only checks (no action recorded,+ * no PR). Rows are kept in one merged store and filtered at render time,+ * so the auto-refresh merge stays filter-agnostic; pagination re-queries+ * the server with the filter so skipped checks don't count against pages.*/export function GoalChecksList({slug,@@ -31,20 +36,43 @@ export function GoalChecksList({initialHasMore: boolean;}) {const [rows, setRows] = useState<CheckRow[]>(initialRows);- // Only load responses update hasMore: a refresh of the first page says- // nothing about whether history below the loaded window remains.- const [hasMore, setHasMore] = useState(initialHasMore);+ const [filter, setFilter] = useState<CheckFilter>("all");+ // hasMore is tracked per filter: only load responses for a given filter+ // update it. "action" starts unknown (null) until its first page loads.+ const [hasMoreAll, setHasMoreAll] = useState(initialHasMore);+ const [hasMoreAction, setHasMoreAction] = useState<boolean | null>(null);const [loading, setLoading] = useState(false);const loadingRef = useRef(false);const sentinelRef = useRef<HTMLDivElement | null>(null);- // The observer callback outlives renders; read rows through a ref.- const rowsRef = useRef(rows);- rowsRef.current = rows;+ const visible = filter === "action" ? rows.filter(tookAction) : rows;+ // The observer callback outlives renders; read visible rows via a ref.+ const visibleRef = useRef(visible);+ visibleRef.current = visible;useEffect(() => {setRows((prev) => mergeRows(prev, initialRows));}, [initialRows]);+ // First switch to "Action taken": the loaded window may hold few or no+ // matching rows, so fetch the newest filtered page from the server.+ useEffect(() => {+ if (filter !== "action" || hasMoreAction !== null) return;+ if (loadingRef.current) return;+ loadingRef.current = true;+ setLoading(true);+ loadMoreGoalChecksAction(goalId, undefined, "action")+ .then((res) => {+ setRows((prev) => mergeRows(prev, res.rows));+ setHasMoreAction(res.hasMore);+ })+ .finally(() => {+ loadingRef.current = false;+ setLoading(false);+ });+ }, [filter, hasMoreAction, goalId]);++ const hasMore = filter === "action" ? (hasMoreAction ?? false) : hasMoreAll;+useEffect(() => {const el = sentinelRef.current;if (!el || !hasMore) return;@@ -54,10 +82,17 @@ export function GoalChecksList({loadingRef.current = true;setLoading(true);try {- const oldest = Math.min(...rowsRef.current.map((r) => r.tick_number));- const res = await loadMoreGoalChecksAction(goalId, oldest);+ const shown = visibleRef.current;+ const oldest =+ shown.length > 0 ? Math.min(...shown.map((r) => r.tick_number)) : undefined;+ const res = await loadMoreGoalChecksAction(+ goalId,+ oldest,+ filter === "action" ? "action" : undefined,+ );setRows((prev) => mergeRows(prev, res.rows));- setHasMore(res.hasMore);+ if (filter === "action") setHasMoreAction(res.hasMore);+ else setHasMoreAll(res.hasMore);} finally {loadingRef.current = false;setLoading(false);@@ -65,18 +100,32 @@ export function GoalChecksList({});io.observe(el);return () => io.disconnect();- }, [goalId, hasMore]);+ }, [goalId, hasMore, filter]);if (rows.length === 0) return null;return (<>- <ul className="m-0 flex list-none flex-col divide-y divide-border/40 p-0">- {rows.map((t) => (- <CheckItem key={t.id} slug={slug} agentSlug={agentSlug} tick={t} />- ))}- </ul>- {hasMore && (+ <div className="mb-2 flex items-center gap-1" role="group" aria-label="Filter checks">+ <FilterButton active={filter === "all"} onClick={() => setFilter("all")}>+ All+ </FilterButton>+ <FilterButton active={filter === "action"} onClick={() => setFilter("action")}>+ Action taken+ </FilterButton>+ </div>+ {visible.length === 0 && !loading ? (+ <p className="m-0 text-[12px] text-[hsl(var(--notfair-ink-4))]">+ No checks took action yet.+ </p>+ ) : (+ <ul className="m-0 flex list-none flex-col divide-y divide-border/40 p-0">+ {visible.map((t) => (+ <CheckItem key={t.id} slug={slug} agentSlug={agentSlug} tick={t} />+ ))}+ </ul>+ )}+ {(hasMore || loading) && (<div ref={sentinelRef} className="flex justify-center py-2">{loading && (<Loader2 className="size-3.5 animate-spin text-[hsl(var(--notfair-ink-4))]" />@@ -87,6 +136,37 @@ export function GoalChecksList({);}+/** A check "took action" when it recorded an action or registered a PR. */+function tookAction(row: CheckRow): boolean {+ return row.actions_count > 0 || row.prs.length > 0;+}++function FilterButton({+ active,+ onClick,+ children,+}: {+ active: boolean;+ onClick: () => void;+ children: React.ReactNode;+}) {+ return (+ <button+ type="button"+ onClick={onClick}+ aria-pressed={active}+ className={cn(+ "cursor-pointer rounded-md px-2 py-1 text-[11px] font-medium transition-colors",+ active+ ? "bg-[hsl(var(--notfair-surface-2))] text-[hsl(var(--notfair-ink-2))]"+ : "text-[hsl(var(--notfair-ink-4))] hover:text-[hsl(var(--notfair-ink-3))]",+ )}+ >+ {children}+ </button>+ );+}+/** Upsert incoming rows by id, newest check first. */function mergeRows(prev: CheckRow[], incoming: CheckRow[]): CheckRow[] {const byId = new Map(prev.map((r) => [r.id, r]));diff --git a/notfair/src/server/actions/goals.ts b/notfair/src/server/actions/goals.tsindex 82696189..edb20f83 100644--- a/notfair/src/server/actions/goals.ts+++ b/notfair/src/server/actions/goals.ts@@ -25,7 +25,7 @@ import {import { agentExistsOnDisk, listProjectAgents } from "@/server/agent-meta";import { runGoalIntake } from "@/server/goals/intake";import { runGoalTick } from "@/server/goals/tick";-import { listCheckRows, type CheckRow } from "@/server/goals/checks";+import { listCheckRows, type CheckFilter, type CheckRow } from "@/server/goals/checks";export type GoalActionResult = {ok: boolean;@@ -267,15 +267,18 @@ export async function getAgentGoalAction(agent_id: string) {}/**- * Older diary page for the goal screen's Checks list — checks strictly- * older than `beforeTick`, newest first. Cursor pagination (not offset)- * so rows never shift under the reader when a new check lands mid-scroll.+ * Diary page for the goal screen's Checks list — checks strictly older+ * than `beforeTick` (omit for the newest page), newest first. Cursor+ * pagination (not offset) so rows never shift under the reader when a+ * new check lands mid-scroll. `filter: "action"` keeps only checks that+ * recorded an action or registered a PR.*/export async function loadMoreGoalChecksAction(goal_id: string,- beforeTick: number,+ beforeTick?: number,+ filter?: CheckFilter,): Promise<{ rows: CheckRow[]; hasMore: boolean }> {const goal = getGoal(goal_id);if (!goal) return { rows: [], hasMore: false };- return listCheckRows(goal.id, { beforeTick });+ return listCheckRows(goal.id, { beforeTick, filter });}diff --git a/notfair/src/server/db/goals.ts b/notfair/src/server/db/goals.tsindex 3908f9bc..72f62c19 100644--- a/notfair/src/server/db/goals.ts+++ b/notfair/src/server/db/goals.ts@@ -881,6 +881,21 @@ export function listGoalTicks(.all(goal_id, limit) as GoalTick[];}+/** Specific ticks by number, newest first — backs the filtered checks list. */+export function listGoalTicksByNumbers(+ goal_id: string,+ tickNumbers: number[],+): GoalTick[] {+ if (tickNumbers.length === 0) return [];+ const placeholders = tickNumbers.map(() => "?").join(",");+ return getDb()+ .prepare(+ `SELECT * FROM goal_ticks WHERE goal_id = ? AND tick_number IN (${placeholders})+ ORDER BY tick_number DESC`,+ )+ .all(goal_id, ...tickNumbers) as GoalTick[];+}+/*** Most recent finished tick that carries context worth briefing the next* turn with: agent turns (session attached) and failures. Observe-onlydiff --git a/notfair/src/server/goals/checks.test.ts b/notfair/src/server/goals/checks.test.tsindex c62088c1..2066dec7 100644--- a/notfair/src/server/goals/checks.test.ts+++ b/notfair/src/server/goals/checks.test.ts@@ -74,6 +74,68 @@ describe("listCheckRows paging", () => {});});+describe("listCheckRows action filter", () => {+ it("annotates every row with its action count", () => {+ seedTicks(3);+ createGoalAction({+ goal_id: goalId,+ tick_number: 2,+ kind: "mutation",+ description: "Pause wasted keywords",+ expected_effect: "less waste",+ review_after: null,+ });+ createGoalAction({+ goal_id: goalId,+ tick_number: 2,+ kind: "research",+ description: "Read search terms",+ expected_effect: "context",+ review_after: null,+ });+ const { rows } = listCheckRows(goalId);+ expect(rows.map((r) => [r.tick_number, r.actions_count])).toEqual([+ [3, 0],+ [2, 2],+ [1, 0],+ ]);+ });++ it("filter=action keeps only checks with actions or PRs, cursor-paged", () => {+ seedTicks(6);+ createGoalAction({+ goal_id: goalId,+ tick_number: 5,+ kind: "mutation",+ description: "Raise budget",+ expected_effect: "more clicks",+ review_after: null,+ });+ createGoalAction({+ goal_id: goalId,+ tick_number: 2,+ kind: "decision",+ description: "Hold steady",+ expected_effect: "n/a",+ review_after: null,+ });+ createGoalPr({+ goal_id: goalId,+ url: "https://github.com/acme/site/pull/7",+ title: "Fix titles",+ tick_number: 4,+ });++ const first = listCheckRows(goalId, { filter: "action", limit: 2 });+ expect(first.rows.map((r) => r.tick_number)).toEqual([5, 4]);+ expect(first.hasMore).toBe(true);++ const next = listCheckRows(goalId, { filter: "action", limit: 2, beforeTick: 4 });+ expect(next.rows.map((r) => r.tick_number)).toEqual([2]);+ expect(next.hasMore).toBe(false);+ });+});+describe("listCheckRows PR attachment", () => {it("attaches a PR to the check stamped on it at registration", () => {seedTicks(3);diff --git a/notfair/src/server/goals/checks.ts b/notfair/src/server/goals/checks.tsindex a78af53e..e2f49666 100644--- a/notfair/src/server/goals/checks.ts+++ b/notfair/src/server/goals/checks.ts@@ -1,4 +1,9 @@-import { listGoalActions, listGoalTicks, type GoalTick } from "@/server/db/goals";+import {+ listGoalActions,+ listGoalTicks,+ listGoalTicksByNumbers,+ type GoalTick,+} from "@/server/db/goals";import { listGoalPrs, type GoalPrState } from "@/server/db/goal-prs";/**@@ -14,25 +19,30 @@ export type CheckPr = {state: GoalPrState;};-export type CheckRow = GoalTick & { prs: CheckPr[] };+export type CheckRow = GoalTick & { prs: CheckPr[]; actions_count: number };++/** "action" keeps only checks that did something: recorded an action+ * (MCP mutation, research note, decision) or registered a PR. */+export type CheckFilter = "all" | "action";export const CHECKS_PAGE_SIZE = 10;export function listCheckRows(goal_id: string,- opts: { limit?: number; beforeTick?: number } = {},+ opts: { limit?: number; beforeTick?: number; filter?: CheckFilter } = {},): { rows: CheckRow[]; hasMore: boolean } {const limit = opts.limit ?? CHECKS_PAGE_SIZE;- // Fetch one extra row purely to learn whether another page exists.- const ticks = listGoalTicks(goal_id, limit + 1, opts.beforeTick);- const hasMore = ticks.length > limit;- const page = ticks.slice(0, limit);++ const actions = listGoalActions(goal_id, 200);+ const actionCountByTick = new Map<number, number>();+ for (const a of actions) {+ if (a.tick_number == null) continue;+ actionCountByTick.set(a.tick_number, (actionCountByTick.get(a.tick_number) ?? 0) + 1);+ }// PRs registered before tick stamping existed resolve their check// through the linked action instead.- const actionTicks = new Map(- listGoalActions(goal_id, 200).map((a) => [a.id, a.tick_number]),- );+ const actionTicks = new Map(actions.map((a) => [a.id, a.tick_number]));const prsByTick = new Map<number, CheckPr[]>();for (const pr of listGoalPrs(goal_id, 100)) {const tickNo =@@ -44,8 +54,31 @@ export function listCheckRows(]);}+ let page: GoalTick[];+ let hasMore: boolean;+ if (opts.filter === "action") {+ // The eligible set is small and known upfront (bounded by the action/PR+ // fetch limits above), so page over its tick numbers directly.+ const eligible = [+ ...new Set([...actionCountByTick.keys(), ...prsByTick.keys()]),+ ]+ .filter((n) => opts.beforeTick === undefined || n < opts.beforeTick)+ .sort((a, b) => b - a);+ hasMore = eligible.length > limit;+ page = listGoalTicksByNumbers(goal_id, eligible.slice(0, limit));+ } else {+ // Fetch one extra row purely to learn whether another page exists.+ const ticks = listGoalTicks(goal_id, limit + 1, opts.beforeTick);+ hasMore = ticks.length > limit;+ page = ticks.slice(0, limit);+ }+return {- rows: page.map((t) => ({ ...t, prs: prsByTick.get(t.tick_number) ?? [] })),+ rows: page.map((t) => ({+ ...t,+ prs: prsByTick.get(t.tick_number) ?? [],+ actions_count: actionCountByTick.get(t.tick_number) ?? 0,+ })),hasMore,};}