diff --git a/gptme/chat.py b/gptme/chat.py index ed68a164..92e60dcc 100644 --- a/gptme/chat.py +++ b/gptme/chat.py @@ -117,11 +117,11 @@ def confirm_func(msg) -> bool: if prompt_msgs: while prompt_msgs: msg = prompt_msgs.pop(0) - if not msg.content.startswith("/"): + if not msg.content.startswith("/") and msg.role == "user": msg = _include_paths(msg, workspace) manager.append(msg) # if prompt is a user-command, execute it - if execute_cmd(msg, manager, confirm_func): + if msg.role == "user" and execute_cmd(msg, manager, confirm_func): continue # Generate and execute response for this prompt diff --git a/gptme/cli.py b/gptme/cli.py index 73526d06..3b431cfe 100644 --- a/gptme/cli.py +++ b/gptme/cli.py @@ -204,12 +204,11 @@ def main( # if stdin is not a tty, we might be getting piped input, which we should include in the prompt was_piped = False + piped_input = None if not sys.stdin.isatty(): # fetch prompt from stdin - prompt_stdin = _read_stdin() - if prompt_stdin: - # TODO: also append if existing convo loaded/resumed - initial_msgs += [Message("system", f"```stdin\n{prompt_stdin}\n```")] + piped_input = _read_stdin() + if piped_input: was_piped = True # Attempt to switch to interactive mode @@ -237,6 +236,8 @@ def main( if resume: logdir = get_logdir_resume() + if piped_input: + prompt_msgs.append(Message("system", f"```stdin\n{piped_input}\n```")) # don't run pick in tests/non-interactive mode, or if the user specifies a name elif ( interactive @@ -248,6 +249,8 @@ def main( logdir = pick_log() else: logdir = get_logdir(name) + if piped_input: + initial_msgs.append(Message("system", f"```stdin\n{piped_input}\n```")) if workspace == "@log": workspace_path: Path | None = logdir / "workspace"