gunk-dev/the-valley

root.go

source68d12192bbd3main's published tip history
1.3 KiB
1package cmd
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/spf13/cobra"
8)
9
10var (
11 version = "dev"
12)
13
14var 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
19It launches autonomous agents in isolated worktrees, manages their lifecycle,
20streams and formats their output, and tracks run state.
21
22Running 'klaus' with no arguments resumes the most recent coordinator session.
23If no session exists, a new one is created. Use 'klaus new' to explicitly start
24a fresh session.`,
25 Version: version,
26 RunE: func(cmd *cobra.Command, args []string) error {
27 return runSession(cmd, false)
28 },
29}
30
31func Execute() error {
32 return rootCmd.Execute()
33}
34
35// exitError is an error that sets klaus's exit status.
36type exitError struct {
37 code int
38 err error
39}
40
41func (e *exitError) Error() string { return e.err.Error() }
42func (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.
46func ExitCode(err error) int {
47 var e *exitError
48 if errors.As(err, &e) {
49 return e.code
50 }
51 return 1
52}
53
54func init() {
55 rootCmd.SetVersionTemplate(fmt.Sprintf("klaus version %s\n", version))
56}