Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(agent): link the inbox report and the slack thread in pr footers (#130927)

Andrew Maguire8343e204a401
diff --git a/packages/agent/packages/agent/src/products/signal-report/product.ts b/packages/agent/packages/agent/src/products/signal-report/product.ts
index 6d71189ba8d2..b19d2e6a451f 100644
--- a/packages/agent/packages/agent/src/products/signal-report/product.ts
+++ b/packages/agent/packages/agent/src/products/signal-report/product.ts
@@ -8,14 +8,17 @@ export function signalReportProduct(): AgentProduct {
id: SIGNAL_REPORT_ORIGIN,
configureSession: ({ launch }) => {
const threadUrl = launch.launchOptions.slack_thread_url;
- const source =
+ const threadSource =
typeof threadUrl === "string" && threadUrl
? { label: "Slack thread", url: threadUrl }
- : launch.source;
+ : undefined;
return {
pullRequests: {
autoPublish: true,
- footer: buildPullRequestFooter(launch, { automated: true, source }),
+ footer: buildPullRequestFooter(launch, {
+ automated: true,
+ sources: [launch.source, threadSource],
+ }),
},
};
},
diff --git a/packages/agent/packages/agent/src/products/slack/product.ts b/packages/agent/packages/agent/src/products/slack/product.ts
index 946dc19bab1d..2ebe9cf682dc 100644
--- a/packages/agent/packages/agent/src/products/slack/product.ts
+++ b/packages/agent/packages/agent/src/products/slack/product.ts
@@ -85,9 +85,9 @@ export function slackProduct(): AgentProduct {
slackProgressChecklist: launchOptions.slack_app_agent_design_enabled,
};
const threadUrl = launchOptions.slack_thread_url;
- const footerSource = threadUrl
+ const threadSource = threadUrl
? { label: "Slack thread", url: threadUrl }
- : launch.source;
+ : undefined;
const closingInstructions =
slackReply && isBenjaminEnabled()
? SIMPLIFIED_TECHNICAL_ENGLISH_INSTRUCTION
@@ -116,7 +116,7 @@ export function slackProduct(): AgentProduct {
existingUrl: launchOptions.slack_notified_pr_url,
footer: buildPullRequestFooter(launch, {
automated: slackOrigin,
- source: footerSource,
+ sources: [launch.source, threadSource],
}),
},
handleQuestions: slackOrigin ? handleQuestions : undefined,
diff --git a/packages/agent/packages/agent/src/sdk/product.test.ts b/packages/agent/packages/agent/src/sdk/product.test.ts
index 791102c38c10..aa5366c322c6 100644
--- a/packages/agent/packages/agent/src/sdk/product.test.ts
+++ b/packages/agent/packages/agent/src/sdk/product.test.ts
@@ -81,7 +81,7 @@ describe("buildPullRequestFooter", () => {
{},
{
automated: true,
- source: { label: "inbox report", url: "https://example.com/r" },
+ sources: [{ label: "inbox report", url: "https://example.com/r" }],
},
"*Created with [PostHog](https://posthog.com?ref=pr) from an [inbox report](https://example.com/r)*",
],
@@ -90,7 +90,7 @@ describe("buildPullRequestFooter", () => {
{},
{
automated: true,
- source: { label: "Slack thread", url: "https://example.com/t" },
+ sources: [{ label: "Slack thread", url: "https://example.com/t" }],
},
"*Created with [PostHog](https://posthog.com?ref=pr) from a [Slack thread](https://example.com/t)*",
],
@@ -102,7 +102,7 @@ describe("buildPullRequestFooter", () => {
const webLaunch = { ...launch(), clientProvenance: "posthog_web" };
const source = { label: "PostHog AI chat", url: "https://example.com/c" };
- expect(buildPullRequestFooter(webLaunch, { source })).toBe(
+ expect(buildPullRequestFooter(webLaunch, { sources: [source] })).toBe(
"*Created with [PostHog](https://posthog.com?ref=pr) from a [PostHog AI chat](https://example.com/c)*",
);
});
diff --git a/packages/agent/packages/agent/src/sdk/product.ts b/packages/agent/packages/agent/src/sdk/product.ts
index 2c5f71f4c14a..682d62d1be66 100644
--- a/packages/agent/packages/agent/src/sdk/product.ts
+++ b/packages/agent/packages/agent/src/sdk/product.ts
@@ -134,7 +134,10 @@ export function defineProduct<LaunchOptions extends object>(definition: {
export function buildPullRequestFooter(
launch: ProductLaunchConfiguration,
- options: { automated?: boolean; source?: TaskSource } = {},
+ options: {
+ automated?: boolean;
+ sources?: readonly (TaskSource | undefined)[];
+ } = {},
): string {
const mobile = launch.launchOptions.client_platform === "mobile";
let createdWith =
@@ -145,10 +148,12 @@ export function buildPullRequestFooter(
createdWith = "Created with [PostHog](https://posthog.com?ref=pr)";
}
- const { source } = options;
- if (!source) {
- return `*${createdWith}*`;
- }
- const article = /^[aeiou]/i.test(source.label) ? "an" : "a";
- return `*${createdWith} from ${article} [${source.label}](${source.url})*`;
+ const links = (options.sources ?? [])
+ .filter((source): source is TaskSource => source !== undefined)
+ .map((source, index) => {
+ const preposition = index === 0 ? "from" : "via";
+ const article = /^[aeiou]/i.test(source.label) ? "an" : "a";
+ return `${preposition} ${article} [${source.label}](${source.url})`;
+ });
+ return `*${[createdWith, ...links].join(" ")}*`;
}
diff --git a/packages/agent/packages/agent/src/server/agent-server.test.ts b/packages/agent/packages/agent/src/server/agent-server.test.ts
index 131ebc5b644e..8144af3e4834 100644
--- a/packages/agent/packages/agent/src/server/agent-server.test.ts
+++ b/packages/agent/packages/agent/src/server/agent-server.test.ts
@@ -8356,11 +8356,18 @@ describe("AgentServer HTTP Mode", () => {
footer: `*Created with [PostHog](https://posthog.com?ref=pr) from an [inbox report](${INBOX_REPORT.url})*`,
},
{
- label: "Slack thread over the inbox report",
+ label: "inbox report via a Slack thread",
origin: "slack",
launchOptions: { slack_thread_url: SLACK_THREAD_URL },
source: INBOX_REPORT,
- footer: `*Created with [PostHog](https://posthog.com?ref=pr) from a [Slack thread](${SLACK_THREAD_URL})*`,
+ footer: `*Created with [PostHog](https://posthog.com?ref=pr) from an [inbox report](${INBOX_REPORT.url}) via a [Slack thread](${SLACK_THREAD_URL})*`,
+ },
+ {
+ label: "inbox report via a Slack thread on a signal_report run",
+ origin: "signal_report",
+ launchOptions: { slack_thread_url: SLACK_THREAD_URL },
+ source: INBOX_REPORT,
+ footer: `*Created with [PostHog](https://posthog.com?ref=pr) from an [inbox report](${INBOX_REPORT.url}) via a [Slack thread](${SLACK_THREAD_URL})*`,
},
{
label: "inbox report on a desktop run",
diff --git a/packages/agent/packages/agent/src/server/product/session.ts b/packages/agent/packages/agent/src/server/product/session.ts
index 62df9a1da2bd..10fc4d88f3f5 100644
--- a/packages/agent/packages/agent/src/server/product/session.ts
+++ b/packages/agent/packages/agent/src/server/product/session.ts
@@ -49,7 +49,7 @@ export function resolvePullRequestFooter(
): string {
return (
session.pullRequests?.footer ??
- buildPullRequestFooter(launch, { source: launch.source })
+ buildPullRequestFooter(launch, { sources: [launch.source] })
);
}