Skip to content

Commit a18b37c

Browse files
authored
fix(agent): Hyperlink pull requests in agent replies (#3208)
1 parent 522185f commit a18b37c

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

packages/agent/src/adapters/claude/session/instructions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ When working in a detached HEAD state, create a descriptive branch name based on
66
When creating a new branch, prefix it with \`posthog-code/\` (e.g. \`posthog-code/fix-login-redirect\`).
77
`;
88

9+
const PULL_REQUEST_LINKS = `
10+
# Pull Request Links
11+
12+
When you mention a pull request in any reply or summary, always hyperlink it to its full URL (e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain text, so readers can open it directly.
13+
`;
14+
915
const PLAN_MODE = `
1016
# Plan Mode
1117
@@ -26,4 +32,5 @@ If an MCP tool call is explicitly denied with a message, relay that denial messa
2632
If an MCP tool call returns an error, treat it as a normal tool error — troubleshoot, retry, or inform the user about the specific error. Do NOT assume it is a permissions issue and do NOT direct the user to any settings page.
2733
`;
2834

29-
export const APPENDED_INSTRUCTIONS = BRANCH_NAMING + PLAN_MODE + MCP_TOOLS;
35+
export const APPENDED_INSTRUCTIONS =
36+
BRANCH_NAMING + PULL_REQUEST_LINKS + PLAN_MODE + MCP_TOOLS;

packages/agent/src/server/agent-server.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,12 @@ we want:
26592659
Generated-By: PostHog Code
26602660
Task-Id: ${taskId}`;
26612661

2662+
const prLinkInstructions = `
2663+
## Referencing pull requests
2664+
When you mention a pull request in any reply or summary, always hyperlink it to its full URL
2665+
(e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain
2666+
text, so readers can open it directly.`;
2667+
26622668
const whyContextInstruction = ` - Add a brief **Why** to the body — one or two sentences capturing the reason the user asked for this change (the motivation, not a restatement of the diff). Keep it short.`;
26632669
const publicRepoSafetyInstruction = ` - **Public-repo safety.** Treat the target repository as public-readable unless you have verified otherwise. The PR title, description, and commit messages must not contain private operational scale (exact event counts, internal row volumes, customer-usage percentages), customer names / emails / companies, references to internal tickets or incidents, the contents of Slack threads (do not quote or paraphrase what was said), or unreleased roadmap details. Linking to the originating Slack thread is fine and encouraged — Slack links are auth-gated and useful as context — as are channel references like "raised in #team-foo". Describe findings qualitatively ("present on nearly all X events, absent from Y") rather than with quantitative figures pulled from analytics queries — the reasoning that uses those numbers can stay in the thread; the PR copy cannot.`;
26642670
// Slack- and inbox-originated PRs are attributed to PostHog, not the
@@ -2685,7 +2691,7 @@ Do the requested work, but stop with local changes ready for review.
26852691
Important:
26862692
- Do NOT create new commits, push to the branch, or update the pull request unless the user explicitly asks.
26872693
- Do NOT create a new branch or a new pull request.
2688-
${signedCommitInstructions}
2694+
${signedCommitInstructions}${prLinkInstructions}
26892695
`;
26902696
}
26912697

@@ -2706,7 +2712,7 @@ After completing the requested changes:
27062712
Important:
27072713
- Do NOT create a new branch or a new pull request.
27082714
- Do NOT push fixes for review comments without replying to and resolving each related thread.
2709-
${signedCommitInstructions}
2715+
${signedCommitInstructions}${prLinkInstructions}
27102716
`;
27112717
}
27122718

@@ -2745,7 +2751,7 @@ ${publishInstructions}
27452751
27462752
Important:
27472753
- Prefer using MCP tools to answer questions with real data over giving generic advice.
2748-
${signedCommitInstructions}
2754+
${signedCommitInstructions}${prLinkInstructions}
27492755
`;
27502756
}
27512757

@@ -2757,7 +2763,7 @@ Do the requested work, but stop with local changes ready for review.
27572763
27582764
Important:
27592765
- Do NOT create a branch, commit, push, or open a pull request unless the user explicitly asks.
2760-
${signedCommitInstructions}
2766+
${signedCommitInstructions}${prLinkInstructions}
27612767
`;
27622768
}
27632769

@@ -2784,7 +2790,7 @@ ${prFooter}
27842790
27852791
Important:
27862792
- Always create the PR as a draft. Do not ask for confirmation.
2787-
${signedCommitInstructions}
2793+
${signedCommitInstructions}${prLinkInstructions}
27882794
`;
27892795
}
27902796

packages/workspace-server/src/services/agent/agent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ When creating pull requests, add the following footer at the end of the PR descr
603603
\`\`\`
604604
---
605605
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
606-
\`\`\``;
606+
\`\`\`
607+
608+
When you mention a pull request in any reply or summary, always hyperlink it to its full URL (e.g. a Markdown link like [#123](https://github.com/org/repo/pull/123)) rather than plain text, so readers can open it directly.`;
607609

608610
if (channelMode) {
609611
const localFolders = (knownLocalFolders ?? []).filter(

0 commit comments

Comments
 (0)