You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
github.com/itchyny/gojq is a pure Go implementation of jq β the JSON query and transformation language. It provides both a CLI and a Go library with full jq compatibility, plus Go-native extensions like context cancellation, custom functions, and custom types. The project currently uses v0.12.18; v0.12.19 is now available.
Current Usage in gh-aw-mcpg
gojq powers the large payload middleware (internal/middleware/jqschema.go). When a backend MCP tool response exceeds the configured sizeThreshold, the middleware:
Saves the full JSON payload to disk (payload.json)
Runs a jq schema-inference filter that replaces leaf values with their type names ("string", "number", etc.) and collapses arrays to a single representative element
Returns a lightweight metadata response to the client containing the schema, a preview, and the file path
Pattern: pre-compiled query code (compile once at init(), reuse per request)
Research Findings
The project already follows gojq's recommended best practices quite well. The benchmarks in jqschema_bench_test.go demonstrate a 10β100x speedup from pre-compiling vs parsing on every request, and the implementation correctly uses RunWithContext for cancellation.
Recent Updates (v0.12.18βv0.12.19)
v0.12.19 is the latest release (observed via GitHub release metadata). An upgrade would bring any bug fixes and potential performance improvements since v0.12.18.
Best Practices (already applied β )
Pre-compile with gojq.Compile() at init() β fail-fast validation at startup
Use RunWithContext() β context cancellation/timeout propagated into jq execution
UTF-8 safe truncation β preview truncation walks back to nearest valid rune boundary
Improvement Opportunities
π Quick Wins
1. Upgrade to v0.12.19
The project uses v0.12.18; v0.12.19 is available. Standard bump via go get github.com/itchyny/gojq@latest + go mod tidy.
2. Rename the custom walk(f) def to avoid shadowing the built-in
The jq schema filter defines def walk(f) which shadows gojq's built-in walk/1. While it works and is well-documented in comments, using a distinct name like walk_schema avoids any potential future confusion:
3. Fix generateRandomID fallback collision risk
When crypto/rand.Read fails, the fallback is fmt.Sprintf("fallback-%d", os.Getpid()) β the same ID for every call within the same process. Concurrent tool calls would collide on payload file paths. A better fallback:
4. Tighten payload file permissions (security) savePayload writes files with 0644 (world-readable). Since payloads may contain sensitive API responses, 0600 (owner read/write only) is more appropriate:
iferr:=os.WriteFile(filePath, payload, 0600); err!=nil { // was 0644
β¨ Feature Opportunities
5. gojq.WithFunction for native Go type helpers
gojq supports registering native Go functions callable from jq filters. For future extensibility (e.g., custom schema annotations, type overrides, field redaction), gojq.WithFunction could inject Go logic directly:
6. gojq.WithVariables for configurable filter parameters
Schema filter options (max depth, excluded fields) could be passed as jq variables at compile time, enabling runtime customization without changing the filter string:
gojq.Compile(query, gojq.WithVariables([]string{"$excludeKeys"}))
// At run time:code.RunWithContext(ctx, data, excludedKeysList)
π Best Practice Alignment
7. Assert single-output contract in tests
The walk_schema filter always produces exactly one output value. Unit tests could verify this invariant by asserting iter.Next() returns false on the second call, documenting the contract and catching future filter changes that accidentally produce multiple outputs.
Recommendations
Priority
Item
Effort
π΄ High
Fix generateRandomID fallback (collision risk on concurrent calls)
Trivial
π΄ High
Fix payload file permissions: 0644 β 0600
Trivial
π‘ Medium
Upgrade gojq to v0.12.19
Low
π‘ Medium
Rename def walk(f) to def walk_schema
Low
π’ Low
Explore gojq.WithFunction for future extensibility
Medium
π’ Low
Add single-output contract assertion in tests
Low
Next Steps
Fix generateRandomID fallback: add time.Now().UnixNano() to avoid collisions
Change payload file write permission from 0644 to 0600
Bump github.com/itchyny/gojq to v0.12.19 and run go mod tidy
Rename def walk(f) β def walk_schema in jqSchemaFilter constant
Generated by Go Fan πΉ Module analysis saved to session artifacts: specs/mods/gojq.md
Note
π Integrity filter blocked 8 items
The following items were blocked because they don't meet the GitHub integrity level.
πΉ Go Fan Report: gojq
Module Overview
github.com/itchyny/gojqis a pure Go implementation of jq β the JSON query and transformation language. It provides both a CLI and a Go library with full jq compatibility, plus Go-native extensions like context cancellation, custom functions, and custom types. The project currently usesv0.12.18;v0.12.19is now available.Current Usage in gh-aw-mcpg
gojq powers the large payload middleware (
internal/middleware/jqschema.go). When a backend MCP tool response exceeds the configuredsizeThreshold, the middleware:payload.json)"string","number", etc.) and collapses arrays to a single representative elementgojq.Parse,gojq.Compile,(*Code).RunWithContext,*gojq.HaltErrorinit(), reuse per request)Research Findings
The project already follows gojq's recommended best practices quite well. The benchmarks in
jqschema_bench_test.godemonstrate a 10β100x speedup from pre-compiling vs parsing on every request, and the implementation correctly usesRunWithContextfor cancellation.Recent Updates (v0.12.18βv0.12.19)
Best Practices (already applied β )
gojq.Compile()atinit()β fail-fast validation at startupRunWithContext()β context cancellation/timeout propagated into jq execution*gojq.HaltErrorspecifically β correct typed error handlingImprovement Opportunities
π Quick Wins
1. Upgrade to v0.12.19
The project uses
v0.12.18;v0.12.19is available. Standard bump viago get github.com/itchyny/gojq@latest+go mod tidy.2. Rename the custom
walk(f)def to avoid shadowing the built-inThe jq schema filter defines
def walk(f)which shadows gojq's built-inwalk/1. While it works and is well-documented in comments, using a distinct name likewalk_schemaavoids any potential future confusion:3. Fix
generateRandomIDfallback collision riskWhen
crypto/rand.Readfails, the fallback isfmt.Sprintf("fallback-%d", os.Getpid())β the same ID for every call within the same process. Concurrent tool calls would collide on payload file paths. A better fallback:4. Tighten payload file permissions (security)
savePayloadwrites files with0644(world-readable). Since payloads may contain sensitive API responses,0600(owner read/write only) is more appropriate:β¨ Feature Opportunities
5.
gojq.WithFunctionfor native Go type helpersgojq supports registering native Go functions callable from jq filters. For future extensibility (e.g., custom schema annotations, type overrides, field redaction),
gojq.WithFunctioncould inject Go logic directly:6.
gojq.WithVariablesfor configurable filter parametersSchema filter options (max depth, excluded fields) could be passed as jq variables at compile time, enabling runtime customization without changing the filter string:
π Best Practice Alignment
7. Assert single-output contract in tests
The
walk_schemafilter always produces exactly one output value. Unit tests could verify this invariant by assertingiter.Next()returnsfalseon the second call, documenting the contract and catching future filter changes that accidentally produce multiple outputs.Recommendations
generateRandomIDfallback (collision risk on concurrent calls)0644β0600def walk(f)todef walk_schemagojq.WithFunctionfor future extensibilityNext Steps
generateRandomIDfallback: addtime.Now().UnixNano()to avoid collisions0644to0600github.qkg1.top/itchyny/gojqtov0.12.19and rungo mod tidydef walk(f)βdef walk_schemainjqSchemaFilterconstantGenerated by Go Fan πΉ
Module analysis saved to session artifacts:
specs/mods/gojq.mdNote
π Integrity filter blocked 8 items
The following items were blocked because they don't meet the GitHub integrity level.
get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".list_commits: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_latest_release: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".get_file_contents: has lower integrity than agent requires. The agent cannot read data with integrity below "unapproved".To allow these resources, lower
min-integrityin your GitHub frontmatter: