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.

feat(desktop): link the user to connect GitHub when a run needs code (#80671)

Vojta Bartoša7d49d28dd3a
diff --git a/products/desktop/packages/agent/src/server/agent-server.ts b/products/desktop/packages/agent/src/server/agent-server.ts
index f3a8b4c817c8..be5653c69405 100644
--- a/products/desktop/packages/agent/src/server/agent-server.ts
+++ b/products/desktop/packages/agent/src/server/agent-server.ts
@@ -3613,6 +3613,32 @@ export class AgentServer {
- If you created a local file but no upload or delivery tool is available, say that plainly and summarize the result in Slack instead.`;
}
+ /**
+ * What to do when a cloud run has no way to reach the user's code.
+ *
+ * Repository access on a cloud run comes from the user's own GitHub connection in
+ * PostHog, so a run can legitimately start without one — nothing is checked out and
+ * there are no credentials to push with. The Slack mention path used to refuse those
+ * mentions outright, which walled off every question that only looked like it needed
+ * code; it now starts the run and leaves the judgement here, where the request itself
+ * is visible. The settings link is built from this run's own host and project so it
+ * lands the user in the right region rather than a hardcoded one.
+ *
+ * Appended to every cloud branch on purpose: a checkout is not proof of access. A
+ * public repository clones with no token at all, so a run can hold the code and still
+ * have no way to push it.
+ */
+ private buildSourceControlAccessInstructions(): string {
+ const settingsUrl = `${this.config.apiUrl.replace(/\/$/, "")}/project/${this.config.projectId}/settings/user-personal-integrations`;
+ return `
+## When you cannot reach the code
+You may have no repository checked out, or no credentials to push and open a pull request with.
+- Answer the part of the request that does not need the code first — questions about PostHog, their data, or their configuration are all still answerable.
+- If the request turns out not to need a code change at all, just answer it and say nothing about GitHub.
+- Only if it genuinely needs a code change, say so plainly and link them to ${settingsUrl} to connect GitHub, then ask them to come back to you.
+- Do not work around it: no guessing at file contents you cannot read, and no starting a change you have no way to deliver.`;
+ }
+
private buildCloudSystemPrompt(
prUrl?: string | null,
slackThreadUrl?: string | null,
@@ -3714,7 +3740,7 @@ Optimize for the fewest shell round trips.
When you create a non-code file the user should be able to download (such as a report, chart, image, archive, or data file), call the \`upload_artifact\` tool with its path before your final reply. In your final reply, link to the download URL returned by the tool—never link to the file's local workspace path. Files left in the workspace don't reach the user. Don't upload source code or repository changes—those belong in a commit or PR.`;
// Closes out every branch below, so a new section is added once rather than five times.
- const commonInstructions = `${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}${artifactInstructions}${this.buildSlackDeliveryInstructions()}`;
+ const commonInstructions = `${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}${artifactInstructions}${this.buildSlackDeliveryInstructions()}${this.buildSourceControlAccessInstructions()}`;
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.`;
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.`;