Skip to content
Open
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
31 changes: 31 additions & 0 deletions apps/code/src/main/services/agent/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,41 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {

private buildSystemPrompt(
credentials: Credentials,
taskId: string,
customInstructions?: string,
): {
append: string;
} {
let prompt = `PostHog context: use project ${credentials.projectId} on ${credentials.apiHost}. When using PostHog MCP tools, operate only on this project.`;

prompt += `

## Attribution
Do NOT use Claude Code's default attribution (no "Co-Authored-By" trailers, no "Generated with [Claude Code]" lines).

Instead, add the following trailers to EVERY commit message (after a blank line at the end):
Generated-By: PostHog Code
Task-Id: ${taskId}

Example:
\`\`\`
git commit -m "$(cat <<'EOF'
fix: resolve login redirect loop

Generated-By: PostHog Code
Task-Id: ${taskId}
EOF
)"
\`\`\`

When creating new branches, prefix them with \`posthog-code/\` (e.g. \`posthog-code/fix-login-redirect\`).

When creating pull requests, add the following footer at the end of the PR description:
\`\`\`
---
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
\`\`\``;

if (customInstructions) {
prompt += `\n\nUser custom instructions:\n${customInstructions}`;
}
Expand Down Expand Up @@ -627,6 +656,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {

const systemPrompt = this.buildSystemPrompt(
credentials,
taskId,
customInstructions,
);
const resumeResponse = await connection.unstable_resumeSession({
Expand Down Expand Up @@ -664,6 +694,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
}
const systemPrompt = this.buildSystemPrompt(
credentials,
taskId,
customInstructions,
);
const newSessionResponse = await connection.newSession({
Expand Down
9 changes: 7 additions & 2 deletions packages/agent/src/server/agent-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,22 +365,27 @@ describe("AgentServer HTTP Mode", () => {
expect(prompt).toContain("https://github.com/org/repo/pull/1");
expect(prompt).toContain("gh pr checkout");
expect(prompt).not.toContain("Create a draft pull request");
expect(prompt).toContain("Generated-By: PostHog Code");
expect(prompt).toContain("Task-Id: test-task-id");
});

it("returns default prompt when no prUrl", () => {
const s = createServer();
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt();
expect(prompt).toContain("Create a new branch");
expect(prompt).toContain("posthog-code/");
expect(prompt).toContain("Create a draft pull request");
expect(prompt).toContain("gh pr create --draft");
expect(prompt).toContain("Generated-By: PostHog Code");
expect(prompt).toContain("Task-Id: test-task-id");
expect(prompt).toContain("Created with [PostHog Code]");
});

it("returns default prompt when prUrl is null", () => {
const s = createServer();
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt(
null,
);
expect(prompt).toContain("Create a new branch");
expect(prompt).toContain("posthog-code/");
expect(prompt).toContain("Create a draft pull request");
expect(prompt).toContain("gh pr create --draft");
});
Expand Down
34 changes: 28 additions & 6 deletions packages/agent/src/server/agent-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,26 @@ export class AgentServer {
}

private buildCloudSystemPrompt(prUrl?: string | null): string {
const taskId = this.config.taskId;
const attributionInstructions = `
## Attribution
Do NOT use Claude Code's default attribution (no "Co-Authored-By" trailers, no "Generated with [Claude Code]" lines).

Instead, add the following trailers to EVERY commit message (after a blank line at the end):
Generated-By: PostHog Code
Task-Id: ${taskId}

Example:
\`\`\`
git commit -m "$(cat <<'EOF'
fix: resolve login redirect loop

Generated-By: PostHog Code
Task-Id: ${taskId}
EOF
)"
\`\`\``;

if (prUrl) {
return `
# Cloud Task Execution
Expand All @@ -1075,8 +1095,7 @@ After completing the requested changes:

Important:
- Do NOT create a new branch or a new pull request.
- Do NOT add "Co-Authored-By" trailers to commit messages.
- Do NOT add "Generated with [Claude Code]" or similar attribution lines to PR descriptions.
${attributionInstructions}
`;
}

Expand Down Expand Up @@ -1105,15 +1124,18 @@ Important:
# Cloud Task Execution

After completing the requested changes:
1. Create a new branch with a descriptive name based on the work done
1. Create a new branch prefixed with \`posthog-code/\` (e.g. \`posthog-code/fix-login-redirect\`) based on the work done
2. Stage and commit all changes with a clear commit message
3. Push the branch to origin
4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and body
4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and body. Add the following footer at the end of the PR description:
\`\`\`
---
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
\`\`\`

Important:
- Always create the PR as a draft. Do not ask for confirmation.
- Do NOT add "Co-Authored-By" trailers to commit messages.
- Do NOT add "Generated with [Claude Code]" or similar attribution lines to PR descriptions.
${attributionInstructions}
`;
}

Expand Down
Loading