Skip to content

Commit 4a13a85

Browse files
taskbotclaude
andcommitted
Fix lint issues and regenerate CLI docs
- 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>
1 parent 020220c commit 4a13a85

4 files changed

Lines changed: 83 additions & 81 deletions

File tree

cmd/thv/app/llm.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818

1919
func newLLMCommand() *cobra.Command {
2020
cmd := &cobra.Command{
21-
Use: "llm",
22-
Short: "Manage LLM gateway authentication",
21+
Use: "llm",
22+
Hidden: true,
23+
Short: "Manage LLM gateway authentication",
2324
Long: `Configure and manage authentication for OIDC-protected LLM gateways.
2425
2526
The llm command bridges AI coding tools to LLM gateways by handling OIDC
@@ -34,7 +35,7 @@ authentication transparently. Two modes are supported:
3435
Run "thv llm setup" to get started.`,
3536
}
3637

37-
cmd.AddCommand(newLLMConfigCommand())
38+
cmd.AddCommand(newConfigCommand())
3839
cmd.AddCommand(newLLMSetupCommand())
3940
cmd.AddCommand(newLLMTeardownCommand())
4041
cmd.AddCommand(newLLMProxyCommand())
@@ -45,21 +46,21 @@ Run "thv llm setup" to get started.`,
4546

4647
// ── config subcommand group ───────────────────────────────────────────────────
4748

48-
func newLLMConfigCommand() *cobra.Command {
49+
func newConfigCommand() *cobra.Command {
4950
cmd := &cobra.Command{
5051
Use: "config",
5152
Short: "Manage LLM gateway configuration",
5253
Long: "The config command provides subcommands to manage LLM gateway connection settings.",
5354
}
5455

55-
cmd.AddCommand(newLLMConfigSetCommand())
56-
cmd.AddCommand(newLLMConfigShowCommand())
57-
cmd.AddCommand(newLLMConfigResetCommand())
56+
cmd.AddCommand(newConfigSetCommand())
57+
cmd.AddCommand(newConfigShowCommand())
58+
cmd.AddCommand(newConfigResetCommand())
5859

5960
return cmd
6061
}
6162

62-
func newLLMConfigSetCommand() *cobra.Command {
63+
func newConfigSetCommand() *cobra.Command {
6364
var (
6465
gatewayURL string
6566
issuer string
@@ -115,18 +116,18 @@ Example:
115116
return cmd
116117
}
117118

118-
func newLLMConfigShowCommand() *cobra.Command {
119+
func newConfigShowCommand() *cobra.Command {
119120
var outputFormat string
120121

121122
cmd := &cobra.Command{
122123
Use: "show",
123124
Short: "Display current LLM gateway configuration",
124125
Args: cobra.NoArgs,
125-
RunE: func(cmd *cobra.Command, _ []string) error {
126+
RunE: func(_ *cobra.Command, _ []string) error {
126127
provider := config.NewDefaultProvider()
127128
llmCfg := provider.GetConfig().LLM
128129

129-
if outputFormat == "json" {
130+
if outputFormat == FormatJSON {
130131
enc, err := json.MarshalIndent(llmCfg, "", " ")
131132
if err != nil {
132133
return fmt.Errorf("failed to encode config as JSON: %w", err)
@@ -164,7 +165,7 @@ func newLLMConfigShowCommand() *cobra.Command {
164165
return cmd
165166
}
166167

167-
func newLLMConfigResetCommand() *cobra.Command {
168+
func newConfigResetCommand() *cobra.Command {
168169
return &cobra.Command{
169170
Use: "reset",
170171
Short: "Clear all LLM gateway configuration and cached tokens",
@@ -179,7 +180,7 @@ tokens from the secrets provider.`,
179180
}
180181

181182
return config.UpdateConfig(func(c *config.Config) error {
182-
c.LLM = llm.LLMConfig{}
183+
c.LLM = llm.Config{}
183184
return nil
184185
})
185186
},

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Config struct {
4848
BuildAuthFiles map[string]string `yaml:"build_auth_files,omitempty"`
4949
RuntimeConfigs map[string]*templates.RuntimeConfig `yaml:"runtime_configs,omitempty"`
5050
RegistryAuth RegistryAuth `yaml:"registry_auth,omitempty"`
51-
LLM llm.LLMConfig `yaml:"llm,omitempty"`
51+
LLM llm.Config `yaml:"llm,omitempty"`
5252
}
5353

5454
// RegistryAuthTypeOAuth is the auth type for OAuth/OIDC authentication.

pkg/llm/config.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,42 @@ const (
1818
DefaultOIDCScopes = "openid offline_access"
1919
)
2020

