Skip to content

Commit 39a11cb

Browse files
committed
feat(code): add commit and pr attribution to system prompt
1 parent 0b92782 commit 39a11cb

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

apps/code/src/main/services/agent/service.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,41 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
418418

419419
private buildSystemPrompt(
420420
credentials: Credentials,
421+
taskId: string,
421422
customInstructions?: string,
422423
): {
423424
append: string;
424425
} {
425426
let prompt = `PostHog context: use project ${credentials.projectId} on ${credentials.apiHost}. When using PostHog MCP tools, operate only on this project.`;
426427

428+
prompt += `
429+
430+
## Attribution
431+
Do NOT use Claude Code's default attribution (no "Co-Authored-By" trailers, no "Generated with [Claude Code]" lines).
432+
433+
Instead, add the following trailers to EVERY commit message (after a blank line at the end):
434+
Generated-By: PostHog Code
435+
Task-Id: ${taskId}
436+
437+
Example:
438+
\`\`\`
439+
git commit -m "$(cat <<'EOF'
440+
fix: resolve login redirect loop
441+
442+
Generated-By: PostHog Code
443+
Task-Id: ${taskId}
444+
EOF
445+
)"
446+
\`\`\`
447+
448+
When creating new branches, prefix them with \`posthog-code/\` (e.g. \`posthog-code/fix-login-redirect\`).
449+
450+
When creating pull requests, add the following footer at the end of the PR description:
451+
\`\`\`
452+
---
453+
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
454+
\`\`\``;
455+
427456
if (customInstructions) {
428457
prompt += `\n\nUser custom instructions:\n${customInstructions}`;
429458
}
@@ -632,6 +661,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
632661

633662
const systemPrompt = this.buildSystemPrompt(
634663
credentials,
664+
taskId,
635665
customInstructions,
636666
);
637667
const resumeResponse = await connection.unstable_resumeSession({
@@ -669,6 +699,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
669699
}
670700
const systemPrompt = this.buildSystemPrompt(
671701
credentials,
702+
taskId,
672703
customInstructions,
673704
);
674705
const newSessionResponse = await connection.newSession({

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,22 +365,27 @@ describe("AgentServer HTTP Mode", () => {
365365
expect(prompt).toContain("https://github.com/org/repo/pull/1");
366366
expect(prompt).toContain("gh pr checkout");
367367
expect(prompt).not.toContain("Create a draft pull request");
368+
expect(prompt).toContain("Generated-By: PostHog Code");
369+
expect(prompt).toContain("Task-Id: test-task-id");
368370
});
369371

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

378383
it("returns default prompt when prUrl is null", () => {
379384
const s = createServer();
380385
const prompt = (s as unknown as TestableServer).buildCloudSystemPrompt(
381386
null,
382387
);
383-
expect(prompt).toContain("Create a new branch");
388+
expect(prompt).toContain("posthog-code/");
384389
expect(prompt).toContain("Create a draft pull request");
385390
expect(prompt).toContain("gh pr create --draft");
386391
});

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,26 @@ export class AgentServer {
10621062
}
10631063

10641064
private buildCloudSystemPrompt(prUrl?: string | null): string {
1065+
const taskId = this.config.taskId;
1066+
const attributionInstructions = `
1067+
## Attribution
1068+
Do NOT use Claude Code's default attribution (no "Co-Authored-By" trailers, no "Generated with [Claude Code]" lines).
1069+
1070+
Instead, add the following trailers to EVERY commit message (after a blank line at the end):
1071+
Generated-By: PostHog Code
1072+
Task-Id: ${taskId}
1073+
1074+
Example:
1075+
\`\`\`
1076+
git commit -m "$(cat <<'EOF'
1077+
fix: resolve login redirect loop
1078+
1079+
Generated-By: PostHog Code
1080+
Task-Id: ${taskId}
1081+
EOF
1082+
)"
1083+
\`\`\``;
1084+
10651085
if (prUrl) {
10661086
return `
10671087
# Cloud Task Execution
@@ -1075,8 +1095,7 @@ After completing the requested changes:
10751095
10761096
Important:
10771097
- Do NOT create a new branch or a new pull request.
1078-
- Do NOT add "Co-Authored-By" trailers to commit messages.
1079-
- Do NOT add "Generated with [Claude Code]" or similar attribution lines to PR descriptions.
1098+
${attributionInstructions}
10801099
`;
10811100
}
10821101

@@ -1105,15 +1124,18 @@ Important:
11051124
# Cloud Task Execution
11061125
11071126
After completing the requested changes:
1108-
1. Create a new branch with a descriptive name based on the work done
1127+
1. Create a new branch prefixed with \`posthog-code/\` (e.g. \`posthog-code/fix-login-redirect\`) based on the work done
11091128
2. Stage and commit all changes with a clear commit message
11101129
3. Push the branch to origin
1111-
4. Create a draft pull request using \`gh pr create --draft${this.config.baseBranch ? ` --base ${this.config.baseBranch}` : ""}\` with a descriptive title and body
1130+
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:
1131+
\`\`\`
1132+
---
1133+
*Created with [PostHog Code](https://posthog.com/code?ref=pr)*
1134+
\`\`\`
11121135
11131136
Important:
11141137
- Always create the PR as a draft. Do not ask for confirmation.
1115-
- Do NOT add "Co-Authored-By" trailers to commit messages.
1116-
- Do NOT add "Generated with [Claude Code]" or similar attribution lines to PR descriptions.
1138+
${attributionInstructions}
11171139
`;
11181140
}
11191141

0 commit comments

Comments
 (0)