12 // usage is the help text of the command.
13 const usage = `Usage: onechat [COMMAND]
16 chat talk to the agent in this terminal (default)
17 daemon run the agent, Telegram, and WhatsApp
18 login log in to ChatGPT with a device code
19 probe LOG COUNT [BUILDS] measure the compactor on a log, with real calls
22 Chat needs a running daemon. ONECHAT_DIR sets the data directory.
28 fmt.Fprintln(os.Stderr, "onechat:", err)
34 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
39 case len(args) == 1 && (args[0] == "help" || args[0] == "--help" || args[0] == "-h"):
40 _, err := fmt.Print(usage)
44 case len(args) == 1 && args[0] == "login":
45 err := chatgptLogin(ctx, os.Stdout)
49 // A signal is the normal stop of the daemon and the client, so their
50 // result does not include ctx.Err().
51 case len(args) == 1 && args[0] == "daemon":
52 return daemon(ctx, os.Stdout)
53 case len(args) == 0 || len(args) == 1 && args[0] == "chat":
54 return terminal(ctx, os.Stdin, os.Stdout)
55 case len(args) > 0 && args[0] == "probe":
56 err := probe(ctx, args[1:], os.Stdout)
61 return fmt.Errorf("unknown command %q\n\n%s", strings.Join(args, " "), strings.TrimSuffix(usage, "\n"))