-
Notifications
You must be signed in to change notification settings - Fork 489
Add jqschema shared workflow for analyzing large tool outputs #1942
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a9dfc1
Initial plan
Copilot 7af76fa
Add json-schema-minify shared workflow
Copilot 57f8ac8
Enhance json-schema-minify documentation with GitHub search examples
Copilot f981da1
Rename json-schema-minify to jqschema and add to workflows
Copilot 1917c1e
Update jqschema to use /tmp/gh-aw/ directly and add bash tools
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ tools: | |
|
|
||
| imports: | ||
| - shared/mcp/tavily.md | ||
| - shared/jqschema.md | ||
| --- | ||
|
|
||
| # Daily News | ||
|
|
||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| --- | ||
| tools: | ||
| bash: | ||
| - "jq *" | ||
| - "/tmp/gh-aw/jqschema.sh" | ||
| steps: | ||
| - name: Set up jq utilities directory | ||
| run: | | ||
| cat > /tmp/gh-aw/jqschema.sh << 'EOF' | ||
| #!/usr/bin/env bash | ||
| # jqschema.sh | ||
| jq -c ' | ||
| def walk(f): | ||
| . as $in | | ||
| if type == "object" then | ||
| reduce keys[] as $k ({}; . + {($k): ($in[$k] | walk(f))}) | ||
| elif type == "array" then | ||
| if length == 0 then [] else [.[0] | walk(f)] end | ||
| else | ||
| type | ||
| end; | ||
| walk(.) | ||
| ' | ||
| EOF | ||
| chmod +x /tmp/gh-aw/jqschema.sh | ||
| --- | ||
|
|
||
| ## jqschema - JSON Schema Discovery | ||
|
|
||
| A utility script is available at `/tmp/gh-aw/jqschema.sh` to help you discover the structure of complex JSON responses. | ||
|
|
||
| ### Purpose | ||
|
|
||
| Generate a compact structural schema (keys + types) from JSON input. This is particularly useful when: | ||
| - Analyzing tool outputs from GitHub search (search_code, search_issues, search_repositories) | ||
| - Exploring API responses with large payloads | ||
| - Understanding the structure of unfamiliar data without verbose output | ||
| - Planning queries before fetching full data | ||
|
|
||
| ### Usage | ||
|
|
||
| ```bash | ||
| # Analyze a file | ||
| cat data.json | /tmp/gh-aw/jqschema.sh | ||
|
|
||
| # Analyze command output | ||
| echo '{"name": "test", "count": 42, "items": [{"id": 1}]}' | /tmp/gh-aw/jqschema.sh | ||
|
|
||
| # Analyze GitHub search results | ||
| gh api search/repositories?q=language:go | /tmp/gh-aw/jqschema.sh | ||
| ``` | ||
|
|
||
| ### How It Works | ||
|
|
||
| The script transforms JSON data by: | ||
| 1. Replacing object values with their type names ("string", "number", "boolean", "null") | ||
| 2. Reducing arrays to their first element's structure (or empty array if empty) | ||
| 3. Recursively processing nested structures | ||
| 4. Outputting compact (minified) JSON | ||
|
|
||
| ### Example | ||
|
|
||
| **Input:** | ||
| ```json | ||
| { | ||
| "total_count": 1000, | ||
| "items": [ | ||
| {"login": "user1", "id": 123, "verified": true}, | ||
| {"login": "user2", "id": 456, "verified": false} | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| **Output:** | ||
| ```json | ||
| {"total_count":"number","items":[{"login":"string","id":"number","verified":"boolean"}]} | ||
| ``` | ||
|
|
||
| ### Best Practices | ||
|
|
||
| **Use this script when:** | ||
| - You need to understand the structure of tool outputs before requesting full data | ||
| - GitHub search tools return large datasets (use `perPage: 1` and pipe through schema minifier first) | ||
| - Exploring unfamiliar APIs or data structures | ||
| - Planning data extraction strategies | ||
|
|
||
| **Example workflow for GitHub search tools:** | ||
| ```bash | ||
| # Step 1: Get schema with minimal data (fetch just 1 result) | ||
| # This helps understand the structure before requesting large datasets | ||
| echo '{}' | gh api search/repositories -f q="language:go" -f per_page=1 | /tmp/gh-aw/jqschema.sh | ||
|
|
||
| # Output shows the schema: | ||
| # {"incomplete_results":"boolean","items":[{...}],"total_count":"number"} | ||
|
|
||
| # Step 2: Review schema to understand available fields | ||
|
|
||
| # Step 3: Request full data with confidence about structure | ||
| # Now you know what fields are available and can query efficiently | ||
| ``` | ||
|
|
||
| **Using with GitHub MCP tools:** | ||
| When using tools like `search_code`, `search_issues`, or `search_repositories`, pipe the output through jqschema to discover available fields: | ||
| ```bash | ||
| # Save a minimal search result to a file | ||
| gh api search/code -f q="jq in:file language:bash" -f per_page=1 > /tmp/sample.json | ||
|
|
||
| # Generate schema to understand structure | ||
| cat /tmp/sample.json | /tmp/gh-aw/jqschema.sh | ||
|
|
||
| # Now you know which fields exist and can use them in your analysis | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@copilot add tools section
tools:
bash:
- "jq *"
- "/tmp/gh-aw/jqschema.sh"
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.
Added tools section with bash: ["jq *", "/tmp/gh-aw/jqschema.sh"]. Tools are automatically merged into workflows that import jqschema.