Skip to content

Commit 7f9775f

Browse files
authored
fix(agent): align existing PR checkout prompts
Use one conditional checkout instruction for both the static cloud system prompt and per-message detected PR context, preventing conflicting guidance on follow-up turns. Generated-By: PostHog Code Task-Id: 9e493924-1eab-496a-ba66-aba8366de96e
1 parent a0b096b commit 7f9775f

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,8 +3504,12 @@ describe("AgentServer HTTP Mode", () => {
35043504
"https://github.com/org/repo/pull/1",
35053505
);
35063506
expect(prompt).toContain(
3507-
"gh pr checkout https://github.com/org/repo/pull/1",
3507+
"If it is not already checked out, check it out with `gh pr checkout https://github.com/org/repo/pull/1`",
35083508
);
3509+
expect(prompt).toContain(
3510+
"Do not check it out again when it is already active",
3511+
);
3512+
expect(prompt).not.toContain("Check out the existing PR branch");
35093513
expect(prompt).toContain("git_signed_commit");
35103514
expect(prompt).toContain("Committing (signed commits required)");
35113515
expect(prompt).not.toContain("Create a draft pull request");

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,10 @@ export class AgentServer {
31393139
].join("\n");
31403140
}
31413141

3142+
private buildExistingPrCheckoutInstruction(prUrl: string): string {
3143+
return `Continue working on the existing PR branch. If it is not already checked out, check it out with \`gh pr checkout ${prUrl}\`. Do not check it out again when it is already active.`;
3144+
}
3145+
31423146
private buildDetectedPrContext(prUrl: string): string {
31433147
if (!this.shouldAutoPublishCloudChanges()) {
31443148
return (
@@ -3152,7 +3156,7 @@ export class AgentServer {
31523156
`IMPORTANT — OVERRIDE PREVIOUS INSTRUCTIONS ABOUT CREATING BRANCHES/PRs.\n` +
31533157
`You already have an open pull request: ${prUrl}\n` +
31543158
`You MUST:\n` +
3155-
`1. Continue working on the existing PR branch. If it is not already checked out, check it out with \`gh pr checkout ${prUrl}\`. Do not check it out again when it is already active.\n` +
3159+
`1. ${this.buildExistingPrCheckoutInstruction(prUrl)}\n` +
31563160
`2. Make changes, commit, and push to that branch\n` +
31573161
`You MUST NOT create a new branch, close the existing PR, or create a new PR.`
31583162
);
@@ -3283,7 +3287,7 @@ ${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
32833287
This task already has an open pull request: ${prUrl}
32843288
32853289
After completing the requested changes:
3286-
1. Check out the existing PR branch with \`gh pr checkout ${prUrl}\`
3290+
1. ${this.buildExistingPrCheckoutInstruction(prUrl)}
32873291
2. Stage your changes with \`git add\`, then call the \`git_signed_commit\` tool with a clear \`message\` (do NOT use \`git commit\`/\`git push\` — they are blocked). This commits to the existing PR branch.
32883292
- If the branch is behind its base, call the \`git_signed_merge\` tool first — it merges the base in server-side with a Verified merge commit. Only if it reports a conflict: fetch and rebase locally (\`git fetch origin <base>\`, \`git rebase origin/<base>\`, resolve, \`git rebase --continue\`), then call the \`git_signed_rewrite\` tool to force-update this same PR branch.
32893293
3. For every PR review comment or review thread you addressed, treat the thread as done only after BOTH of these:

0 commit comments

Comments
 (0)