Skip to content

Commit 519dfd4

Browse files
authored
fix(agent): allow no-repo cloud runs to clone repos (#1955)
1 parent bec5aa0 commit 519dfd4

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,49 @@ describe("AgentServer HTTP Mode", () => {
639639
expect(prompt).toContain("stop with local changes ready for review");
640640
});
641641

642+
it.each([
643+
{
644+
label: "createPr unset",
645+
config: { repositoryPath: undefined },
646+
shouldContain: [
647+
"Cloud Task Execution — No Repository Mode",
648+
"Clone the repository into /tmp/workspace/repos/<owner>/<repo>",
649+
"gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>",
650+
"If the user explicitly asks you to open or update a pull request",
651+
"open a draft pull request",
652+
"unless the user explicitly asks",
653+
"Generated-By: PostHog Code",
654+
"Task-Id: test-task-id",
655+
],
656+
shouldNotContain: [],
657+
},
658+
{
659+
label: "createPr false",
660+
config: { repositoryPath: undefined, createPr: false },
661+
shouldContain: [
662+
"Cloud Task Execution — No Repository Mode",
663+
"You may clone a repository and make local edits in that clone",
664+
"Do NOT create branches, commits, push changes, or open pull requests in this run",
665+
],
666+
shouldNotContain: ["open a draft pull request", "gh pr create --draft"],
667+
},
668+
])(
669+
"returns no-repository prompt for $label",
670+
({ config, shouldContain, shouldNotContain }) => {
671+
const s = createServer(config);
672+
const prompt = (
673+
s as unknown as TestableServer
674+
).buildCloudSystemPrompt();
675+
676+
for (const text of shouldContain) {
677+
expect(prompt).toContain(text);
678+
}
679+
for (const text of shouldNotContain) {
680+
expect(prompt).not.toContain(text);
681+
}
682+
},
683+
);
684+
642685
it("returns auto-PR prompt for Slack-origin runs", () => {
643686
process.env.POSTHOG_CODE_INTERACTION_ORIGIN = "slack";
644687
const s = createServer();

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,19 @@ ${attributionInstructions}
16051605
}
16061606

16071607
if (!this.config.repositoryPath) {
1608+
const publishInstructions =
1609+
this.config.createPr === false
1610+
? `
1611+
When the user asks for code changes:
1612+
- You may clone a repository and make local edits in that clone
1613+
- Do NOT create branches, commits, push changes, or open pull requests in this run`
1614+
: `
1615+
When the user explicitly asks to clone or work in a GitHub repository:
1616+
- Clone the repository into /tmp/workspace/repos/<owner>/<repo> using \`gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>\`
1617+
- Work from inside that cloned repository for follow-up code changes
1618+
- 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
1619+
- Do NOT create branches, commits, push changes, or open pull requests unless the user explicitly asks for that`;
1620+
16081621
return `
16091622
# Cloud Task Execution — No Repository Mode
16101623
@@ -1617,11 +1630,12 @@ When the user asks about analytics, data, metrics, events, funnels, dashboards,
16171630
16181631
When the user asks for code changes or software engineering tasks:
16191632
- Let them know you can help but don't have a repository connected for this session
1620-
- Offer to write code snippets, scripts, or provide guidance
1633+
- If they have not specified a repository to clone, offer to write code snippets, scripts, or provide guidance
1634+
${publishInstructions}
16211635
16221636
Important:
1623-
- Do NOT create branches, commits, or pull requests in this mode.
16241637
- Prefer using MCP tools to answer questions with real data over giving generic advice.
1638+
${attributionInstructions}
16251639
`;
16261640
}
16271641

0 commit comments

Comments
 (0)