diff --git a/src/timmy/cli.py b/src/timmy/cli.py index fd4268c..5ffa82a 100644 --- a/src/timmy/cli.py +++ b/src/timmy/cli.py @@ -176,6 +176,35 @@ def think( timmy.print_response(f"Think carefully about: {topic}", stream=True, session_id=_CLI_SESSION_ID) +def _read_message_input(message: list[str]) -> str: + """Join CLI arguments and read from stdin when appropriate.""" + message_str = " ".join(message) + + if message_str == "-" or not _is_interactive(): + try: + stdin_content = sys.stdin.read().strip() + except (KeyboardInterrupt, EOFError): + stdin_content = "" + if stdin_content: + message_str = stdin_content + elif message_str == "-": + typer.echo("No input provided via stdin.", err=True) + raise typer.Exit(1) + + return message_str + + +def _resolve_session_id(session_id: str | None, new_session: bool) -> str: + """Return the effective session ID based on CLI flags.""" + import uuid + + if session_id is not None: + return session_id + if new_session: + return str(uuid.uuid4()) + return _CLI_SESSION_ID + + @app.command() def chat( message: list[str] = typer.Argument( @@ -216,13 +245,9 @@ def chat( session_id = _resolve_session_id(session_id, new_session) timmy = create_timmy(backend=backend, session_id=session_id) - # Use agent.run() so we can intercept paused runs for tool confirmation. run_output = timmy.run(message_str, stream=False, session_id=session_id) - - # Handle paused runs — dangerous tools need user approval run_output = _handle_tool_confirmation(timmy, run_output, session_id, autonomous=autonomous) - # Print the final response content = run_output.content if hasattr(run_output, "content") else str(run_output) if content: from timmy.session import _clean_response