feat(protocol): generate Go SDK from Codex JSON Schema#2
feat(protocol): generate Go SDK from Codex JSON Schema#2birdmanmandbir merged 3 commits intomainfrom
Conversation
Add custom Python codegen (cmd/codegen/main.py) that reads the Codex app-server-protocol JSON Schema (339 types) and generates typed Go bindings: - protocol/types_gen.go: 240 structs, 44 enums, type aliases - protocol/unions_gen.go: discriminated unions (ClientRequest, ServerNotification, ServerRequest) with typed params getters - protocol/methods_gen.go: 42 client request + 42 server notification + 7 server request method constants Includes Makefile, go:generate directive, CI workflow, and tests.
Add CI pipeline that verifies generated files are up-to-date, runs go vet and go test on push to main and PRs.
PR Review: feat: Generate Go SDK from Codex JSON SchemaSummarySolid codegen foundation. Python script reads the Codex JSON Schema and emits typed Go structs, discriminated union wrappers with typed Critical1. Inconsistent Go field naming for snake_case vs camelCase JSON keys The
Same for Root cause: The snake_case branch at line 86-88 of # Snake_case path (line 86-88) - NO acronym fixup
if "_" in name:
parts = name.split("_")
name = "".join(p.capitalize() for p in parts if p)
return name # <-- returns "ThreadId" not "ThreadID"
# camelCase path (lines 100-110) - HAS acronym fixup
result = re.sub(r'Id$', 'ID', result) # <-- fixes to "ThreadID"Fix: Apply the same acronym regex fixups after the snake_case join before returning. Minor2. Dead code in Lines 94-96 compute aggressive replacements that are immediately overwritten at line 100 ( 3. This is a hack to keep the 4. CI doesn't cache Python — The GitHub Actions workflow sets up Python 3.12 but doesn't cache pip. Not needed now since there are no pip dependencies, but worth noting if dependencies are added later. Nits
VERDICT: NEEDS_WORKThe snake_case acronym inconsistency (#1) is a real API surface bug — consumers will see |
Triage UpdateFixed
Additional improvements
Not addressed
|
Re-Review: Post-Fix AssessmentOriginal Issues - Status
Additional Improvements Verified
New Minor IssueDead code in Lines 36-47 build into a // Current (dead code + redo):
var result strings.Builder
for _, part := range parts { // <-- this loop output gets discarded
if part != "" {
result.WriteByte(part[0] - 32 + 32)
// ...
}
}
// Oops, wrote two bytes above. Let me redo this properly.
result.Reset()
for _, part := range parts { // <-- this is the real loop
// ...
}Nit: regexp.MustCompile in function bodies
VERDICT: NEEDS_WORKThe dead code with "Oops" comment in |
Triage UpdateFixed
RemainingNone — all review items addressed. |
Re-Review: Post-Fix Assessment (Round 2)Original Issues — Final Status
Verified
Warning: Changes are uncommittedAll the fixes exist in the working tree but have not been committed. The VERDICT: LGTMAll review items are addressed. Code quality is good — the Go port is clean, idiomatic, and well-structured. Just needs a commit. |
Replace cmd/codegen/main.py (714 lines) with cmd/codegen/main.go, making the project pure Go with zero external dependencies. - Port all schema parsing, type generation, union generation, and method constant generation to idiomatic Go - Fix snake_case field acronym inconsistency: toGoFieldName now applies Id→ID, Url→URL, Api→API, Mcp→MCP fixups to both snake_case and camelCase paths (thread_id→ThreadID, call_id→CallID, etc.) - Remove var _ json.RawMessage hack from generated output - Hoist regexp.MustCompile calls to package-level vars - Use go/format (stdlib) instead of shelling out to gofmt - Update Makefile with help, fmt, lint targets - Add gofmt check, golangci-lint, and go build steps to CI - Remove actions/setup-python from CI workflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Triage UpdateStatus: All items addressed, committed, and pushedCommit Fixed (all rounds)
RemainingNone — merging. |
Summary
cmd/codegen/main.py) produces three files:protocol/types_gen.go— ~330 struct types, enums, and type aliases with correct json tags and nullable pointersprotocol/unions_gen.go— discriminated union types (ClientRequest,ServerNotification,ServerRequest) with typed params accessor methodsprotocol/methods_gen.go— all method/notification/request string constantsgenerate,vet,test,citargetsmake generate/go generate ./...Test plan
go vet ./...passesgo test ./...passes (marshal round-trips, params unmarshaling, enum values, nullable field omission)