feat(git-guards): add GraphQL command guidance for known failure patterns#57
Conversation
…erns Adds allow-with-guidance detection to git-permission-guard.py for gh api graphql commands. When a command matches a known failure pattern (shell variable expansion, wrong mutation names, -f/-F flags, multi-line queries), the hook allows the command to proceed but injects corrective guidance via permissionDecisionReason so Claude can self-correct. Detects 4 patterns based on log analysis of 1,400+ failures: - Shell $variable expansion (125 occurrences) - Wrong mutation names: addPullRequestReviewComment (711) and resolvePullRequestReviewThread (162) - -f/-F query= flags that cause Go template variable expansion - Multi-line query indicators (trailing backslash, literal \n) Also adds test_graphql_guidance.py covering all 8 verification cases. (claude)
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 232eee3 in 10 seconds. Click for details.
- Reviewed
250lines of code in2files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_OfC604WQaS8B6jgE
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Summary of ChangesHello @JacobPEvans, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a helpful guidance mechanism for common gh api graphql errors. The implementation is solid, with new functions that are well-defined and specific. The addition of a comprehensive test suite is particularly commendable, as it covers all the new detection patterns, including edge cases and false positives. I have one suggestion to make the detection of incorrect mutation names more robust and avoid potential false positives.
There was a problem hiding this comment.
Pull request overview
This pull request adds proactive GraphQL command guidance to the git-permission-guard.py hook. When Claude attempts to run a gh api graphql command with known failure patterns, the guard allows the command to proceed (so it fails naturally with GitHub's error message) but simultaneously injects corrective guidance for immediate self-correction. This is based on analysis of over 1,400 actual failures across 8 distinct error types.
Changes:
- Adds
allow_with_guidance()function to emit warnings while allowing commands - Implements
check_graphql_guidance()to detect 4 common GraphQL failure patterns - Adds comprehensive test suite with 8 test cases covering all patterns and edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
git-guards/scripts/git-permission-guard.py |
Adds GraphQL guidance detection with 4 pattern checks (shell variables, wrong mutations, wrong flags, multi-line queries) and allow_with_guidance mechanism |
git-guards/scripts/test_graphql_guidance.py |
New test suite with 8 test cases validating detection patterns, false positive prevention, and combined pattern handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace simple substring `in` check with regex `\b{name}\b\s*\(` to
avoid false positives when a wrong mutation name appears in a comment
or string literal within the GraphQL query rather than as an actual
mutation call.
(claude)
CI validates all scripts in scripts/ have executable permission. (claude)
Summary
git-permission-guard.pyforgh api graphqlcommands matching known failure patternspermissionDecisionReasonfor immediate self-correctionFailure patterns covered
$variableexpansion in queries--raw-fieldwith inline valuesaddPullRequestReviewComment(wrong mutation)addPullRequestReviewThreadReply+ exampleresolvePullRequestReviewThread(wrong mutation)resolveReviewThread+ example-f/-F query=flags (Go template processing)--raw-fieldinstead\, literal\n)Implementation
Uses the
permissionDecision: "allow"+permissionDecisionReasonpattern (already used inwebfetch-guard.py). Multiple warnings are collected and shown together when a command has multiple issues.Only triggers for
gh api graphqlcommands — all other commands are completely unaffected.Test plan
-fflag → allow + 2 warningsaddPullRequestReviewComment→ allow + mutation guidanceresolvePullRequestReviewThread→ allow + mutation guidanceresolveReviewThread→ silent allow (no false positive)gh pr list→ silent allow (unaffected)--jq '$var'→ silent allow (no false positive on jq content)All 8 test cases pass via
git-guards/scripts/test_graphql_guidance.py.🤖 Generated with Claude Code
Important
Adds guidance for known failure patterns in
gh api graphqlcommands ingit-permission-guard.py, allowing commands to proceed with corrective advice.allow_with_guidancedetection ingit-permission-guard.pyforgh api graphqlcommands with known failure patterns.permissionDecisionReasonfor self-correction.$variableexpansion, wrong mutation names,-f/-Fflags, and multi-line queries.permissionDecision: "allow"+permissionDecisionReasonpattern.gh api graphqlcommands; other commands are unaffected.test_graphql_guidance.pywith 8 test cases, all passing.This description was created by
for 232eee3. You can customize this summary. It will automatically update as commits are pushed.