Skip to content

Commit aef8f59

Browse files
Generate Prompt based on github issue (#220)
1 parent a2080bd commit aef8f59

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

.agents/commands/gh_issue.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bash
2+
#
3+
# A command to generate an agent prompt to diagnose and formulate
4+
# a plan for resolving a GitHub issue.
5+
#
6+
# IMPORTANT: This command is prompted to NOT write any code and to ONLY
7+
# produce a plan. You should still be vigilant when running this but that
8+
# is the expected behavior.
9+
#
10+
# The `<issue>` parameter can be either an issue number or a full GitHub
11+
# issue URL.
12+
#
13+
# NOTE: This script assumes you are inside a git repo with a valid
14+
# GitHub remote configured.
15+
16+
set -euo pipefail
17+
18+
usage() {
19+
cat <<USAGE
20+
Usage: $(basename "$0") <issue-number-or-url>
21+
22+
Example:
23+
$(basename "$0") 219
24+
$(basename "$0") https://github.com/interlynk-io/sbomasm/issues/219
25+
26+
This prints a detailed prompt (to stdout) for an assistant to:
27+
- Deep-dive on the issue
28+
- Explain the problem
29+
- Produce a comprehensive plan (NO CODE)
30+
USAGE
31+
exit 1
32+
}
33+
34+
if [[ $# -eq 0 ]]; then
35+
usage
36+
fi
37+
38+
ISSUE="$1"
39+
40+
# Ensure dependencies
41+
for dep in gh jq git; do
42+
if ! command -v "$dep" >/dev/null 2>&1; then
43+
echo "Error: '$dep' is required but not found in PATH." >&2
44+
exit 2
45+
fi
46+
done
47+
48+
# Detect repo from current git remote
49+
REMOTE_URL=$(git config --get remote.origin.url || true)
50+
if [[ -z "$REMOTE_URL" ]]; then
51+
echo "Error: No remote.origin.url found. Run this inside a cloned GitHub repo." >&2
52+
exit 3
53+
fi
54+
55+
# Normalize remote URL into "owner/repo"
56+
if [[ "$REMOTE_URL" =~ ^git@github.com:(.+)\.git$ ]]; then
57+
REPO="${BASH_REMATCH[1]}"
58+
elif [[ "$REMOTE_URL" =~ ^https://github.com/(.+)\.git$ ]]; then
59+
REPO="${BASH_REMATCH[1]}"
60+
elif [[ "$REMOTE_URL" =~ ^https://github.com/(.+)$ ]]; then
61+
REPO="${BASH_REMATCH[1]}"
62+
else
63+
echo "Error: Unsupported remote URL format: $REMOTE_URL" >&2
64+
exit 3
65+
fi
66+
67+
# Fetch issue data
68+
if ! ISSUE_JSON=$(gh issue view "$ISSUE" --repo "$REPO" --json author,title,number,body,comments 2>/dev/null); then
69+
echo "Error: failed to fetch issue from GitHub. Check repo/issue and that you have gh auth configured." >&2
70+
exit 4
71+
fi
72+
73+
TITLE=$(jq -r '.title // ""' <<<"$ISSUE_JSON")
74+
NUMBER=$(jq -r '.number // ""' <<<"$ISSUE_JSON")
75+
BODY=$(jq -r '.body // ""' <<<"$ISSUE_JSON")
76+
COMMENTS=$(jq -r '
77+
if (.comments | length) > 0 then
78+
[.comments[] | ("### Comment by (" + (.author.login // "unknown") + ")\n\n" + (.body // ""))] | join("\n\n")
79+
else
80+
""
81+
end
82+
' <<<"$ISSUE_JSON")
83+
[[ -z "$COMMENTS" ]] && COMMENTS="(no comments)"
84+
ISSUE_URL="https://github.com/${REPO}/issues/${NUMBER}"
85+
86+
# Print prompt
87+
printf '%s\n\n' "Deep-dive on this GitHub issue. Find the problem and generate a plan.
88+
Do not write code. Explain the problem clearly and propose a comprehensive plan
89+
to solve it."
90+
91+
printf '# %s (%s)\n\n' "$TITLE" "$NUMBER"
92+
printf '## Description\n%s\n\n' "$BODY"
93+
printf '## Comments\n%s\n\n' "$COMMENTS"
94+
95+
cat <<'TASKS'
96+
97+
## Your Tasks
98+
99+
You are an experienced software developer tasked with diagnosing issues.
100+
101+
1. Review the issue context and details.
102+
2. Examine the relevant parts of the codebase. Analyze the code thoroughly
103+
until you have a solid understanding of how it works.
104+
3. Explain the issue in detail, including the problem and its root cause.
105+
4. Create a comprehensive plan to solve the issue. The plan should include:
106+
- Required code changes
107+
- Potential impacts on other parts of the system
108+
- Necessary tests to be written or updated
109+
- Documentation updates
110+
- Performance considerations
111+
- Security implications
112+
- Backwards compatibility (if applicable)
113+
- Include the reference link to the source issue and any related discussions
114+
5. Think deeply about all aspects of the task. Consider edge cases, potential
115+
challenges, and best practices for addressing the issue. Review the plan
116+
with the oracle and adjust it based on its feedback.
117+
118+
**ONLY CREATE A PLAN. DO NOT WRITE ANY CODE.** Your task is to create
119+
a thorough, comprehensive strategy for understanding and resolving the issue.
120+
TASKS
121+
122+
printf '\nSource: %s\n' "$ISSUE_URL"

0 commit comments

Comments
 (0)