Skip to content

codegen: add endpoint grouper with agent-first naming (PRINFRA-121) - #13

Merged
somanshreddy merged 1 commit into
mainfrom
03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm
Apr 1, 2026
Merged

somanshreddy merged 1 commit into
mainfrom
03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Takes an OpenAPI spec and produces command.Groups — CLI command definitions grouped by name. This is the core of the codegen pipeline.

Naming algorithm

Derives CLI command names from URL path structure. No hardcoded maps or word classification.

Steps:

  1. Group name from tag — lowercase, spaces to hyphens, singularize ("Video Translate" → "video-translate")
  2. Parse path segments — drop version prefix + group root, classify the rest: literals → sub-groups, {params} → positional args
  3. Append terminal verb from HTTP method (GET→list/get, POST→create, DELETE→delete, PATCH/PUT→update)
  4. Exception — endpoints marked x-cli-action: true in the OpenAPI spec skip the terminal verb. This flag is an extension (like x-cli-visible) set by the API team on RPC-style action endpoints where the last path segment is already a verb — without it, POST .../stop would produce stop create. The codegen reads the flag; the spec annotations are tracked in PRINFRA-145.

Common case — standard CRUD:

GET /v3/videos/{video_id}
  tag "Videos" → group "video"
  remaining: [{video_id}]
  {video_id} → positional arg
  last is param → GET → terminal verb "get"
  → heygen video get <video-id>

Edge case — nested action endpoint:

POST /v3/video-agents/sessions/{session_id}/stop   [x-cli-action: true]
  tag "Video Agent" → group "video-agent"
  remaining: [sessions, {session_id}, stop]
  sessions → sub-group, {session_id} → arg, stop → sub-group
  x-cli-action → no terminal verb (without it, this would be "sessions stop create")
  → heygen video-agent sessions stop <session-id>

Automation

Of every generated command, the following is fully automatic from the spec:

  • Group name, command name, sub-group hierarchy, flags, args, pagination, multipart, body encoding

The only manual inputs are:

  • x-cli-visible in the spec — 15 v1/v2 endpoints excluded (set by API team)
  • x-cli-action in the spec — 3 action endpoints where the path segment is the verb (set by API team)
  • examples.yaml in the CLI repo — curated usage examples for every command

Other responsibilities

  • Filters endpoints by x-cli-visible
  • Detects pagination from response schema (has_more + token field)
  • Detects multipart from content type; emits Source: "file" flags that route to inv.FilePath
  • Classifies body fields as simple (→ flag) or complex (→ skipped, covered by -d/--data)
  • Validates no generated flag name collides with reserved names (-d, --help, --version)

Design decisions

  • Agent-first grammar — every command ends with a verb for predictable structure
  • PUT → update (not upload) — correct REST semantics; PUT is idempotent update
  • Plural sub-groups — mirror the URL path (sessions, endpoints, proofreads)
  • Safe path decomposition — bounds-checked segment indexing, handles short paths gracefully

Testing

11 tests covering: hidden endpoint filtering, group name singularization, terminal verbs, query flags, complex field skipping, path args, pagination, multipart with Source:"file", examples, x-cli-action, sub-group naming.

Files

  • codegen/grouper.go — GroupEndpoints, buildSpec, deriveCommandName, schema/pagination/multipart helpers
  • codegen/grouper_test.go — 11 tests
  • codegen/testdata/test_spec.yaml — test OpenAPI spec (videos, avatars, assets, action and hidden endpoints)

@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 803d72a to 1ac674a Compare March 31, 2026 18:29
@somanshreddy somanshreddy changed the title codegen: add endpoint grouper and subcommand naming algorithm codegen: add endpoint grouper and naming algorithm (PRINFRA-121) Mar 31, 2026
@linear

linear Bot commented Mar 31, 2026

Copy link
Copy Markdown
PRINFRA-121 CLI M1: OpenAPI codegen pipeline

Build the code generation pipeline that reads openapi/external-api.json and produces CommandSpec structs.

Scope

  • Go program in codegen/ using text/template
  • Parse OpenAPI spec, filter to v3 endpoints only
  • Generate CommandSpec data structs in gen/ (zero logic)
  • overrides.yaml for:
    • Positional arg promotion (prompt, text, file)
    • Command group naming (video-translations → translate, webhooks/endpoints → webhook)
    • Help examples per command
  • make generate SPEC=... target
  • Nested path collapsing (e.g., /webhooks/endpoints/{id}/rotate-secret → webhook rotate-secret)
  • Golden file tests for codegen output stability
  • Generate all ~30 commands, wire into Cobra at startup

