Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/agent/src/server/agent-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,49 @@ describe("AgentServer HTTP Mode", () => {
expect(prompt).toContain("stop with local changes ready for review");
});

it.each([
{
label: "createPr unset",
config: { repositoryPath: undefined },
shouldContain: [
"Cloud Task Execution — No Repository Mode",
"Clone the repository into /tmp/workspace/repos/<owner>/<repo>",
"gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>",
"If the user explicitly asks you to open or update a pull request",
"open a draft pull request",
"unless the user explicitly asks",
"Generated-By: PostHog Code",
"Task-Id: test-task-id",
],
shouldNotContain: [],
},
{
label: "createPr false",
config: { repositoryPath: undefined, createPr: false },
shouldContain: [
"Cloud Task Execution — No Repository Mode",
"You may clone a repository and make local edits in that clone",
"Do NOT create branches, commits, push changes, or open pull requests in this run",
],
shouldNotContain: ["open a draft pull request", "gh pr create --draft"],
},
])(
"returns no-repository prompt for $label",
({ config, shouldContain, shouldNotContain }) => {
const s = createServer(config);
const prompt = (
s as unknown as TestableServer
).buildCloudSystemPrompt();

for (const text of shouldContain) {
expect(prompt).toContain(text);
}
for (const text of shouldNotContain) {
expect(prompt).not.toContain(text);
}
},
);

it("returns auto-PR prompt for Slack-origin runs", () => {
process.env.POSTHOG_CODE_INTERACTION_ORIGIN = "slack";
const s = createServer();
Expand Down
18 changes: 16 additions & 2 deletions packages/agent/src/server/agent-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,19 @@ ${attributionInstructions}
}

if (!this.config.repositoryPath) {
const publishInstructions =
this.config.createPr === false
? `
When the user asks for code changes:
- You may clone a repository and make local edits in that clone
- Do NOT create branches, commits, push changes, or open pull requests in this run`
: `
When the user explicitly asks to clone or work in a GitHub repository:
- Clone the repository into /tmp/workspace/repos/<owner>/<repo> using \`gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>\`
- Work from inside that cloned repository for follow-up code changes
- If the user explicitly asks you to open or update a pull request, create a branch, commit the requested changes, push it, and open a draft pull request from inside the clone
- Do NOT create branches, commits, push changes, or open pull requests unless the user explicitly asks for that`;

return `
# Cloud Task Execution — No Repository Mode

Expand All @@ -1617,11 +1630,12 @@ When the user asks about analytics, data, metrics, events, funnels, dashboards,

When the user asks for code changes or software engineering tasks:
- Let them know you can help but don't have a repository connected for this session
- Offer to write code snippets, scripts, or provide guidance
- If they have not specified a repository to clone, offer to write code snippets, scripts, or provide guidance
${publishInstructions}

Important:
- Do NOT create branches, commits, or pull requests in this mode.
- Prefer using MCP tools to answer questions with real data over giving generic advice.
${attributionInstructions}
`;
}

Expand Down
Loading