]> git.giacomolli.uk - onechat/blobdiff - command.go
Require consent and review for autosquash
[onechat] / command.go
index a49f1d9c007b6ef5f1739708cab70d1986d2b95a..8b5f29e106bbe511acba63bd6d7183840be2670f 100644 (file)
@@ -19,6 +19,8 @@ Commands:
                            import WhatsApp history (stop the daemon first)
     -n                     print the plan without model calls
     --agent NAME           import into an existing direct child (default: root)
+  notify [--agent-id ID] --source SOURCE --id ID --text TEXT
+                           send an external event (default: root)
   login                    log in to ChatGPT with a device code
   probe LOG COUNT [BUILDS] measure the compactor on a log, with real calls
   version                  show the build version
@@ -48,25 +50,57 @@ func parseCommand(ctx context.Context, args []string) error {
        case len(args) == 1 && args[0] == "login":
                err := chatgptLogin(ctx, os.Stdout)
                if err != nil {
-                       return err
+                       return fmt.Errorf("log in: %w", err)
                }
 
        // A signal is the normal stop of the daemon and the client, so their
        // result does not include ctx.Err().
        case len(args) == 1 && args[0] == "daemon":
-               return daemon(ctx, os.Stdout)
+               err := daemon(ctx, os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("run daemon: %w", err)
+               }
+
+               return nil
        case len(args) == 0 || len(args) == 1 && args[0] == "chat":
-               return terminal(ctx, os.Stdin, os.Stdout)
+               err := terminal(ctx, os.Stdin, os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("run terminal: %w", err)
+               }
+
+               return nil
        case len(args) == 2 && args[0] == "backup":
-               return backup(ctx, args[1], os.Stdout)
+               err := backup(ctx, args[1], os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("run backup: %w", err)
+               }
+
+               return nil
        case len(args) == 2 && args[0] == "restore":
-               return restore(ctx, args[1], os.Stdout)
+               err := restore(ctx, args[1], os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("run restore: %w", err)
+               }
+
+               return nil
+       case len(args) > 0 && args[0] == "notify":
+               err := notify(ctx, args[1:], os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("submit external event: %w", err)
+               }
+
+               return nil
        case len(args) > 0 && args[0] == "import":
-               return whatsappImport(ctx, args[1:], os.Stdout)
+               err := whatsappImport(ctx, args[1:], os.Stdout)
+               if err != nil {
+                       return fmt.Errorf("import WhatsApp history: %w", err)
+               }
+
+               return nil
        case len(args) > 0 && args[0] == "probe":
                err := probe(ctx, args[1:], os.Stdout)
                if err != nil {
-                       return err
+                       return fmt.Errorf("run probe: %w", err)
                }
        default:
                return fmt.Errorf("unknown command %q\n\n%s", strings.Join(args, " "), strings.TrimSuffix(usage, "\n"))