Mapping Rules

  • OpenAPI tag → command group
  • POST → create, GET (list) → list, GET (by id) → get, DELETE → delete, PATCH → update
  • Path params → positional args, query params → flags, body fields → flags
  • overrides.yaml exceptions for positional promotion and group naming

Acceptance Criteria

  • make generate produces compilable CommandSpec files for all v3 endpoints
  • Adding a new endpoint to spec + re-running codegen produces new command
  • Generated help text includes descriptions and examples
  • Golden file tests pass
  • Override validation: make generate fails if overrides reference non-existent endpoints

@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_openapi_spec_parser branch from 5b95564 to 735c417 Compare March 31, 2026 19:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 1ac674a to 612f394 Compare March 31, 2026 19:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_openapi_spec_parser branch from 735c417 to 3511ac2 Compare March 31, 2026 20:08
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 612f394 to 16bd8ed Compare March 31, 2026 20:08
@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_openapi_spec_parser to graphite-base/13 March 31, 2026 20:59
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 16bd8ed to b29c389 Compare March 31, 2026 20:59
@somanshreddy
somanshreddy changed the base branch from graphite-base/13 to 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions March 31, 2026 20:59
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from b29c389 to f03c006 Compare March 31, 2026 21:06
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from ee89581 to 15e4901 Compare March 31, 2026 21:07
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from f03c006 to cfec8dd Compare March 31, 2026 21:25
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from 15e4901 to cae4380 Compare March 31, 2026 21:25
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 2 times, most recently from 868657e to 2c83785 Compare March 31, 2026 21:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from cae4380 to 9e4f567 Compare March 31, 2026 21:55
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 2c83785 to 21f7dfa Compare March 31, 2026 21:55
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from 9e4f567 to 89d91d3 Compare March 31, 2026 21:58
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 2 times, most recently from c337bb8 to 5a7da12 Compare March 31, 2026 22:02
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch 2 times, most recently from 1a1881e to 545c7f1 Compare March 31, 2026 22:04
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 5a7da12 to a4d0678 Compare March 31, 2026 22:04
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 45caa51 to fd011ae Compare April 1, 2026 04:27
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from b240371 to 18f3382 Compare April 1, 2026 04:27
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from fd011ae to 791edee Compare April 1, 2026 04:39
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch 2 times, most recently from 5a3e6ad to b08f6d2 Compare April 1, 2026 06:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 791edee to 61e9e49 Compare April 1, 2026 06:41
@somanshreddy somanshreddy changed the title codegen: add endpoint grouper and naming algorithm (PRINFRA-121) codegen: add endpoint grouper with agent-first naming (PRINFRA-121) Apr 1, 2026
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 4 times, most recently from 19c3f69 to a61cb00 Compare April 1, 2026 07:23
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from b08f6d2 to 6e8db51 Compare April 1, 2026 07:26
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from a61cb00 to 0a34434 Compare April 1, 2026 07:26
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from 6e8db51 to ef458e1 Compare April 1, 2026 07:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 2 times, most recently from 23a6763 to f6691d3 Compare April 1, 2026 07:42
@somanshreddy
somanshreddy marked this pull request as ready for review April 1, 2026 08:04
@somanshreddy
somanshreddy requested a review from jrusso1020 April 1, 2026 08:15
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from ef458e1 to 89e818b Compare April 1, 2026 17:01
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from f6691d3 to 57dd9f1 Compare April 1, 2026 17:02

somanshreddy commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Apr 1, 7:16 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 1, 7:18 PM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 1, 7:19 PM UTC: @somanshreddy merged this pull request with Graphite.

@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions to graphite-base/13 April 1, 2026 19:17
@somanshreddy
somanshreddy changed the base branch from graphite-base/13 to main April 1, 2026 19:17
Groups parsed endpoints by OpenAPI tag, derives group names (lowercase,
singularized, overrides applied), derives subcommand names from path
suffix + HTTP method (list/get/create/delete/update/nested-action).
Routes path params to ArgSpec, query params to FlagSpec, body fields
to FlagSpec. Applies positional promotions from overrides.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 57dd9f1 to 34911cf Compare April 1, 2026 19:18
@somanshreddy
somanshreddy merged commit 25e9715 into main Apr 1, 2026
8 checks passed
@somanshreddy
somanshreddy deleted the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch April 1, 2026 19:19
@somanshreddy somanshreddy added this to the M1: Codegen Pipeline milestone Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants