Kong CLI parity via shared command logic
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
PersistentPreRuninto 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 issuesmise run fmt:go— clean- Both
cogandcog-kongcompile; no binaries committed - New
cmd/cog-kong/main_test.goasserts 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/cogremains the production Cobra binary, unchanged in behaviour.- Draft: opening for review of the shared-code seams before finalising.
I found a few parity issues between the Kong and Cobra CLIs and posted them as review comments on PR #3047.
Summary of issues:
BaseImageBuildCmdis missing--no-cacheand--progressflags that the Cobra version haspredict,train,weights, anddebugcommands are hidden in Cobra but visible in Kong- Unreachable
os.Exit(1)afterparser.FatalIfErrorf(err)inmain.go(dead code)
The review with suggestions is here: https://github.com/replicate/cog/pull/3047#pullrequestreview-4429601140
github run
LGTM
github run
LGTM
github run
LGTM
github run