mirror of
https://github.com/alvinunreal/tmuxai.git
synced 2026-10-05 22:35:26 +02:00
2.7 KiB
2.7 KiB
cli/
Responsibility
- Defines and wires the user-facing command-line interface surface for
tmuxai. - Owns CLI argument/flag parsing, bootstrap behavior (version/config/initial request), and startup orchestration for a manager-based interactive session.
- Delegates operational behavior to shared packages (
config,internal,logger) and remains thin by only translating CLI intent into manager options and lifecycle calls.
Design
- Uses Cobra’s
*cobra.Commandas a single root command (tmuxai [request message]) with global flags and aPersistentPreRunversion gate. - Keeps parse state in package-level vars (
taskFileFlag,kbFlag,modelFlag, pane selectors, and booleans) bound once ininit(). - Root
Runis single-threaded bootstrap flow: load config, normalize/resolve request source, constructinternal.ManagerOptions, createinternal.Manager, apply CLI overrides, then start interaction. - Uses simple signal handling (
SIGTERM,SIGHUP) to ensure manager cleanup before process exit. - Exports only
Execute()as the entrypoint used bymain.go, preserving a clean boundary between runtime bootstrap and command registration.
Data & Control Flow
main()initializes logging and invokescli.Execute().Execute()delegates to Cobra’srootCmd.Execute().- On invocation,
PersistentPreRunchecks--versionand exits withinternal.Version/Commit/Date. Runloads configuration viaconfig.Load(configFileFlag), then builds initial request text from args or--filecontent.- It maps CLI flags into
internal.ManagerOptions:--exec-pane->ForcedExecPaneID--read-panes->ForcedReadPaneIDs
internal.NewManager(cfg, options)is called, then async signal goroutine registers cleanup hooks.- Late-bound overrides are applied on the manager before launch:
--kb->mgr.LoadKBsFromCLI(...)--model->mgr.SetModelsDefault(...)--yolo->mgr.SessionOverrides["yolo"] = true
mgr.Start(initMessage)transfers control to the interactive loop; CLI layer no longer manages domain logic.
Integration Points
github.com/alvinunreal/tmuxai/config: reads effective config and environment overrides viaconfig.Load(...).github.com/alvinunreal/tmuxai/internal: constructs and drives the runtimeManagerand calls high-level methods for KB loading, model switching, and session execution.github.com/alvinunreal/tmuxai/logger: structured runtime logging for config/mode/bootstrap and error reporting.github.com/spf13/cobra: provides command framework, flag binding, and parsing.main.go: only consumer ofcli.Execute(), keeping CLI package as the terminal API boundary.