refactor(kit): Expose core Kit CLI functionality as a reusable Go library #905#1097
Conversation
Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6da19a0973
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| desc, err := localRepo.PullModel(ctx, repo, *opts.modelRef, &opts.NetworkOptions) | ||
| desc, err := localRepo.PullModel(ctx, repo, *opts.ModelRef, &opts.NetworkOptions) |
There was a problem hiding this comment.
Normalize Pull concurrency before invoking repository pull
The new kit.Pull API forwards opts.NetworkOptions directly into localRepo.PullModel without running NetworkOptions.Complete or otherwise enforcing a minimum concurrency, so zero-value PullOptions (a common Go usage) pass Concurrency=0. In pkg/lib/repo/local/pull.go:65-85, that becomes semaphore.NewWeighted(0) followed by Acquire(..., 1), which blocks until context cancellation and makes pulls hang/fail even for valid references; the old CLI path avoided this because flag parsing set a default and Complete validated >=1.
Useful? React with 👍 / 👎.
| if err != nil { | ||
| return err | ||
| } | ||
| reg, err := remote.NewRegistry(opts.Registry, &opts.NetworkOptions) |
There was a problem hiding this comment.
Default TLS verification to enabled for kit API calls
This new library entrypoint passes opts.NetworkOptions straight to remote.NewRegistry, so callers who use zero-value LoginOptions get TLSVerify=false; pkg/lib/network/auth.go:71 then sets InsecureSkipVerify = !opts.TLSVerify, silently disabling certificate verification. The CLI previously defaulted --tls-verify to true via flag wiring, but the extracted pkg/kit API now exposes an insecure default for normal programmatic use and can allow MITM interception of registry credentials unless every caller manually overrides it.
Useful? React with 👍 / 👎.
Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
|
Addressed both Codex P1 suggestions by adding safe default normalization in pkg/kit API entrypoints (pull/login), and re-ran targeted tests for kit/network/repo packages. |
| @@ -66,17 +91,15 @@ func removeAllModels(ctx context.Context, opts *removeOptions) error { | |||
| output.Errorf("Failed to remove %s@%s: %s", repository, manifestDesc.Digest, err) | |||
| continue | |||
| } | |||
| // Skip future manifest descriptors with this digest, since we just removed it. | |||
| skipManifests[manifestDesc.Digest] = true | |||
| output.Infof("Removed %s@%s", repository, manifestDesc.Digest) | |||
| } | |||
There was a problem hiding this comment.
Why have all the comments on this file been removed?
There was a problem hiding this comment.
the comments were accidentally stripped during the initial refactor. Restored all comments in pkg/kit/remove.go (the new home for this logic) in 95e4e52, including the skipManifests explanation, untag-vs-delete rationale, and the oras Untagger interface note.
pkg/cmd/remove/cmd.go
Outdated
| kitOpts := &kit.RemoveOptions{ | ||
| NetworkOptions: opts.NetworkOptions, | ||
| ConfigHome: opts.configHome, | ||
| ForceDelete: opts.forceDelete, | ||
| RemoveAll: opts.removeAll, | ||
| Remote: opts.remote, | ||
| ModelRef: opts.modelRef, | ||
| ExtraTags: opts.extraTags, |
There was a problem hiding this comment.
We're now duplicating the options for every command twice -- once in the cmd package and once in the kit package. Why not import the e.g. kit.RemoveOptions struct here and bind flags into it instead of defining it twice?
There was a problem hiding this comment.
Agreed, this was unnecessary duplication. Fixed in 95e4e52 — all cmd packages now embed kit.*Options directly (e.g. type removeOptions struct { kit.RemoveOptions }) and pass &opts.RemoveOptions to the kit function. CLI-specific fields like format/template in list or username/password in login are the only local additions. No more manual field-by-field copy.
022577d to
503f383
Compare
Resolve merge conflicts with upstream/main, incorporating: - artifact.FormatRepositoryForDisplay/ReferenceIsDigest renames - --filter support for kit list - kitfile.FilterConf/ParseFilter relocation Address reviewer feedback: - Eliminate options duplication by embedding kit.*Options in cmd structs - Restore comments removed during initial refactor - Use kit.ModelInfo directly in cmd/list via type alias Fix review findings: - Fix %ws typo in removeModelRef error wrapping - Add credential/concurrency initialization to kit.Push - Fix TagCommand to use declared opts variable Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
503f383 to
b9ad61f
Compare
Add pkg/kit wrappers for pack, kitinit, and diff commands: - kit.Pack: packs ModelKits with cwd save/restore for library safety - kit.Init: generates Kitfiles from local dirs or HF repos, returns bytes - kit.Diff: compares two ModelKits concurrently, returns DiffResult - kit.CompareManifests: re-exported pure comparison function Fix review bugs: - Extract applyNetworkDefaults helper for consistent TLS/credential defaults across all remote-capable functions (Pull, Push, Login, Inspect, Info, List, Diff) - Fix %w verb in output.Errorf (only valid in fmt.Errorf) Wire CLI commands to delegate to pkg/kit, move tests accordingly. Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
Signed-off-by: Arnab Chatterjee <arnabchat2001@gmail.com>
Known limitations & follow-up workNot yet wrapped in
|
|
@amisevsk Let me know of your thoughts if dev, kitimport, kitcache and version should be included in this PR. also waiting for your review |
Description
Refactors CLI command implementations into a reusable Go API under
pkg/kit.pkg/kitoperations forInfo,Inspect,List,Login,Logout,Pull,Push,Remove,Tag, andUnpackwrappers.pkg/cmd/*/cmd.go) to callpkg/kitinstead of local command-specific logic.pkg/cmd/*.pkg/kit/list_test.go.pkg/kit/doc.go,pkg/kit/README.md)..gitignoreto ignore root-only binaries (/kit,/kit.exe).go test ./...passes.Closes #905
AI-Assisted Code