21-
// LLMConfig holds all LLM gateway settings persisted under the llm: key in
21+
// Config holds all LLM gateway settings persisted under the llm: key in
2222
// ToolHive's config.yaml.
23-
type LLMConfig struct {
24-
GatewayURL string `yaml:"gateway_url,omitempty"`
25-
OIDC LLMOIDCConfig `yaml:"oidc,omitempty"`
26-
Proxy LLMProxyConfig `yaml:"proxy,omitempty"`
27-
Auth LLMAuthState `yaml:"auth,omitempty"`
28-
ConfiguredTools []LLMToolConfig `yaml:"configured_tools,omitempty"`
23+
type Config struct {
24+
GatewayURL string `yaml:"gateway_url,omitempty"`
25+
OIDC OIDCConfig `yaml:"oidc,omitempty"`
26+
Proxy ProxyConfig `yaml:"proxy,omitempty"`
27+
ConfiguredTools []ToolConfig `yaml:"configured_tools,omitempty"`
2928
}
3029

31-
// LLMOIDCConfig holds OIDC provider settings for the LLM gateway.
32-
type LLMOIDCConfig struct {
30+
// OIDCConfig holds OIDC provider settings and cached token state for the LLM
31+
// gateway. Cached fields follow the same pattern as RegistryOAuthConfig in
32+
// pkg/config/config.go — token values are never stored here, only references
33+
// and expiry metadata.
34+
type OIDCConfig struct {
3335
Issuer string `yaml:"issuer,omitempty"`
3436
ClientID string `yaml:"client_id,omitempty"`
3537
Scopes []string `yaml:"scopes,omitempty"`
3638
Audience string `yaml:"audience,omitempty"`
3739
CallbackPort int `yaml:"callback_port,omitempty"`
38-
}
3940

40-
// LLMProxyConfig holds configuration for the localhost reverse proxy.
41-
type LLMProxyConfig struct {
42-
ListenPort int `yaml:"listen_port,omitempty"`
41+
// CachedRefreshTokenRef is the secrets-provider key under which the refresh
42+
// token is stored (never the token value itself).
43+
CachedRefreshTokenRef string `yaml:"cached_refresh_token_ref,omitempty"`
44+
// CachedTokenExpiry is the expiry of the most recently cached access token,
45+
// used to surface helpful messages when the token is about to expire.
46+
CachedTokenExpiry time.Time `yaml:"cached_token_expiry,omitempty"`
4347
}
4448

45-
// LLMAuthState records token lifecycle metadata persisted to config (no token
46-
// values — those live in the secrets provider or memory only).
47-
type LLMAuthState struct {
48-
// CachedTokenExpiry is the expiry time of the most recently cached access
49-
// token. Used to surface helpful messages when the token is about to expire.
50-
CachedTokenExpiry time.Time `yaml:"cached_token_expiry,omitempty"`
49+
// ProxyConfig holds configuration for the localhost reverse proxy.
50+
type ProxyConfig struct {
51+
ListenPort int `yaml:"listen_port,omitempty"`
5152
}
5253

53-
// LLMToolConfig records a tool that setup has configured, so teardown knows
54+
// ToolConfig records a tool that setup has configured, so teardown knows
5455
// exactly what to reverse.
55-
type LLMToolConfig struct {
56+
type ToolConfig struct {
5657
// Tool is the canonical tool identifier (e.g. "claude-code", "cursor").
5758
Tool string `yaml:"tool"`
5859
// Mode is the authentication mode: "direct" or "proxy".
@@ -63,13 +64,13 @@ type LLMToolConfig struct {
6364

6465
// IsConfigured reports whether the minimum required fields are present for the
6566
// LLM gateway to be usable: gateway URL, OIDC issuer, and OIDC client ID.
66-
func (c *LLMConfig) IsConfigured() bool {
67+
func (c *Config) IsConfigured() bool {
6768
return c.GatewayURL != "" && c.OIDC.Issuer != "" && c.OIDC.ClientID != ""
6869
}
6970

7071
// Validate performs full validation of the LLM config, including HTTPS
7172
// enforcement, port range checks, and OIDC field requirements.
72-
func (c *LLMConfig) Validate() error {
73+
func (c *Config) Validate() error {
7374
var errs []error
7475

7576
if c.GatewayURL == "" {
@@ -99,7 +100,7 @@ func (c *LLMConfig) Validate() error {
99100

100101
// EffectiveProxyPort returns the configured proxy listen port, or
101102
// DefaultProxyListenPort if none is set.
102-
func (c *LLMConfig) EffectiveProxyPort() int {
103+
func (c *Config) EffectiveProxyPort() int {
103104
if c.Proxy.ListenPort > 0 {
104105
return c.Proxy.ListenPort
105106
}
@@ -108,7 +109,7 @@ func (c *LLMConfig) EffectiveProxyPort() int {
108109

109110
// EffectiveScopes returns the configured OIDC scopes, or the default scopes
110111
// (openid, offline_access) if none are set.
111-
func (c *LLMOIDCConfig) EffectiveScopes() []string {
112+
func (c *OIDCConfig) EffectiveScopes() []string {
112113
if len(c.Scopes) > 0 {
113114
return c.Scopes
114115
}

0 commit comments

Comments
 (0)