| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | |
| 7 | "github.com/spf13/cobra" |
| 8 | ) |
| 9 | |
| 10 | var ( |
| 11 | version = "dev" |
| 12 | ) |
| 13 | |
| 14 | var rootCmd = &cobra.Command{ |
| 15 | Use: "klaus", |
| 16 | Short: "Multi-agent orchestrator for Claude Code, Codex, and agy", |
| 17 | Long: `klaus orchestrates parallel coding agents using git worktrees and tmux panes. |
| 18 | |
| 19 | It launches autonomous agents in isolated worktrees, manages their lifecycle, |
| 20 | streams and formats their output, and tracks run state. |
| 21 | |
| 22 | Running 'klaus' with no arguments resumes the most recent coordinator session. |
| 23 | If no session exists, a new one is created. Use 'klaus new' to explicitly start |
| 24 | a fresh session.`, |
| 25 | Version: version, |
| 26 | RunE: func(cmd *cobra.Command, args []string) error { |
| 27 | return runSession(cmd, false) |
| 28 | }, |
| 29 | } |
| 30 | |
| 31 | func Execute() error { |
| 32 | return rootCmd.Execute() |
| 33 | } |
| 34 | |
| 35 | // exitError is an error that sets klaus's exit status. |
| 36 | type exitError struct { |
| 37 | code int |
| 38 | err error |
| 39 | } |
| 40 | |
| 41 | func (e *exitError) Error() string { return e.err.Error() } |
| 42 | func (e *exitError) Unwrap() error { return e.err } |
| 43 | |
| 44 | // ExitCode is the exit status for an error Execute returned: the one the |
| 45 | // error asks for, else 1. |
| 46 | func ExitCode(err error) int { |
| 47 | var e *exitError |
| 48 | if errors.As(err, &e) { |
| 49 | return e.code |
| 50 | } |
| 51 | return 1 |
| 52 | } |
| 53 | |
| 54 | func init() { |
| 55 | rootCmd.SetVersionTemplate(fmt.Sprintf("klaus version %s\n", version)) |
| 56 | } |