cog icon indicating copy to clipboard operation
cog copied to clipboard

Kong CLI parity via shared command logic

Open markphelps opened this issue 5 months ago • 4 comments

Summary

Builds the side-by-side cmd/cog-kong CLI to full command parity with the existing Cobra CLI (cmd/cog), while extracting parser-independent command behaviour into shared, exported functions under pkg/cli.

Both CLIs now execute the same core code: command behaviour, validation, Docker/model/provider setup, output formatting, and errors live in shared Run* functions and *Options structs. Cobra owns flag registration/parsing; Kong owns struct tags + DI; neither owns behaviour.

All 13 commands reach parity: build, push, serve, exec, predict, run, train, init, login, doctor, debug, weights (import/pull/status), base-image (dockerfile/build).

Approach

Each task extracts one command's behaviour into shared code, then wires both Cobra and Kong adapters into it (TDD: failing parse/behaviour test → shared runner → thin adapters):

Task Shared runner(s) added
build RunBuild, BuildFlagsOptions, ResolveBuildImageName
push RunPush, ResolvePushTarget, PushCommandOptions
serve/exec RunServe, RunExec, RuntimeBuildOptions
init/login/doctor/debug RunInit, RunLogin, RunDoctor, RunDebug
predict/run/train RunPrediction, RunTrain
weights RunWeightsImport, RunWeightsPull, RunWeightsStatus
base-image RunBaseImageDockerfile, RunBaseImageBuild

Deviations from the original plan

The plan was speculative in a few spots; the implementation matches the real code:

  • Dropped non-existent OCIIndex / OCIIndexEnabled() from build options.
  • Used the real base-image flags (--cuda/--python/--torch), not the plan's guessed --*-version.
  • Removed short:"v" from Kong's --version — it diverged from Cobra (which has no -v) and collided with the weights commands' -v (verbose).
  • Moved the weights experimental warning from Cobra's PersistentPreRun into the shared runners, so it fires once per subcommand from a single source.

Verification

  • mise run test:go — all pass (2018 tests)
  • mise run lint:go — 0 issues
  • mise run fmt:go — clean
  • Both cog and cog-kong compile; no binaries committed
  • New cmd/cog-kong/main_test.go asserts the full command surface (registration, nested commands, root globals, per-command flag parsing) without requiring Docker

Notes

  • Base branch is kong (this stacks on the existing side-by-side scaffold).
  • cmd/cog remains the production Cobra binary, unchanged in behaviour.
  • Draft: opening for review of the shared-code seams before finalising.

markphelps avatar Jun 04 '26 16:06 markphelps

I found a few parity issues between the Kong and Cobra CLIs and posted them as review comments on PR #3047.

Summary of issues:

  1. BaseImageBuildCmd is missing --no-cache and --progress flags that the Cobra version has
  2. predict, train, weights, and debug commands are hidden in Cobra but visible in Kong
  3. Unreachable os.Exit(1) after parser.FatalIfErrorf(err) in main.go (dead code)

The review with suggestions is here: https://github.com/replicate/cog/pull/3047#pullrequestreview-4429601140

github run

ask-bonk avatar Jun 04 '26 16:06 ask-bonk

LGTM

github run

ask-bonk avatar Jun 08 '26 18:06 ask-bonk

LGTM

github run

ask-bonk avatar Jun 08 '26 19:06 ask-bonk

LGTM

github run

ask-bonk avatar Jun 11 '26 15:06 ask-bonk