Add thv llm command group with config types and management commands#5032
Add thv llm command group with config types and management commands#5032
Conversation
Introduces the pkg/llm package with LLMConfig types (IsConfigured, Validate, EffectiveProxyPort, EffectiveScopes), adds ScopeLLM to the secrets scoped provider, wires the LLM field into the top-level Config struct, and adds the thv llm cobra command group with fully-implemented config set/show/reset subcommands plus stubbed setup, teardown, proxy start, and token commands. Part of #5016. Closes #5027. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5032 +/- ##
==========================================
+ Coverage 69.09% 69.78% +0.69%
==========================================
Files 556 557 +1
Lines 73348 56254 -17094
==========================================
- Hits 50679 39258 -11421
+ Misses 19648 13978 -5670
+ Partials 3021 3018 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
b4b0dd2 to
fbd81ea
Compare
PR size has been reduced below the XL threshold. Thank you for splitting this up!
|
✅ PR size has been reduced below the XL threshold. The size review has been dismissed and this PR can now proceed with normal review. Thank you for splitting this up! |
There was a problem hiding this comment.
Pull request overview
Adds the initial thv llm CLI surface and configuration model needed to support OIDC-protected LLM gateway authentication, including persistence in config.yaml and a dedicated secrets scope.
Changes:
- Introduces
pkg/llmconfig types + validation helpers and accompanying unit tests. - Adds an
llmsection to the top-level app config and a new secrets scope for LLM refresh tokens. - Wires a new
thv llmcommand group (config commands implemented; other subcommands stubbed) and generates CLI reference docs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/secrets/scoped.go | Adds ScopeLLM for namespacing LLM-related secrets. |
| pkg/llm/doc.go | Package-level documentation for the new LLM domain package. |
| pkg/llm/config.go | Defines persisted LLM config schema + validation/defaulting helpers. |
| pkg/llm/config_test.go | Unit tests for configuration validation/default behavior. |
| pkg/config/config.go | Adds LLM llm.Config to the root config struct (llm: YAML key). |
| cmd/thv/app/llm.go | Implements thv llm config set/show/reset; adds stubs for setup/teardown/proxy/token. |
| cmd/thv/app/commands.go | Registers thv llm and marks it informational (no container runtime required). |
| docs/cli/thv_llm.md | Autogenerated reference for thv llm. |
| docs/cli/thv_llm_config.md | Autogenerated reference for thv llm config. |
| docs/cli/thv_llm_config_set.md | Autogenerated reference for thv llm config set. |
| docs/cli/thv_llm_config_show.md | Autogenerated reference for thv llm config show. |
| docs/cli/thv_llm_config_reset.md | Autogenerated reference for thv llm config reset. |
| docs/cli/thv_llm_proxy.md | Autogenerated reference for thv llm proxy. |
| docs/cli/thv_llm_proxy_start.md | Autogenerated reference for thv llm proxy start. |
| docs/cli/thv_llm_setup.md | Autogenerated reference for thv llm setup. |
| docs/cli/thv_llm_teardown.md | Autogenerated reference for thv llm teardown. |
| docs/cli/thv.md | Adds thv llm to the root command documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fbd81ea to
4a13a85
Compare
4a13a85 to
8b39715
Compare
8b39715 to
d3e0bce
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename pkg/llm types to drop LLM prefix (revive stutter: LLMConfig → Config, LLMOIDCConfig → OIDCConfig, etc.) - Fix unused cmd parameter in config show RunE (revive) - Use FormatJSON constant instead of raw "json" string (goconst) - Fix gci import ordering in pkg/config/config.go - Regenerate docs/cli/ for the new thv llm command group Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d3e0bce to
4c1ad31
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Introduces the
thv llmcommand group as the foundation for LLM gatewayauthentication (RFC-0070 / stacklok/toolhive-rfcs#70). The
thv llmfeaturebridges AI coding tools to OIDC-protected LLM gateways — this PR lays the
skeleton that subsequent PRs (token source, proxy, tool adapters, setup/teardown)
will build on.
authentication against LLM gateways. Without a persistent config model and a
CLI entry point, nothing else in this feature can land.
pkg/llm/config.go—Config,OIDCConfig,ProxyConfig,ToolConfigtypes withIsConfigured(),ValidatePartial(), andValidate()(HTTPS enforcement, port range checks, required-field guards)
pkg/secrets/scoped.go— addsScopeLLMsecret scope for storing OIDCrefresh tokens under
__thv_llm_*pkg/config/config.go— addsLLM llm.Configfield (yaml:"llm,omitempty")to the top-level
Configstructcmd/thv/app/llm.go—thv llm config set/show/reset(fully implemented)plus stubbed
setup,teardown,proxy start, and hiddentokencommandscmd/thv/app/commands.go— registersthv llmin root command; addsllmto the informational-commands map (no container runtime needed)
Part of #5016. Closes #5027.
Type of change
Test plan
task test) —pkg/llmtests coverIsConfigured(),ValidatePartial(),Validate()(HTTPS enforcement, port range, required fields),EffectiveProxyPort(),EffectiveScopes()task lint-fix) —task license-fixrun; build is cleanDoes this introduce a user-facing change?
Yes —
thv llmis a new top-level command group. Theconfig set/show/resetsubcommands are fully functional. The remaining subcommands (
setup,teardown,proxy start,token) are stubbed and return "not implemented" until subsequentPRs land.
Special notes for reviewers
thv llm tokencommand is intentionallyHidden: true— it is notmeant for direct user invocation; it serves as the
apiKeyHelper/auth.commandtarget for OIDC-capable AI tools.
pkg/llm/config.gorather thanpkg/config/as specifiedin the RFC — this keeps the LLM domain self-contained. Types are named without
the
LLMprefix (e.g.llm.Confignotllm.LLMConfig) since the packagename already provides that context.
ScopeLLM = "llm"satisfies the no-underscore invariant documented inpkg/secrets/scoped.go.Generated with Claude Code
Large PR Justification
This is adding a new thv llm command. This PR includes the basic and scaffolding. Cannot be split.