@@ -148,7 +148,7 @@ def handle_cmd(
148
148
149
149
150
150
@click .command (help = docstring )
151
- @click .argument ("prompt " , default = None , required = False )
151
+ @click .argument ("prompts " , default = None , required = False , nargs = - 1 )
152
152
@click .option (
153
153
"--prompt-system" ,
154
154
default = "full" ,
@@ -187,7 +187,7 @@ def handle_cmd(
187
187
help = "Show hidden system messages." ,
188
188
)
189
189
def main (
190
- prompt : str | None ,
190
+ prompts : list [ str ] ,
191
191
prompt_system : str ,
192
192
name : str ,
193
193
llm : LLMChoice ,
@@ -214,7 +214,7 @@ def main(
214
214
else :
215
215
promptmsgs = [Message ("system" , prompt_system )]
216
216
217
- logfile = get_logfile (name )
217
+ logfile = get_logfile (name , interactive = not prompts and sys . stdin . isatty () )
218
218
print (f"Using logdir { logfile .parent } " )
219
219
logmanager = LogManager .load (
220
220
logfile , initial_msgs = promptmsgs , show_hidden = show_hidden
@@ -232,6 +232,11 @@ def main(
232
232
command_triggered = False
233
233
234
234
while True :
235
+ prompt = None
236
+ if prompts :
237
+ prompt = prompts [0 ]
238
+ prompts = prompts [1 :]
239
+
235
240
# if non-interactive and command has been run, exit
236
241
if command_triggered and not sys .stdin .isatty ():
237
242
logger .info ("Command triggered and not in TTY, exiting" )
@@ -250,8 +255,8 @@ def main(
250
255
# Empty command, ask for input again
251
256
print ()
252
257
continue
253
- # we will exit when a prompt given on command line and we're non-interactive
254
- if prompt :
258
+ # we will exit when last cli-provided prompt is done (if we're non-interactive, see above)
259
+ if prompt and len ( prompts ) == 0 :
255
260
command_triggered = True
256
261
prompt = None
257
262
logmanager .append (Message ("user" , inquiry ), quiet = True )
@@ -367,7 +372,7 @@ def _load_readline_history() -> None:
367
372
atexit .register (readline .write_history_file , HISTORY_FILE )
368
373
369
374
370
- def get_logfile (name : str ) -> Path :
375
+ def get_logfile (name : str , interactive = True ) -> Path :
371
376
# let user select between starting a new conversation and loading a previous one
372
377
# using the library
373
378
title = "New conversation or load previous? "
@@ -385,7 +390,7 @@ def get_logfile(name: str) -> Path:
385
390
]
386
391
387
392
# don't run pick in tests/non-interactive mode
388
- if sys . stdout . isatty () :
393
+ if interactive :
389
394
options = [
390
395
NEW_CONV ,
391
396
] + prev_convs
0 commit comments