| 863 | } |
| 864 | |
| 865 | func (f *runExecFlags) handleExecMode(ctx context.Context, out *cli.Printer, rt runtime.Runtime, sess *session.Session, args []string) error { |
| 866 | if f.sessionReadOnly { |
| 867 | return errors.New("--session-read-only cannot be used with --exec: there is nothing to display without a TUI") |
| 868 | } |
| 869 | |
| 870 | // args[0] is the agent file; args[1:] are user messages for multi-turn conversation |
| 871 | var userMessages []string |
| 872 | if len(args) > 1 { |
| 873 | userMessages = args[1:] |
| 874 | } |
| 875 | |
| 876 | err := cli.Run(ctx, out, cli.Config{ |
| 877 | AppName: AppName, |
| 878 | AttachmentPath: f.attachmentPath, |
| 879 | HideToolCalls: f.hideToolCalls, |
| 880 | OutputJSON: f.outputJSON, |
| 881 | AutoApprove: f.autoApprove, |
| 882 | }, rt, sess, userMessages) |
| 883 | if cliErr, ok := errors.AsType[cli.RuntimeError](err); ok { |
| 884 | return RuntimeError{Err: cliErr.Err} |
| 885 | } |
| 886 | return err |
| 887 | } |
| 888 | |
| 889 | func readInitialMessage(args []string) (*string, error) { |
| 890 | if len(args) < 2 { |