Skip to content

Commit f447948

Browse files
authored
Optimize security-guard Claude token usage via prompt cache alignment and smaller diff payloads (#2085)
* Initial plan * chore: optimize security-guard workflow token usage Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/9a210269-8ac9-41e3-919f-856a1265a617 * chore: refine security-guard diff truncation handling Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/9a210269-8ac9-41e3-919f-856a1265a617 * chore: align security-guard max turns env with workflow limit Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/81eb38a8-a633-497a-8d84-e626733b6f8a --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 6af8b15 commit f447948

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

.github/workflows/security-guard.lock.yml

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/security-guard.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
issues: read
1212
engine:
1313
id: claude
14-
max-turns: 12
14+
max-turns: 10
1515
features:
1616
cli-proxy: true
1717
tools:
@@ -32,14 +32,22 @@ steps:
3232
if: github.event.pull_request.number
3333
run: |
3434
DELIM="GHAW_PR_FILES_$(date +%s)"
35+
DIFF_LIMIT=5000
36+
DIFF_TMP="$(mktemp)"
3537
{
3638
echo "PR_FILES<<${DELIM}"
3739
gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" \
3840
--paginate --jq '.[] | "### " + .filename + " (+" + (.additions|tostring) + "/-" + (.deletions|tostring) + ")\n" + (.patch // "") + "\n"' \
39-
| head -c 8000 || true
41+
> "$DIFF_TMP" || true
42+
DIFF_SIZE="$(wc -c < "$DIFF_TMP" | tr -d ' ')"
43+
head -c "$DIFF_LIMIT" "$DIFF_TMP" || true
44+
if [ "$DIFF_SIZE" -gt "$DIFF_LIMIT" ]; then
45+
echo -e "\n[DIFF TRUNCATED at ${DIFF_LIMIT} bytes — use get_file_contents for full context]"
46+
fi
4047
echo ""
4148
echo "${DELIM}"
4249
} >> "$GITHUB_OUTPUT"
50+
rm -f "$DIFF_TMP"
4351
env:
4452
GH_TOKEN: ${{ github.token }}
4553
PR_NUMBER: ${{ github.event.pull_request.number }}
@@ -101,14 +109,6 @@ This repository implements a **network firewall for AI agents** that provides L7
101109
- Wildcard pattern security (prevents overly broad patterns)
102110
- Protocol prefix handling
103111

104-
## Changed Files (Pre-fetched)
105-
106-
The following PR diff has been pre-computed. Focus your security analysis on these changes:
107-
108-
```
109-
${{ steps.pr-diff.outputs.PR_FILES }}
110-
```
111-
112112
## Your Task
113113

114114
Analyze PR #${{ github.event.pull_request.number }} in repository ${{ github.repository }}.
@@ -170,4 +170,12 @@ If no security issues are found:
170170
- Do not add a comment (use noop safe-output)
171171
- The PR passes the security review
172172

173-
**SECURITY**: Be thorough but avoid false positives. Focus on actual security weakening, not code style or refactoring that maintains the same security level.
173+
**SECURITY**: Be thorough but avoid false positives. Focus on actual security weakening, not code style or refactoring that maintains the same security level.
174+
175+
## Changed Files (Pre-fetched)
176+
177+
The following PR diff has been pre-computed. Focus your security analysis on these changes:
178+
179+
```
180+
${{ steps.pr-diff.outputs.PR_FILES }}
181+
```

0 commit comments

Comments
 (0)