Skip to content

Commit ee29987

Browse files
author
Tulga Tsogtgerel
committed
System prompt generation & Github Workflow Step summary update
1 parent 9facaf2 commit ee29987

File tree

5 files changed

+86
-100
lines changed

5 files changed

+86
-100
lines changed

action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ inputs:
3232
outputs:
3333
success:
3434
description: 'Whether the reaction was successfully added'
35-
value: ${{ steps.react.outputs.success }}
35+
value: ${{ steps.auggie.outputs.success }}
3636

3737
runs:
3838
using: 'composite'
@@ -51,8 +51,8 @@ runs:
5151
shell: bash
5252
working-directory: ${{ github.action_path }}
5353

54-
- name: React to comment
55-
id: react
54+
- name: Run Auggie
55+
id: auggie
5656
run: bun run ${{ github.action_path }}/src/index.ts
5757
shell: bash
5858
env:
@@ -64,4 +64,5 @@ runs:
6464
INPUT_AUGMENT_API_URL: ${{ inputs.augment_api_url }}
6565
INPUT_WORKSPACE_ROOT: ${{ inputs.workspace_root }}
6666
GITHUB_REPOSITORY: ${{ github.repository }}
67+
GITHUB_STEP_SUMMARY: ${{ env.GITHUB_STEP_SUMMARY }}
6768

src/auggie.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import * as core from "@actions/core";
22
import { Auggie } from "@augmentcode/auggie-sdk";
3+
import type { GithubPullRequest } from "./types";
4+
import { AGENT_SYSTEM_PROMPT, generateContextPrompt } from "./utils/prompt";
35

46
/**
57
* Options for running Auggie agent
68
*/
79
export type RunAuggieOptions = {
8-
prompt: string;
10+
userPrompt: string;
911
apiKey?: string;
1012
apiUrl?: string;
1113
workspaceRoot?: string;
1214
githubToken?: string;
15+
context?: GithubPullRequest;
1316
};
1417

1518
/**
1619
* Run Auggie agent with the given prompt and return the response
1720
*/
1821
export async function runAuggie(options: RunAuggieOptions): Promise<string> {
19-
const { prompt, apiKey, apiUrl, workspaceRoot, githubToken } = options;
22+
const { userPrompt, apiKey, apiUrl, workspaceRoot, githubToken, context } =
23+
options;
2024

2125
const workspace = workspaceRoot || process.cwd();
2226

@@ -41,10 +45,21 @@ export async function runAuggie(options: RunAuggieOptions): Promise<string> {
4145
allowIndexing: true,
4246
});
4347

44-
core.info("📝 Sending prompt to Auggie...");
48+
core.info("📝 Running Auggie agent ...");
4549

46-
// Send prompt and get response
47-
const response = await client.prompt(prompt, { isAnswerOnly: true });
50+
// Build the full prompt by combining system prompt, context, and user prompt
51+
let fullPrompt = AGENT_SYSTEM_PROMPT;
52+
53+
// Add context information if provided
54+
if (context) {
55+
const contextPrompt = generateContextPrompt(context);
56+
fullPrompt = `${fullPrompt}\n\n${contextPrompt}`;
57+
}
58+
59+
// Add user prompt
60+
fullPrompt = `${fullPrompt}\n\n${userPrompt}`;
61+
62+
const response = await client.prompt(fullPrompt, { isAnswerOnly: true });
4863

4964
core.info("✅ Auggie agent completed successfully");
5065

src/index.ts

Lines changed: 12 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,7 @@
22
import * as core from "@actions/core";
33
import { Octokit } from "@octokit/rest";
44
import { runAuggie } from "./auggie";
5-
import {
6-
getInput,
7-
parseRepository,
8-
postComment,
9-
reactToComment,
10-
} from "./utils";
11-
12-
// Regex patterns for extracting issue/PR numbers from URLs
13-
const ISSUE_URL_PATTERN = /\/issues\/(\d+)$/;
14-
const PR_URL_PATTERN = /\/pulls\/(\d+)$/;
15-
16-
type GetIssueNumberParams = {
17-
octokit: Octokit;
18-
owner: string;
19-
repo: string;
20-
commentId: number;
21-
eventName: string;
22-
};
23-
24-
/**
25-
* Get issue/PR number from the comment
26-
* For issue_comment events, we need to fetch the comment to get the issue number
27-
* For pull_request_review_comment events, we need to fetch the comment to get the PR number
28-
*/
29-
async function getIssueNumber({
30-
octokit,
31-
owner,
32-
repo,
33-
commentId,
34-
eventName,
35-
}: GetIssueNumberParams): Promise<number> {
36-
if (eventName === "issue_comment") {
37-
// Fetch the comment to get the issue URL
38-
const { data: comment } = await octokit.rest.issues.getComment({
39-
owner,
40-
repo,
41-
comment_id: commentId,
42-
});
43-
44-
// Extract issue number from the issue URL
45-
const issueUrlMatch = comment.issue_url.match(ISSUE_URL_PATTERN);
46-
if (!issueUrlMatch?.[1]) {
47-
throw new Error(
48-
`Could not extract issue number from URL: ${comment.issue_url}`
49-
);
50-
}
51-
52-
return Number.parseInt(issueUrlMatch[1], 10);
53-
}
54-
55-
if (eventName === "pull_request_review_comment") {
56-
// Fetch the review comment to get the PR URL
57-
const { data: comment } = await octokit.rest.pulls.getReviewComment({
58-
owner,
59-
repo,
60-
comment_id: commentId,
61-
});
62-
63-
// Extract PR number from the pull request URL
64-
const prUrlMatch = comment.pull_request_url.match(PR_URL_PATTERN);
65-
if (!prUrlMatch?.[1]) {
66-
throw new Error(
67-
`Could not extract PR number from URL: ${comment.pull_request_url}`
68-
);
69-
}
70-
71-
return Number.parseInt(prUrlMatch[1], 10);
72-
}
73-
74-
throw new Error(`Unsupported event type: ${eventName}`);
75-
}
5+
import { getInput, parseRepository, reactToComment } from "./utils";
766

