: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(agent): support named pull request templates (#102726)
Mikayla Thompson0c400f204b81
diff --git a/products/desktop/packages/agent/src/server/agent-server.test.ts b/products/desktop/packages/agent/src/server/agent-server.test.tsindex 9aa4cd7d0001..7887ac78225c 100644--- a/products/desktop/packages/agent/src/server/agent-server.test.ts+++ b/products/desktop/packages/agent/src/server/agent-server.test.ts@@ -6776,6 +6776,7 @@ describe("AgentServer HTTP Mode", () => {"*Created with [PostHog Desktop](https://posthog.com/desktop?ref=pr)*",);expect(prompt).toContain(".github/pull_request_template.md");+ expect(prompt).toContain(".github/PULL_REQUEST_TEMPLATE/*.md");expect(prompt).toContain("gh issue list --search");expect(prompt).toContain("Closes #<n>");});@@ -6803,6 +6804,7 @@ describe("AgentServer HTTP Mode", () => {"open a draft pull request","unless the user explicitly asks",".github/pull_request_template.md",+ ".github/PULL_REQUEST_TEMPLATE/*.md","gh issue list --search","Closes #<n>","Generated-By: PostHog Desktop",@@ -6884,6 +6886,7 @@ describe("AgentServer HTTP Mode", () => {);// PR template detection (repo first, org `.github` fallback)expect(prompt).toContain(".github/pull_request_template.md");+ expect(prompt).toContain(".github/PULL_REQUEST_TEMPLATE/*.md");expect(prompt).toContain("org's `.github` repo");// Related-issue linkingexpect(prompt).toContain("gh issue list --state open --search");diff --git a/products/desktop/packages/agent/src/server/agent-server.ts b/products/desktop/packages/agent/src/server/agent-server.tsindex 2d30942361c3..c15f82848fb5 100644--- a/products/desktop/packages/agent/src/server/agent-server.ts+++ b/products/desktop/packages/agent/src/server/agent-server.ts@@ -4824,7 +4824,7 @@ When the user asks for code changes:: shouldAutoCreatePr? `When the user asks for code changes in a GitHub repository:-- After completing code changes in a cloned repository, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone without waiting to be asked. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.+- After completing code changes in a cloned repository, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone without waiting to be asked. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` or in \`.github/PULL_REQUEST_TEMPLATE/*.md\` (or other variants; fall back to the org's \`.github\` repo via \`gh api\`). If multiple templates exist, use the one that best matches the change. Use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.- Keep the PR description brief overall. Summarize only the most important changes — do NOT enumerate every change you made. A few sentences or bullets is plenty.${whyContextInstruction.trimStart()}${publicRepoSafetyInstruction.trimStart()}@@ -4833,7 +4833,7 @@ ${prMentionSafetyInstruction.trimStart()}- Always create the PR as a draft. Do not ask for confirmation before publishing completed code changes`: `When the user explicitly asks for code changes in a GitHub repository:-- If the user explicitly asks you to open or update a pull request, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.+- If the user explicitly asks you to open or update a pull request, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` or in \`.github/PULL_REQUEST_TEMPLATE/*.md\` (or other variants; fall back to the org's \`.github\` repo via \`gh api\`). If multiple templates exist, use the one that best matches the change. Use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.- Keep the PR description brief overall. Summarize only the most important changes — do NOT enumerate every change you made. A few sentences or bullets is plenty.${whyContextInstruction.trimStart()}${publicRepoSafetyInstruction.trimStart()}@@ -4875,7 +4875,7 @@ Do the requested work, but stop with local changes ready for review.Important:- Do NOT create a branch, commit, push, or open a pull request unless the user explicitly asks.-- If the user explicitly asks you to open a pull request: pick a new branch name prefixed with \`posthog/\`, stage your changes with \`git add\`, and call the \`git_signed_commit\` tool with \`branch\` set to that name and a clear \`message\` (do NOT use \`git commit\`/\`git push\` — they are blocked). Before opening the PR, check the repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links. Keep the description brief overall — summarize only the most important changes.+- If the user explicitly asks you to open a pull request: pick a new branch name prefixed with \`posthog/\`, stage your changes with \`git add\`, and call the \`git_signed_commit\` tool with \`branch\` set to that name and a clear \`message\` (do NOT use \`git commit\`/\`git push\` — they are blocked). Before opening the PR, check the repo for a PR template at \`.github/pull_request_template.md\` or in \`.github/PULL_REQUEST_TEMPLATE/*.md\` (or other variants; fall back to the org's \`.github\` repo via \`gh api\`). If multiple templates exist, use the one that best matches the change. Use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links. Keep the description brief overall — summarize only the most important changes.${whyContextInstruction.trimStart()}${publicRepoSafetyInstruction.trimStart()}${prMentionSafetyInstruction.trimStart()}@@ -4900,8 +4900,8 @@ Otherwise, after completing the requested changes:${whyContextInstruction}${publicRepoSafetyInstruction}${prMentionSafetyInstruction}- - Check the repo for a PR template at \`.github/pull_request_template.md\` (also try \`.github/PULL_REQUEST_TEMPLATE.md\`, \`docs/pull_request_template.md\`, and root variants). If one exists, use its exact section headings as the PR body — do NOT fall back to a generic Summary/Test plan format.- - If no repo-level template exists, check the org's \`.github\` repo via \`gh api /repos/<owner>/.github/contents/.github/pull_request_template.md\` (and other common paths) and use that as a fallback.+ - Check the repo for a default PR template at \`.github/pull_request_template.md\` (also try \`.github/PULL_REQUEST_TEMPLATE.md\`, \`docs/pull_request_template.md\`, and root variants). Also check for named templates in \`.github/PULL_REQUEST_TEMPLATE/*.md\`. If multiple templates exist, use the one that best matches the change. Use its exact section headings as the PR body — do NOT fall back to a generic Summary/Test plan format.+ - If no repo-level template exists, check the org's \`.github\` repo via \`gh api\`. Look for both a default template and named templates in \`.github/PULL_REQUEST_TEMPLATE/*.md\`, and use the best match as a fallback.- Search for matching open issues with \`gh issue list --state open --search '<keywords>'\` (derive keywords from the branch name, commits, and changed files; \`gh issue view <n>\` to confirm relevance). For every issue this PR would resolve, include a \`Closes #<n>\` line in the body so GitHub auto-links and auto-closes it on merge. For issues that are related but not fully resolved, use \`Refs #<n>\` instead.4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and the body prepared above. Add the following footer at the end of the PR description:\`\`\`