Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

feat(goals): context + memory on the check log, honest window-pressure story

Yuting Zhong649f03b8700f
diff --git a/notfair/src/app/(app)/[project]/goals/[agent]/checks/[thread]/page.tsx b/notfair/src/app/(app)/[project]/goals/[agent]/checks/[thread]/page.tsx
index cc442222..33ba2db5 100644
--- a/notfair/src/app/(app)/[project]/goals/[agent]/checks/[thread]/page.tsx
+++ b/notfair/src/app/(app)/[project]/goals/[agent]/checks/[thread]/page.tsx
@@ -3,13 +3,20 @@ import { notFound } from "next/navigation";
import { ArrowLeft } from "lucide-react";
import { getProject } from "@/server/db/projects";
import { resolveAgentBySlug } from "@/server/agent-meta";
-import { getGoalForAgent, getLatestGoalForAgent } from "@/server/db/goals";
+import {
+ getGoalForAgent,
+ getLatestGoalForAgent,
+ listGoalLearnings,
+} from "@/server/db/goals";
import { listSessionsForAgent } from "@/server/sessions/view";
import { readTranscriptTail } from "@/server/sessions/transcript-tail";
import { getMcpCatalog } from "@/server/mcp-catalog";
+import { DEFAULT_HARNESS_ADAPTER, requireAdapter } from "@/server/adapters/registry";
import { projectHref } from "@/lib/project-href";
import { goalLabel } from "@/lib/goal-label";
import { LiveTranscript } from "@/components/live-transcript";
+import { GoalContextDialog } from "@/components/goal-context-dialog";
+import { GoalMemoryDialog } from "@/components/goal-memory-dialog";
export const dynamic = "force-dynamic";
@@ -44,6 +51,12 @@ export default async function CheckTranscriptPage({
display_name: m.display_name,
resource_url: m.resource_url,
}));
+ const modelOptions = await requireAdapter(
+ project.harness_adapter ?? DEFAULT_HARNESS_ADAPTER,
+ ).listModels();
+ // A check runs as the same agent as the goal chat: identical identity,
+ // tools, and learnings ledger — only the conversation is the tick's own.
+ const learnings = goal ? listGoalLearnings(goal.id, 100) : [];
return (
<div className="flex min-h-0 flex-1 flex-col">
@@ -58,6 +71,26 @@ export default async function CheckTranscriptPage({
<h1 className="m-0 min-w-0 truncate text-[14px] font-semibold">
{goal ? goalLabel(goal) : resolved.name} — check log
</h1>
+ <div className="ml-auto flex shrink-0 items-center gap-2">
+ <GoalContextDialog
+ projectSlug={slug}
+ agentId={resolved.agent_id}
+ threadId={threadId}
+ models={modelOptions.map((m) => ({
+ value: m.value,
+ label: m.label,
+ context_window: m.context_window,
+ }))}
+ />
+ <GoalMemoryDialog
+ entries={learnings.map((l) => ({
+ id: l.id,
+ body: l.body,
+ confidence: l.confidence,
+ created_at: l.created_at,
+ }))}
+ />
+ </div>
</header>
<div className="min-h-0 flex-1">
<LiveTranscript
diff --git a/notfair/src/components/goal-context-dialog.test.tsx b/notfair/src/components/goal-context-dialog.test.tsx
new file mode 100644
index 00000000..d86a3553
--- /dev/null
+++ b/notfair/src/components/goal-context-dialog.test.tsx
@@ -0,0 +1,70 @@
+// @vitest-environment jsdom
+import { fireEvent, render, screen } from "@testing-library/react";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { GoalContextDialog } from "@/components/goal-context-dialog";
+
+// Mock at the server-action boundary, per repo test conventions.
+const getContext = vi.hoisted(() => vi.fn());
+vi.mock("@/server/actions/context", () => ({
+ getGoalContextAction: getContext,
+}));
+
+const props = {
+ projectSlug: "proj",
+ agentSlug: "goal-1",
+ agentId: "agent-1",
+ threadId: "tick-7",
+ models: [{ value: "opus", label: "Opus", context_window: 1000 }],
+};
+
+function contextOf(totalTokens: number) {
+ return {
+ ok: true,
+ total_tokens: totalTokens,
+ chunks: [
+ {
+ key: "identity",
+ label: "Agent instructions",
+ group: "instructions",
+ chars: totalTokens * 4,
+ tokens: totalTokens,
+ content: "You are goal-1.",
+ format: "markdown",
+ },
+ ],
+ };
+}
+
+async function openDialog() {
+ fireEvent.click(screen.getByRole("button", { name: /context/i }));
+ await screen.findByText(/agent instructions/i);
+}
+
+beforeEach(() => getContext.mockReset());
+
+describe("GoalContextDialog window pressure", () => {
+ it("stays quiet while the window has comfortable headroom", async () => {
+ getContext.mockResolvedValueOnce(contextOf(500)); // 50% of 1000
+ render(<GoalContextDialog {...props} />);
+ await openDialog();
+ expect(screen.queryByText(/approaching the window/i)).toBeNull();
+ expect(screen.getByText(/50\.0% used/)).toBeInTheDocument();
+ });
+
+ it("explains auto-compaction when usage nears the window", async () => {
+ getContext.mockResolvedValueOnce(contextOf(850)); // 85% of 1000
+ render(<GoalContextDialog {...props} />);
+ await openDialog();
+ expect(screen.getByText(/approaching the window/i)).toBeInTheDocument();
+ expect(screen.getByText(/automatically compacts/i)).toBeInTheDocument();
+ });
+
+ it("reports an outgrown window with an honest >100% figure", async () => {
+ getContext.mockResolvedValueOnce(contextOf(1250)); // 125% of 1000
+ render(<GoalContextDialog {...props} />);
+ await openDialog();
+ expect(screen.getByText(/outgrown the window/i)).toBeInTheDocument();
+ expect(screen.getByText(/125\.0% used/)).toBeInTheDocument();
+ });
+});
diff --git a/notfair/src/components/goal-context-dialog.tsx b/notfair/src/components/goal-context-dialog.tsx
index 9683f973..397dcb2b 100644
--- a/notfair/src/components/goal-context-dialog.tsx
+++ b/notfair/src/components/goal-context-dialog.tsx
@@ -156,7 +156,7 @@ export function GoalContextDialog({
<span className="text-[hsl(var(--notfair-ink-4))]"> of </span>
{fmtK(window)}
<span className="ml-2 text-[13px] font-normal text-[hsl(var(--notfair-ink-3))]">
- {pct(state.total).toFixed(1)}% used
+ {((state.total / window) * 100).toFixed(1)}% used
</span>
</>
) : (
@@ -182,6 +182,26 @@ export function GoalContextDialog({
</label>
</div>
+ {/* Near/over the window: say what actually happens, before the
+ user has to wonder. The harness compacts on its own; the
+ goal's operating state never lives in the window. */}
+ {window !== undefined && state.total >= window * 0.8 && (
+ <div className="rounded-md bg-[hsl(var(--notfair-warn-soft))] px-3 py-2 text-[12px] leading-relaxed text-[hsl(var(--notfair-warn))]">
+ <b>
+ {state.total >= window
+ ? "This conversation has outgrown the window."
+ : "Approaching the window."}
+ </b>{" "}
+ The harness automatically compacts older turns to keep the
+ thread going — nothing breaks, but compacted turns are
+ summarized and lose detail. The goal itself is not at risk:
+ its metric, actions, and memory live in NotFair&rsquo;s
+ database, the agent&rsquo;s instructions are re-sent every
+ turn, and every check runs from a fresh, self-contained
+ brief.
+ </div>
+ )}
+
{/* Stacked bar of the WHOLE window; the muted tail is free space. */}
<div
className="flex h-4 w-full overflow-hidden rounded-md"