Skip to content

refactor: move llm setup/teardown orchestration to pkg/llm #5091

Closed

Description

@yrobla

Background

`runLLMSetup` and `runLLMTeardown` in `cmd/thv/app/llm.go` are ~100 lines each of orchestration logic: login injection, rollback, atomic persistence, and tool patching sequencing. Per `.claude/rules/cli-commands.md` the CLI layer should be a thin wrapper with business logic in `pkg/`.

Flagged during review of #5068.

What to do

  • Move setup/teardown orchestration to `pkg/llm/setup.go`
  • Define `LoginFunc` type in `pkg/llm/` (currently `loginFunc` in `cmd/thv/app/llm.go`)
  • Move helpers: `mergeToolConfigs`, `hasProxyMode`, `isTarget`, `purgeCachedTokens`
  • CLI `runLLMSetup`/`runLLMTeardown` become thin wrappers calling `pkg/llm.Setup()` / `pkg/llm.Teardown()`

Why

Before HTTP API or operator callers need the same flow, the business logic needs to be importable without pulling in cobra. Moving it to `pkg/llm/` makes it reusable and independently testable.

Activity

  1. added a commit that references this issue on Apr 29, 2026
    6b9fa1d
  2. added a commit that references this issue on Apr 29, 2026
    b27d310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions