1 // Command onechat runs the agent daemon and its terminal client.
13 // usage is the help text of the command.
14 const usage = `Usage: onechat [COMMAND]
17 backup FILE archive the running daemon data
18 restore FILE restore into an empty data directory
19 chat talk to the agent in this terminal (default)
20 daemon run the agent, Telegram, and WhatsApp
21 import [-n] [--agent NAME] ZIP...
22 import WhatsApp history (stop the daemon first)
23 -n print the plan without model calls
24 --agent NAME import into an existing direct child (default: root)
25 login log in to ChatGPT with a device code
26 probe LOG COUNT [BUILDS] measure the compactor on a log, with real calls
27 version show the build version
30 Chat needs a running daemon. ONECHAT_DIR sets the data directory.
33 // version is set by the package build and stays dev for direct Go builds.
39 fmt.Fprintln(os.Stderr, "onechat:", err)
45 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
50 case len(args) == 1 && (args[0] == "help" || args[0] == "--help" || args[0] == "-h"):
51 _, err := fmt.Print(usage)
53 return fmt.Errorf("write command help: %w", err)
55 case len(args) == 1 && args[0] == "version":
56 _, err := fmt.Println(version)
58 return fmt.Errorf("write build version: %w", err)
60 case len(args) == 1 && args[0] == "login":
61 err := chatgptLogin(ctx, os.Stdout)
66 // A signal is the normal stop of the daemon and the client, so their
67 // result does not include ctx.Err().
68 case len(args) == 1 && args[0] == "daemon":
69 return daemon(ctx, os.Stdout)
70 case len(args) == 0 || len(args) == 1 && args[0] == "chat":
71 return terminal(ctx, os.Stdin, os.Stdout)
72 case len(args) == 2 && args[0] == "backup":
73 return backup(ctx, args[1], os.Stdout)
74 case len(args) == 2 && args[0] == "restore":
75 return restore(ctx, args[1], os.Stdout)
76 case len(args) > 0 && args[0] == "import":
77 return whatsappImport(ctx, args[1:], os.Stdout)
78 case len(args) > 0 && args[0] == "probe":
79 err := probe(ctx, args[1:], os.Stdout)
84 return fmt.Errorf("unknown command %q\n\n%s", strings.Join(args, " "), strings.TrimSuffix(usage, "\n"))