777
/**
788
* Main function
@@ -101,35 +31,25 @@ async function main(): Promise<void> {
10131
// React to the comment to acknowledge receipt
10232
await reactToComment({ octokit, owner, repo, commentId, eventName });
10333

34+
// Log GITHUB_STEP_SUMMARY availability
35+
const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;
36+
if (stepSummaryPath) {
37+
core.info(`📊 GITHUB_STEP_SUMMARY available at: ${stepSummaryPath}`);
38+
} else {
39+
core.warning("⚠️ GITHUB_STEP_SUMMARY not available");
40+
}
41+
10442
// Run Auggie agent with the prompt
10543
core.info("🚀 Running Auggie agent...");
106-
const response = await runAuggie({
107-
prompt,
44+
await runAuggie({
45+
userPrompt: prompt,
10846
apiKey: augmentApiKey,
10947
apiUrl: augmentApiUrl,
11048
workspaceRoot: workspaceRoot || undefined,
11149
githubToken,
11250
});
11351

114-
// Get issue number for posting the response
115-
const issueNumber = await getIssueNumber({
116-
octokit,
117-
owner,
118-
repo,
119-
commentId,
120-
eventName,
121-
});
122-
123-
// Post the response as a comment
124-
await postComment({
125-
octokit,
126-
owner,
127-
repo,
128-
issueNumber,
129-
body: response,
130-
eventName,
131-
});
132-
52+
core.info("✅ Auggie agent completed successfully");
13353
core.setOutput("success", "true");
13454
} catch (error) {
13555
const errorMessage = error instanceof Error ? error.message : String(error);

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type GithubPullRequest = {
2+
title: string;
3+
body: string;
4+
author: string;
5+
baseRefName: string;
6+
headRefName: string;
7+
headRefOid: string;
8+
additions: number;
9+
deletions: number;
10+
state: string;
11+
}

src/utils/prompt.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { GithubPullRequest } from "../types";
2+
3+
export const AGENT_SYSTEM_PROMPT = `You are an AI assistant designed to help with GitHub issues and pull requests.
4+
5+
Your workflow:
6+
1. Add a comment to the PR letting the user know you're starting to work on it.
7+
2. Read the PR context and understand the request.
8+
3. Create a Todo List:
9+
- Update the original comment on the PR with a todo list of what you're going to do. (Use the github-api tool to update the comment. Replace the initial message with the todo list.)
10+
- Use your GitHub comment to maintain a detailed task list based on the request.
11+
- Format todos as a checklist (- [ ] for incomplete, - [x] for complete).
12+
- Update the comment with each task completion.
13+
4. Update the GitHub Workflow Summary:
14+
- Write a detailed execution report to the file path specified in the GITHUB_STEP_SUMMARY environment variable.
15+
- Use markdown formatting for the summary.
16+
- Include: task overview, what was accomplished, files changed, links to relevant resources.
17+
- Append to the file using >> or write using the bash tool.
18+
- Example format:
19+
## Auggie Agent Report
20+
21+
✅ Task completed successfully
22+
23+
### Summary
24+
- What was done
25+
- Files modified
26+
- Links to PRs/commits
27+
5. Update the original comment with a final summary (remove previous messages, keep only the final summary) that includes:
28+
- What documentation was updated
29+
- Link to the docs PR`;
30+
31+
export const generateContextPrompt = (context: GithubPullRequest) => {
32+
return `PR Title: ${context.title}
33+
PR Author: ${context.author}
34+
PR Branch: ${context.headRefName} -> ${context.baseRefName}
35+
PR State: ${context.state}
36+
PR Additions: ${context.additions}
37+
PR Deletions: ${context.deletions}
38+
PR Body: ${context.body}`;
39+
};

0 commit comments

Comments
 (0)