Skip to content

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

fix(chat): PostHog exec reads "Ran a query" even on label-less legacy rows

Yuting Zhongdd99500cbb7c
diff --git a/notfair/src/components/chat/tool-intent.ts b/notfair/src/components/chat/tool-intent.ts
index bf104110..e1a7f2d1 100644
--- a/notfair/src/components/chat/tool-intent.ts
+++ b/notfair/src/components/chat/tool-intent.ts
@@ -104,7 +104,7 @@ export function humanizeTool(name: string, label: string | null): ToolIntent {
return { verb: "Searched the web", target: label ?? undefined };
// MCP / generic tool — strip namespace prefixes and speak the action
// in natural language ("Listed ad accounts", "Ran a query", …).
- return mcpActionIntent(formatToolName(name), label);
+ return mcpActionIntent(formatToolName(name), label, name);
}
/**
@@ -114,15 +114,23 @@ export function humanizeTool(name: string, label: string | null): ToolIntent {
* phrase and the rest names the object. Unknown verbs fall back to
* "Called <action>" — honest, never wrong.
*/
-function mcpActionIntent(action: string, label: string | null): ToolIntent {
+function mcpActionIntent(
+ action: string,
+ label: string | null,
+ fullName = "",
+): ToolIntent {
const pretty = prettifyToolAction(action); // e.g. "list ad accounts"
const [head = "", ...rest] = pretty.split(" ");
const obj = rest.join(" ");
const target = label ?? undefined;
// SQL-looking labels beat name heuristics: whatever the tool is called,
- // the user is looking at a query.
+ // the user is looking at a query. Analytics servers whose exec IS a
+ // query engine (PostHog) qualify by name even for label-less legacy
+ // rows — their exec has no other meaning.
const sqlish =
- !!label && /^\s*(select|with|insert|delete\s+from|update\s+\w+\s+set)\b/i.test(label);
+ (!!label &&
+ /^\s*(select|with|insert|delete\s+from|update\s+\w+\s+set)\b/i.test(label)) ||
+ fullName.toLowerCase().includes("posthog");
switch (head.toLowerCase()) {
case "exec":
case "execute":
diff --git a/notfair/src/components/chat/transcript-model.test.ts b/notfair/src/components/chat/transcript-model.test.ts
index e61f2102..34c4212b 100644
--- a/notfair/src/components/chat/transcript-model.test.ts
+++ b/notfair/src/components/chat/transcript-model.test.ts
@@ -137,6 +137,11 @@ describe("humanizeTool", () => {
expect(humanizeTool("mcp__X__frobnicateWidget", null).verb).toBe(
"Called frobnicate widget",
);
+ // PostHog's exec is a query engine — label-less legacy rows still
+ // deserve the honest specific verb.
+ expect(humanizeTool("notfair_growth__posthog.exec", null).verb).toBe(
+ "Ran a query",
+ );
});
});
diff --git a/notfair/src/server/adapters/codex-local/parse.test.ts b/notfair/src/server/adapters/codex-local/parse.test.ts
new file mode 100644
index 00000000..5f88a31b
--- /dev/null
+++ b/notfair/src/server/adapters/codex-local/parse.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from "vitest";
+
+import { makeCodexStreamState, parseCodexLine } from "./parse";
+
+const line = (obj: unknown) => JSON.stringify(obj);
+
+describe("parseCodexLine — MCP tool labels", () => {
+ it("carries the query argument of an mcp_tool_call into the label", () => {
+ const events = parseCodexLine(
+ line({
+ type: "item.started",
+ item: {
+ type: "mcp_tool_call",
+ id: "item_1",
+ server: "notfair_growth__posthog",
+ tool: "exec",
+ arguments: {
+ query: "SELECT count() FROM events\nWHERE timestamp >= now()",
+ },
+ },
+ }),
+ makeCodexStreamState(),
+ );
+ expect(events).toHaveLength(1);
+ expect(events[0]).toMatchObject({
+ kind: "tool",
+ phase: "start",
+ name: "notfair_growth__posthog.exec",
+ // First line only, so the collapsed row stays one line.
+ label: "SELECT count() FROM events",
+ });
+ });
+
+ it("falls back to a compact key=value digest when no string field matches", () => {
+ const events = parseCodexLine(
+ line({
+ type: "item.started",
+ item: {
+ type: "mcp_tool_call",
+ id: "item_2",
+ server: "s",
+ tool: "updateCampaignBudget",
+ arguments: { campaign_id: 12345, amount_micros: 5_000_000, validate: true },
+ },
+ }),
+ makeCodexStreamState(),
+ );
+ expect(events[0]).toMatchObject({
+ label: "campaign_id=12345 amount_micros=5000000 validate=true",
+ });
+ });
+
+ it("leaves the label undefined when there are no arguments", () => {
+ const events = parseCodexLine(
+ line({
+ type: "item.started",
+ item: { type: "mcp_tool_call", id: "item_3", server: "s", tool: "t" },
+ }),
+ makeCodexStreamState(),
+ );
+ expect(events[0]).toMatchObject({ kind: "tool" });
+ expect((events[0] as { label?: string }).label).toBeUndefined();
+ });
+});