-
Notifications
You must be signed in to change notification settings - Fork 0
Update Jules Triage Prompt and Parsing Logic #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import logging | ||
| import os | ||
| import sys | ||
| import re | ||
| from typing import Any, Dict, List | ||
|
|
||
| try: | ||
|
|
@@ -44,7 +45,7 @@ | |
| 1. **Strict JSON Only:** Your final output must be **only** the JSON array. No markdown, no "Here is the JSON", no fluff. | ||
| 2. **Label Discipline:** Use ONLY the labels provided in `{available_labels}`. Do not hallucinate new labels. | ||
| 3. **Variable Safety:** Reference variables strictly. | ||
| 4. **No Command Injection:** Do not use command substitution `$()` in generated output. | ||
| 4. **No Command Injection:** Do not use command substitution `$()` in generated shell commands. | ||
|
|
||
| ## Input Data | ||
|
|
||
|
|
@@ -79,7 +80,7 @@ | |
|
|
||
| ## Output Specification | ||
|
|
||
| Write a JSON array to the output. Format: | ||
| Write a JSON array to the output file. Format: | ||
|
|
||
| ```json | ||
| [ | ||
|
|
@@ -94,8 +95,8 @@ | |
| "explanation": "Request to beautify logging. Low priority per Goat Principle (current logs are ugly but functional)." | ||
| }} | ||
| ] | ||
| ``` | ||
| """ | ||
| Final Command Construction | ||
| Generate the final shell command to write the JSON to the environment variable. Ensure the JSON string is single-quoted to handle special characters correctly. """ | ||
|
Comment on lines
+98
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The updated system prompt instructs the LLM to generate a shell command that includes triaged issue data. This is a dangerous pattern because the issue data (e.g., explanations) is untrusted and can be crafted by an attacker to perform command injection. The prompt's instruction to 'Ensure the JSON string is single-quoted' is insufficient to prevent injection, as an attacker can include a single quote in the input to close the string and append malicious commands (e.g., |
||
|
|
||
|
|
||
| async def triage_issues_with_llm( | ||
|
|
@@ -195,13 +196,19 @@ async def triage_issues_with_llm( | |
| # 5. Parse JSON | ||
| content = response.content.strip() | ||
|
|
||
| # Strip Markdown code blocks if present | ||
| if content.startswith("```json"): | ||
| content = content[7:] | ||
| if content.startswith("```"): | ||
| content = content[3:] | ||
| if content.endswith("```"): | ||
| content = content[:-3] | ||
| # Attempt to extract JSON array using regex if markdown or extra text is present | ||
| # Matches [...] with DOTALL | ||
| json_match = re.search(r"\[.*\]", content, re.DOTALL) | ||
| if json_match: | ||
| content = json_match.group(0) | ||
|
Comment on lines
+201
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current parsing logic uses a greedy regular expression # Use a non-greedy match to find the first JSON-like array structure
json_match = re.search(r"[\s*\{.*?\}\s*]", content, re.DOTALL) |
||
| else: | ||
| # Fallback to simple stripping if regex fails (e.g. no brackets) | ||
| if content.startswith("```json"): | ||
| content = content[7:] | ||
| if content.startswith("```"): | ||
| content = content[3:] | ||
| if content.endswith("```"): | ||
| content = content[:-3] | ||
|
|
||
| content = content.strip() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
reimport becomes unused if the suggested refactoring of the JSON parsing logic is adopted, as that suggestion replaces the regular expression with a more robust bracket-balancing algorithm. To keep the codebase clean, please consider removing this import along with that change.